Clean-up lock-ref implementation
This drops "mustexist" parameter lock_ref_sha1() and lock_any_ref_forupdate() functions take. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 27, 2006 at 01:09 UTC
4431fcc4b134ae501e3e57dc568ae4f031e57898
5 files changed
+11
-12
builtin-pack-refs.c
+1
-1
@@ -53,7 +53,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
53
/* make sure nobody touched the ref, and unlink */
54
static void prune_ref(struct ref_to_prune *r)
55
{
56
- struct ref_lock *lock = lock_ref_sha1(r->name + 5, r->sha1, 1);
56
+ struct ref_lock *lock = lock_ref_sha1(r->name + 5, r->sha1);
57
58
if (lock) {
59
unlink(git_path("%s", r->name));
builtin-update-ref.c
+1
-1
@@ -48,7 +48,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
48
if (oldval && get_sha1(oldval, oldsha1))
49
die("%s: not a valid old SHA1", oldval);
50
51
- lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL, 0);
51
+ lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
52
if (!lock)
53
return 1;
54
if (write_ref_sha1(lock, sha1, msg) < 0)
fetch.c
+1
-1
@@ -266,7 +266,7 @@ int pull(int targets, char **target, const char **write_ref,
266
if (!write_ref || !write_ref[i])
267
continue;
268
269
- lock[i] = lock_ref_sha1(write_ref[i], NULL, 0);
269
+ lock[i] = lock_ref_sha1(write_ref[i], NULL);
270
if (!lock[i]) {
271
error("Can't lock ref %s", write_ref[i]);
272
goto unlock_and_fail;
refs.c
+6
-7
@@ -447,12 +447,13 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
447
return lock;
448
}
449
450
-static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char *old_sha1, int mustexist)
450
+static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char *old_sha1)
451
{
452
char *ref_file;
453
const char *orig_ref = ref;
454
struct ref_lock *lock;
455
struct stat st;
456
+ int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
457
458
lock = xcalloc(1, sizeof(struct ref_lock));
459
lock->lock_fd = -1;
@@ -480,20 +481,18 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
481
return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
482
}
483
483
-struct ref_lock *lock_ref_sha1(const char *ref,
484
- const unsigned char *old_sha1, int mustexist)
484
+struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
485
{
486
char refpath[PATH_MAX];
487
if (check_ref_format(ref))
488
return NULL;
489
strcpy(refpath, mkpath("refs/%s", ref));
490
- return lock_ref_sha1_basic(refpath, old_sha1, mustexist);
490
+ return lock_ref_sha1_basic(refpath, old_sha1);
491
}
492
493
-struct ref_lock *lock_any_ref_for_update(const char *ref,
494
- const unsigned char *old_sha1, int mustexist)
493
+struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1)
494
{
496
- return lock_ref_sha1_basic(ref, old_sha1, mustexist);
495
+ return lock_ref_sha1_basic(ref, old_sha1);
496
}
497
498
void unlock_ref(struct ref_lock *lock)
refs.h
+2
-2
@@ -27,10 +27,10 @@ extern int for_each_remote_ref(each_ref_fn, void *);
27
extern int get_ref_sha1(const char *ref, unsigned char *sha1);
28
29
/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/
30
-extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1, int mustexist);
30
+extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1);
31
32
/** Locks any ref (for 'HEAD' type refs). */
33
-extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int mustexist);
33
+extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1);
34
35
/** Release any lock taken but not written. **/
36
extern void unlock_ref(struct ref_lock *lock);