Re: [PATCH v3 06/44] refs.c: move delete_ref and delete_refs to the common code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/12/2015 11:51 PM, David Turner wrote:
> From: Ronnie Sahlberg <sahlberg@xxxxxxxxxx>
> 
> Move delete_pseudoref, delete_ref() and delete_refs() to the refs.c
> file since these functions do not contain any backend specific code.
> 
> Based on a patch by Ronnie Sahlberg.
> 
> Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx>
> Signed-off-by: Ronnie Sahlberg <sahlberg@xxxxxxxxxx>
> ---
>  refs-be-files.c | 94 ---------------------------------------------------------
>  refs.c          | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 94 insertions(+), 94 deletions(-)
> 
> diff --git a/refs-be-files.c b/refs-be-files.c
> index 7fe4931..099df75 100644
> --- a/refs-be-files.c
> +++ b/refs-be-files.c
> @@ -2877,100 +2877,6 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
>  	return 0;
>  }
>  
> -static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1)
> -{
> -	static struct lock_file lock;
> -	const char *filename;
> -
> -	filename = git_path("%s", pseudoref);
> -
> -	if (old_sha1 && !is_null_sha1(old_sha1)) {
> -		int fd;
> -		unsigned char actual_old_sha1[20];
> -
> -		fd = hold_lock_file_for_update(&lock, filename,
> -					       LOCK_DIE_ON_ERROR);
> -		if (fd < 0)
> -			die_errno(_("Could not open '%s' for writing"), filename);
> -		if (read_ref(pseudoref, actual_old_sha1))
> -			die("could not read ref '%s'", pseudoref);
> -		if (hashcmp(actual_old_sha1, old_sha1)) {
> -			warning("Unexpected sha1 when deleting %s", pseudoref);
> -			rollback_lock_file(&lock);
> -			return -1;
> -		}
> -
> -		unlink(filename);
> -		rollback_lock_file(&lock);
> -	} else {
> -		unlink(filename);
> -	}
> -
> -	return 0;
> -}
> -
> [...]
> diff --git a/refs.c b/refs.c
> index 2d10708..205a899 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -116,3 +116,97 @@ int update_ref(const char *msg, const char *refname,
>  		ref_transaction_free(t);
>  	return 0;
>  }
> +
> +
> +static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1)
> +{
> +	static struct lock_file lock;
> +	const char *filename;
> +
> +	filename = git_path("%s", pseudoref);
> +
> +	if (old_sha1 && !is_null_sha1(old_sha1)) {
> +		int fd;
> +		unsigned char actual_old_sha1[20];
> +
> +		fd = hold_lock_file_for_update(&lock, filename,
> +					       LOCK_DIE_ON_ERROR);
> +		if (fd < 0)
> +			die_errno(_("Could not open '%s' for writing"), filename);
> +		read_ref(pseudoref, actual_old_sha1);

The same test vanishes here as in the previous patch. The original was

		if (read_ref(pseudoref, actual_old_sha1))
			die("could not read ref '%s'", pseudoref);

> +		if (hashcmp(actual_old_sha1, old_sha1)) {
> +			warning("Unexpected sha1 when deleting %s", pseudoref);
> +			rollback_lock_file(&lock);
> +			return -1;
> +		}
> +
> +		unlink(filename);
> +		rollback_lock_file(&lock);
> +	} else {
> +		unlink(filename);
> +	}
> +
> +	return 0;
> +}
> +
> [...]

Michael

-- 
Michael Haggerty
mhagger@xxxxxxxxxxxx

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]