@matheusbsbs / matheus-bagliano / commits / d0740d92be
Fork 0

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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed May 19, 2006 at 03:29 UTC d0740d92beb019a7b02678e5acea79c0ff67e3ee
6 files changed +27 -4
fetch.c
+15 -2
@@ -8,6 +8,7 @@
8 #include "refs.h"
9
10 const char *write_ref = NULL;
11 +const char *write_ref_log_details = NULL;
12
13 const unsigned char *current_ref = NULL;
14
@@ -206,13 +207,17 @@ int pull(char *target)
207 {
208 struct ref_lock *lock;
209 unsigned char sha1[20];
210 + char *msg;
211 + int ret;
212
213 save_commit_buffer = 0;
214 track_object_refs = 0;
215 if (write_ref) {
216 lock = lock_ref_sha1(write_ref, current_ref, 1);
214 - if (!lock)
217 + if (!lock) {
218 + error("Can't lock ref %s", write_ref);
219 return -1;
220 + }
221 }
222
223 if (!get_recover) {
@@ -234,7 +239,15 @@ int pull(char *target)
239 }
240
241 if (write_ref) {
237 - return write_ref_sha1(lock, sha1, "git fetch");
242 + if (write_ref_log_details) {
243 + msg = xmalloc(strlen(write_ref_log_details) + 12);
244 + sprintf(msg, "fetch from %s", write_ref_log_details);
245 + } else
246 + msg = NULL;
247 + ret = write_ref_sha1(lock, sha1, msg ? msg : "fetch (unknown)");
248 + if (msg)
249 + free(msg);
250 + return ret;
251 }
252 return 0;
253 }
fetch.h
+3
@@ -25,6 +25,9 @@ extern int fetch_ref(char *ref, unsigned char *sha1);
25 /* If set, the ref filename to write the target value to. */
26 extern const char *write_ref;
27
28 +/* If set additional text will appear in the ref log. */
29 +extern const char *write_ref_log_details;
30 +
31 /* If set, the hash that the current value of write_ref must be. */
32 extern const unsigned char *current_ref;
33
http-fetch.c
+2
@@ -1223,6 +1223,7 @@ int main(int argc, char **argv)
1223 int rc = 0;
1224
1225 setup_git_directory();
1226 + git_config(git_default_config);
1227
1228 while (arg < argc && argv[arg][0] == '-') {
1229 if (argv[arg][1] == 't') {
@@ -1249,6 +1250,7 @@ int main(int argc, char **argv)
1250 }
1251 commit_id = argv[arg];
1252 url = argv[arg + 1];
1253 + write_ref_log_details = url;
1254
1255 http_init();
1256
local-fetch.c
+2
@@ -208,6 +208,7 @@ int main(int argc, char **argv)
208 int arg = 1;
209
210 setup_git_directory();
211 + git_config(git_default_config);
212
213 while (arg < argc && argv[arg][0] == '-') {
214 if (argv[arg][1] == 't')
@@ -239,6 +240,7 @@ int main(int argc, char **argv)
240 usage(local_pull_usage);
241 commit_id = argv[arg];
242 path = argv[arg + 1];
243 + write_ref_log_details = path;
244
245 if (pull(commit_id))
246 return 1;
refs.c
+3 -2
@@ -142,6 +142,8 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
142 namelen = strlen(de->d_name);
143 if (namelen > 255)
144 continue;
145 + if (namelen>5 && !strcmp(de->d_name+namelen-5,".lock"))
146 + continue;
147 memcpy(path + baselen, de->d_name, namelen+1);
148 if (stat(git_path("%s", path), &st) < 0)
149 continue;
@@ -296,7 +298,6 @@ static struct ref_lock* lock_ref_sha1_basic(const char *path,
298 plen = strlen(path) - plen;
299 path = resolve_ref(path, lock->old_sha1, mustexist);
300 if (!path) {
299 - error("Can't read ref %s", path);
301 unlock_ref(lock);
302 return NULL;
303 }
@@ -326,7 +327,7 @@ struct ref_lock* lock_ref_sha1(const char *ref,
327 if (check_ref_format(ref))
328 return NULL;
329 return lock_ref_sha1_basic(git_path("refs/%s", ref),
329 - strlen(ref), old_sha1, mustexist);
330 + 5 + strlen(ref), old_sha1, mustexist);
331 }
332
333 struct ref_lock* lock_any_ref_for_update(const char *ref,
ssh-fetch.c
+2
@@ -132,6 +132,7 @@ int main(int argc, char **argv)
132 if (!prog) prog = "git-ssh-upload";
133
134 setup_git_directory();
135 + git_config(git_default_config);
136
137 while (arg < argc && argv[arg][0] == '-') {
138 if (argv[arg][1] == 't') {
@@ -158,6 +159,7 @@ int main(int argc, char **argv)
159 }
160 commit_id = argv[arg];
161 url = argv[arg + 1];
162 + write_ref_log_details = url;
163
164 if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1))
165 return 1;