diff options
author | Junio C Hamano <junkio@cox.net> | 2007-02-04 16:54:47 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-04 16:54:47 -0800 |
commit | d1f289c5aa52bb77dc4959fb21cef032d954869f (patch) | |
tree | 525c95c67c6ae06278a99f244dc5d120c45a8747 /builtin-reflog.c | |
parent | Why is it bad to rewind a branch that has already been pushed out? (diff) | |
parent | show-branch -g: default to the current branch. (diff) | |
download | tgif-d1f289c5aa52bb77dc4959fb21cef032d954869f.tar.xz |
Merge branch 'np/dreflog'
* np/dreflog:
show-branch -g: default to the current branch.
Let git-checkout always drop any detached head
Enable HEAD@{...} and make it independent from the current branch
scan reflogs independently from refs
add reflog when moving HEAD to a new branch
create_symref(): do not assume pathname from git_path() persists long enough
add logref support to git-symbolic-ref
move create_symref() past log_ref_write()
add reflog entries for HEAD when detached
enable separate reflog for HEAD
lock_ref_sha1_basic(): remember the original name of a ref when resolving it
make reflog filename independent from struct ref_lock
Diffstat (limited to 'builtin-reflog.c')
-rw-r--r-- | builtin-reflog.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/builtin-reflog.c b/builtin-reflog.c index b443ed9ef6..bfb169ac04 100644 --- a/builtin-reflog.c +++ b/builtin-reflog.c @@ -242,20 +242,18 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, struct cmd_reflog_expire_cb *cmd = cb_data; struct expire_reflog_cb cb; struct ref_lock *lock; - char *newlog_path = NULL; + char *log_file, *newlog_path = NULL; int status = 0; - if (strncmp(ref, "refs/", 5)) - return error("not a ref '%s'", ref); - memset(&cb, 0, sizeof(cb)); /* we take the lock for the ref itself to prevent it from * getting updated. */ - lock = lock_ref_sha1(ref + 5, sha1); + lock = lock_any_ref_for_update(ref, sha1); if (!lock) return error("cannot lock ref '%s'", ref); - if (!file_exists(lock->log_file)) + log_file = xstrdup(git_path("logs/%s", ref)); + if (!file_exists(log_file)) goto finish; if (!cmd->dry_run) { newlog_path = xstrdup(git_path("logs/%s.lock", ref)); @@ -271,13 +269,14 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, if (fclose(cb.newlog)) status |= error("%s: %s", strerror(errno), newlog_path); - if (rename(newlog_path, lock->log_file)) { + if (rename(newlog_path, log_file)) { status |= error("cannot rename %s to %s", - newlog_path, lock->log_file); + newlog_path, log_file); unlink(newlog_path); } } free(newlog_path); + free(log_file); unlock_ref(lock); return status; } @@ -351,7 +350,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) } if (do_all) - status |= for_each_ref(expire_reflog, &cb); + status |= for_each_reflog(expire_reflog, &cb); while (i < argc) { const char *ref = argv[i++]; unsigned char sha1[20]; |