summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Brad King <brad.king@kitware.com>2013-09-04 11:22:41 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-09-04 11:09:09 -0700
commit2ddb5d170ac5fa3568efecb001c4ff0af0580c0d (patch)
treebb4fba5d814e92183bb8447409d0b22712c27115
parentrefs: factor update_ref steps into helpers (diff)
downloadtgif-2ddb5d170ac5fa3568efecb001c4ff0af0580c0d.tar.xz
refs: factor delete_ref loose ref step into a helper
Factor loose ref deletion into helper function delete_ref_loose to allow later use elsewhere. Signed-off-by: Brad King <brad.king@kitware.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/refs.c b/refs.c
index 4347826dcb..ab9d22ec7a 100644
--- a/refs.c
+++ b/refs.c
@@ -2450,24 +2450,31 @@ static int repack_without_ref(const char *refname)
return commit_packed_refs();
}
+static int delete_ref_loose(struct ref_lock *lock, int flag)
+{
+ if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
+ /* loose */
+ int err, i = strlen(lock->lk->filename) - 5; /* .lock */
+
+ lock->lk->filename[i] = 0;
+ err = unlink_or_warn(lock->lk->filename);
+ lock->lk->filename[i] = '.';
+ if (err && errno != ENOENT)
+ return 1;
+ }
+ return 0;
+}
+
int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
{
struct ref_lock *lock;
- int err, i = 0, ret = 0, flag = 0;
+ int ret = 0, flag = 0;
lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
if (!lock)
return 1;
- if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
- /* loose */
- i = strlen(lock->lk->filename) - 5; /* .lock */
- lock->lk->filename[i] = 0;
- err = unlink_or_warn(lock->lk->filename);
- if (err && errno != ENOENT)
- ret = 1;
+ ret |= delete_ref_loose(lock, flag);
- lock->lk->filename[i] = '.';
- }
/* removing the loose one could have resurrected an earlier
* packed one. Also, if it was not loose we need to repack
* without it.