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>
pull/288/head
Shawn Pearce 17 years ago committed by Junio C Hamano
parent 732232a123
commit d0740d92be
  1. 17
      fetch.c
  2. 3
      fetch.h
  3. 2
      http-fetch.c
  4. 2
      local-fetch.c
  5. 5
      refs.c
  6. 2
      ssh-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;
}

@ -25,6 +25,9 @@ extern int fetch_ref(char *ref, unsigned char *sha1);
/* If set, the ref filename to write the target value to. */
extern const char *write_ref;
/* If set additional text will appear in the ref log. */
extern const char *write_ref_log_details;
/* If set, the hash that the current value of write_ref must be. */
extern const unsigned char *current_ref;

@ -1223,6 +1223,7 @@ int main(int argc, char **argv)
int rc = 0;
setup_git_directory();
git_config(git_default_config);
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
@ -1249,6 +1250,7 @@ int main(int argc, char **argv)
}
commit_id = argv[arg];
url = argv[arg + 1];
write_ref_log_details = url;
http_init();

@ -208,6 +208,7 @@ int main(int argc, char **argv)
int arg = 1;
setup_git_directory();
git_config(git_default_config);
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't')
@ -239,6 +240,7 @@ int main(int argc, char **argv)
usage(local_pull_usage);
commit_id = argv[arg];
path = argv[arg + 1];
write_ref_log_details = path;
if (pull(commit_id))
return 1;

@ -142,6 +142,8 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
namelen = strlen(de->d_name);
if (namelen > 255)
continue;
if (namelen>5 && !strcmp(de->d_name+namelen-5,".lock"))
continue;
memcpy(path + baselen, de->d_name, namelen+1);
if (stat(git_path("%s", path), &st) < 0)
continue;
@ -296,7 +298,6 @@ static struct ref_lock* lock_ref_sha1_basic(const char *path,
plen = strlen(path) - plen;
path = resolve_ref(path, lock->old_sha1, mustexist);
if (!path) {
error("Can't read ref %s", path);
unlock_ref(lock);
return NULL;
}
@ -326,7 +327,7 @@ struct ref_lock* lock_ref_sha1(const char *ref,
if (check_ref_format(ref))
return NULL;
return lock_ref_sha1_basic(git_path("refs/%s", ref),
strlen(ref), old_sha1, mustexist);
5 + strlen(ref), old_sha1, mustexist);
}
struct ref_lock* lock_any_ref_for_update(const char *ref,

@ -132,6 +132,7 @@ int main(int argc, char **argv)
if (!prog) prog = "git-ssh-upload";
setup_git_directory();
git_config(git_default_config);
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
@ -158,6 +159,7 @@ int main(int argc, char **argv)
}
commit_id = argv[arg];
url = argv[arg + 1];
write_ref_log_details = url;
if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1))
return 1;

Loading…
Cancel
Save