From: Ronnie Sahlberg <sahlberg@xxxxxxxxxx> Move delete_pseudoref() and delete_ref() to refs/refs.c since these functions do not contain any backend specific code. We can't move delete_refs yet because it depends on the files-backend-specific repack_without_refs. Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx> Signed-off-by: Ronnie Sahlberg <sahlberg@xxxxxxxxxx> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> --- refs/files-backend.c | 56 ---------------------------------------------------- refs/refs.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index e8c592a..6d502ac 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2892,62 +2892,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; -} - -int delete_ref(const char *refname, const unsigned char *old_sha1, - unsigned int flags) -{ - struct ref_transaction *transaction; - struct strbuf err = STRBUF_INIT; - - if (ref_type(refname) == REF_TYPE_PSEUDOREF) - return delete_pseudoref(refname, old_sha1); - - transaction = ref_transaction_begin(&err); - if (!transaction || - ref_transaction_delete(transaction, refname, old_sha1, - flags, NULL, &err) || - ref_transaction_commit(transaction, &err)) { - error("%s", err.buf); - ref_transaction_free(transaction); - strbuf_release(&err); - return 1; - } - ref_transaction_free(transaction); - strbuf_release(&err); - return 0; -} - int delete_refs(struct string_list *refnames) { struct strbuf err = STRBUF_INIT; diff --git a/refs/refs.c b/refs/refs.c index a63a58d..96d5c6d 100644 --- a/refs/refs.c +++ b/refs/refs.c @@ -117,3 +117,59 @@ 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); + 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; +} + +int delete_ref(const char *refname, const unsigned char *old_sha1, + unsigned int flags) +{ + struct ref_transaction *transaction; + struct strbuf err = STRBUF_INIT; + + if (ref_type(refname) == REF_TYPE_PSEUDOREF) + return delete_pseudoref(refname, old_sha1); + + transaction = ref_transaction_begin(&err); + if (!transaction || + ref_transaction_delete(transaction, refname, old_sha1, + flags, NULL, &err) || + ref_transaction_commit(transaction, &err)) { + error("%s", err.buf); + ref_transaction_free(transaction); + strbuf_release(&err); + return 1; + } + ref_transaction_free(transaction); + strbuf_release(&err); + return 0; +} -- 2.6.2 -- 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