From: Michael Haggerty Date: Tue, 13 Oct 2015 03:51:10 GMT Subject: Re: [PATCH v3 06/44] refs.c: move delete_ref and delete_refs to the common code Message-ID: <561C7FAE.5010500@alum.mit.edu> In-Reply-To: <1444686725-27660-7-git-send-email-dturner@twopensource.com> On 10/12/2015 11:51 PM, David Turner wrote: > From: Ronnie Sahlberg > > 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 > Signed-off-by: Ronnie Sahlberg > --- > 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@alum.mit.edu