From 3631bf77f75bc34e810216f3ec6abc8203e2d16a Mon Sep 17 00:00:00 2001 From: Erick Mattos Date: Fri, 21 May 2010 21:28:37 -0300 Subject: checkout --orphan: respect -l option always Added changes to satisfy a corner case: creating reflogs by using -l when core.logAllRefUpdates is set to false. Signed-off-by: Erick Mattos Signed-off-by: Junio C Hamano --- builtin/checkout.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index c3825219c1..9d618c21d2 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -493,7 +493,24 @@ static void update_refs_for_switch(struct checkout_opts *opts, struct strbuf msg = STRBUF_INIT; const char *old_desc; if (opts->new_branch) { - if (!opts->new_orphan_branch) + if (opts->new_orphan_branch) { + if (opts->new_branch_log && !log_all_ref_updates) { + int temp; + char *log_file; + char *ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch); + + temp = log_all_ref_updates; + log_all_ref_updates = 1; + if (log_ref_setup(ref_name, &log_file)) { + fprintf(stderr, "Can not do reflog for '%s'\n", + opts->new_orphan_branch); + log_all_ref_updates = temp; + return; + } + log_all_ref_updates = temp; + } + } + else create_branch(old->name, opts->new_branch, new->name, 0, opts->new_branch_log, opts->track); new->name = opts->new_branch; @@ -517,6 +534,14 @@ static void update_refs_for_switch(struct checkout_opts *opts, opts->new_branch ? " a new" : "", new->name); } + if (old->path && old->name) { + char log_file[PATH_MAX], ref_file[PATH_MAX]; + + git_snpath(log_file, sizeof(log_file), "logs/%s", old->path); + git_snpath(ref_file, sizeof(ref_file), "%s", old->path); + if (!file_exists(ref_file) && file_exists(log_file)) + remove_path(log_file); + } } else if (strcmp(new->name, "HEAD")) { update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL, REF_NODEREF, DIE_ON_ERR); @@ -684,8 +709,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) if (opts.new_orphan_branch) { if (opts.new_branch) die("--orphan and -b are mutually exclusive"); - if (opts.track > 0 || opts.new_branch_log) - die("--orphan cannot be used with -t or -l"); + if (opts.track > 0) + die("--orphan cannot be used with -t"); opts.new_branch = opts.new_orphan_branch; } -- cgit v1.3 From 157aaea5fff7dbf2fc39829d827b35df647562a4 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Thu, 10 Jun 2010 14:54:03 +0200 Subject: log_ref_setup: don't return stack-allocated array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 859c301 (refs: split log_ref_write logic into log_ref_setup, 2010-05-21) refactors the stack allocation of the log_file array into the new log_ref_setup() function, but passes it back to the caller. Since the original intent seems to have been to split the work between log_ref_setup and log_ref_write, make it the caller's responsibility to allocate the buffer. Signed-off-by: Thomas Rast Reported-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/checkout.c | 4 ++-- refs.c | 26 ++++++++++++-------------- refs.h | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index 9d618c21d2..72e4fbc729 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -496,12 +496,12 @@ static void update_refs_for_switch(struct checkout_opts *opts, if (opts->new_orphan_branch) { if (opts->new_branch_log && !log_all_ref_updates) { int temp; - char *log_file; + char log_file[PATH_MAX]; char *ref_name = mkpath("refs/heads/%s", opts->new_orphan_branch); temp = log_all_ref_updates; log_all_ref_updates = 1; - if (log_ref_setup(ref_name, &log_file)) { + if (log_ref_setup(ref_name, log_file, sizeof(log_file))) { fprintf(stderr, "Can not do reflog for '%s'\n", opts->new_orphan_branch); log_all_ref_updates = temp; diff --git a/refs.c b/refs.c index 1161c2d0d9..10abda7d0d 100644 --- a/refs.c +++ b/refs.c @@ -1258,43 +1258,41 @@ static int copy_msg(char *buf, const char *msg) return cp - buf; } -int log_ref_setup(const char *ref_name, char **log_file) +int log_ref_setup(const char *ref_name, char *logfile, int bufsize) { int logfd, oflags = O_APPEND | O_WRONLY; - char logfile[PATH_MAX]; - git_snpath(logfile, sizeof(logfile), "logs/%s", ref_name); - *log_file = logfile; + git_snpath(logfile, bufsize, "logs/%s", ref_name); if (log_all_ref_updates && (!prefixcmp(ref_name, "refs/heads/") || !prefixcmp(ref_name, "refs/remotes/") || !prefixcmp(ref_name, "refs/notes/") || !strcmp(ref_name, "HEAD"))) { - if (safe_create_leading_directories(*log_file) < 0) + if (safe_create_leading_directories(logfile) < 0) return error("unable to create directory for %s", - *log_file); + logfile); oflags |= O_CREAT; } - logfd = open(*log_file, oflags, 0666); + logfd = open(logfile, oflags, 0666); if (logfd < 0) { if (!(oflags & O_CREAT) && errno == ENOENT) return 0; if ((oflags & O_CREAT) && errno == EISDIR) { - if (remove_empty_directories(*log_file)) { + if (remove_empty_directories(logfile)) { return error("There are still logs under '%s'", - *log_file); + logfile); } - logfd = open(*log_file, oflags, 0666); + logfd = open(logfile, oflags, 0666); } if (logfd < 0) return error("Unable to append to %s: %s", - *log_file, strerror(errno)); + logfile, strerror(errno)); } - adjust_shared_perm(*log_file); + adjust_shared_perm(logfile); close(logfd); return 0; } @@ -1305,14 +1303,14 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, int logfd, result, written, oflags = O_APPEND | O_WRONLY; unsigned maxlen, len; int msglen; - char *log_file; + char log_file[PATH_MAX]; char *logrec; const char *committer; if (log_all_ref_updates < 0) log_all_ref_updates = !is_bare_repository(); - result = log_ref_setup(ref_name, &log_file); + result = log_ref_setup(ref_name, log_file, sizeof(log_file)); if (result) return result; diff --git a/refs.h b/refs.h index 594c9d97fd..762ce504b5 100644 --- a/refs.h +++ b/refs.h @@ -69,7 +69,7 @@ extern void unlock_ref(struct ref_lock *lock); extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg); /** Setup reflog before using. **/ -int log_ref_setup(const char *ref_name, char **log_file); +int log_ref_setup(const char *ref_name, char *logfile, int bufsize); /** Reads log for the value of ref during at_time. **/ extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt); -- cgit v1.3