From 4bd18c43d9a8a8fc1aa598926100f6999953ba48 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 17 May 2006 05:55:02 -0400 Subject: Improve abstraction of ref lock/write. Created 'struct ref_lock' to contain the data necessary to perform a ref update. This change improves writing a ref as the file names are generated only once (rather than twice) and supports following symrefs (up to the maximum depth). Further the ref_lock structure provides room to extend the update API with ref logging. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- fetch.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'fetch.c') diff --git a/fetch.c b/fetch.c index 73bde07aea..8bdaacb8e8 100644 --- a/fetch.c +++ b/fetch.c @@ -204,14 +204,14 @@ static int mark_complete(const char *path, const unsigned char *sha1) int pull(char *target) { + struct ref_lock *lock; unsigned char sha1[20]; - int fd = -1; save_commit_buffer = 0; track_object_refs = 0; - if (write_ref && current_ref) { - fd = lock_ref_sha1(write_ref, current_ref); - if (fd < 0) + if (write_ref) { + lock = lock_ref_sha1(write_ref, current_ref, 1); + if (!lock) return -1; } @@ -219,20 +219,22 @@ int pull(char *target) for_each_ref(mark_complete); } - if (interpret_target(target, sha1)) - return error("Could not interpret %s as something to pull", - target); - if (process(lookup_unknown_object(sha1))) + if (interpret_target(target, sha1)) { + error("Could not interpret %s as something to pull", target); + unlock_ref(lock); + return -1; + } + if (process(lookup_unknown_object(sha1))) { + unlock_ref(lock); return -1; - if (loop()) + } + if (loop()) { + unlock_ref(lock); return -1; - + } + if (write_ref) { - if (current_ref) { - write_ref_sha1(write_ref, fd, sha1); - } else { - write_ref_sha1_unlocked(write_ref, sha1); - } + return write_ref_sha1(lock, sha1, "git fetch"); } return 0; } -- cgit v1.2.1 From d0740d92beb019a7b02678e5acea79c0ff67e3ee Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 19 May 2006 03:29:26 -0400 Subject: Log ref updates made by fetch. If a ref is changed by http-fetch, local-fetch or ssh-fetch record the change and the remote URL/name in the log for the ref. This requires loading the config file to check logAllRefUpdates. Also fixed a bug in the ref lock generation; the log file name was not being produced right due to a bad prefix length. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- fetch.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'fetch.c') diff --git a/fetch.c b/fetch.c index 8bdaacb8e8..fd57684d8f 100644 --- a/fetch.c +++ b/fetch.c @@ -8,6 +8,7 @@ #include "refs.h" const char *write_ref = NULL; +const char *write_ref_log_details = NULL; const unsigned char *current_ref = NULL; @@ -206,13 +207,17 @@ int pull(char *target) { struct ref_lock *lock; unsigned char sha1[20]; + char *msg; + int ret; save_commit_buffer = 0; track_object_refs = 0; if (write_ref) { lock = lock_ref_sha1(write_ref, current_ref, 1); - if (!lock) + if (!lock) { + error("Can't lock ref %s", write_ref); return -1; + } } if (!get_recover) { @@ -234,7 +239,15 @@ int pull(char *target) } if (write_ref) { - return write_ref_sha1(lock, sha1, "git fetch"); + if (write_ref_log_details) { + msg = xmalloc(strlen(write_ref_log_details) + 12); + sprintf(msg, "fetch from %s", write_ref_log_details); + } else + msg = NULL; + ret = write_ref_sha1(lock, sha1, msg ? msg : "fetch (unknown)"); + if (msg) + free(msg); + return ret; } return 0; } -- cgit v1.2.1 From 99bd0f555823f3c3868561af33d85864a90a7d9a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 31 May 2006 15:23:44 -0700 Subject: fetch.c: do not pass uninitialized lock to unlock_ref(). Signed-off-by: Junio C Hamano --- fetch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'fetch.c') diff --git a/fetch.c b/fetch.c index ae92d5212e..cc6013e7af 100644 --- a/fetch.c +++ b/fetch.c @@ -203,7 +203,7 @@ static int mark_complete(const char *path, const unsigned char *sha1) int pull(char *target) { - struct ref_lock *lock; + struct ref_lock *lock = NULL; unsigned char sha1[20]; char *msg; int ret; @@ -223,15 +223,18 @@ int pull(char *target) if (interpret_target(target, sha1)) { error("Could not interpret %s as something to pull", target); - unlock_ref(lock); + if (lock) + unlock_ref(lock); return -1; } if (process(lookup_unknown_object(sha1))) { - unlock_ref(lock); + if (lock) + unlock_ref(lock); return -1; } if (loop()) { - unlock_ref(lock); + if (lock) + unlock_ref(lock); return -1; } -- cgit v1.2.1