Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-02-23 09:54:37 +0300
committerJunio C Hamano <gitster@pobox.com>2008-02-23 09:54:37 +0300
commit50f3ac29cbadbf7e0ff099b493b00cfa4129e1e0 (patch)
tree72b756b4c7d60709b7484cceeb3a1d82a18a86af /builtin-reflog.c
parentcb97cc9fef60ea2ff1ce51cf575314c04488dbfd (diff)
parent4cd883d724ec36a120263d47058e65c6d1de642f (diff)
Merge branch 'bc/reflog-fix' into js/reflog-delete
* bc/reflog-fix: (1490 commits) builtin-reflog.c: don't install new reflog on write failure hash: fix lookup_hash semantics gitweb: Better chopping in commit search results builtin-tag.c: remove cruft git-merge-index documentation: clarify synopsis send-email: fix In-Reply-To regression git-reset --hard and git-read-tree --reset: fix read_cache_unmerged() Teach git-grep --name-only as synonym for -l diff: fix java funcname pattern for solaris t3404: use configured shell instead of /bin/sh git_config_*: don't assume we are parsing a config file prefix_path: use is_absolute_path() instead of *orig == '/' git-clean: handle errors if removing files fails Clarified the meaning of git-add -u in the documentation git-clone.sh: properly configure remote even if remote's head is dangling git.el: Set process-environment instead of invoking env Documentation/git-stash: document options for git stash list send-email: squelch warning due to comparing undefined $_ to "" cvsexportcommit: be graceful when "cvs status" reorders the arguments Rename git-core rpm to just git and rename the meta-pacakge to git-all. ... Conflicts: Documentation/git-reflog.txt t/t1410-reflog.sh
Diffstat (limited to 'builtin-reflog.c')
-rw-r--r--builtin-reflog.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 5e5498945f..8af75bc3e1 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -35,6 +35,16 @@ struct expire_reflog_cb {
struct cmd_reflog_expire_cb *cmd;
};
+struct collected_reflog {
+ unsigned char sha1[20];
+ char reflog[FLEX_ARRAY];
+};
+struct collect_reflog_cb {
+ struct collected_reflog **e;
+ int alloc;
+ int nr;
+};
+
#define INCOMPLETE (1u<<10)
#define STUDYING (1u<<11)
@@ -270,10 +280,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
for_each_reflog_ent(ref, expire_reflog_ent, &cb);
finish:
if (cb.newlog) {
- if (fclose(cb.newlog))
+ if (fclose(cb.newlog)) {
status |= error("%s: %s", strerror(errno),
newlog_path);
- if (rename(newlog_path, log_file)) {
+ unlink(newlog_path);
+ } else if (rename(newlog_path, log_file)) {
status |= error("cannot rename %s to %s",
newlog_path, log_file);
unlink(newlog_path);
@@ -285,15 +296,35 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
return status;
}
+static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data)
+{
+ struct collected_reflog *e;
+ struct collect_reflog_cb *cb = cb_data;
+ size_t namelen = strlen(ref);
+
+ e = xmalloc(sizeof(*e) + namelen + 1);
+ hashcpy(e->sha1, sha1);
+ memcpy(e->reflog, ref, namelen + 1);
+ ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
+ cb->e[cb->nr++] = e;
+ return 0;
+}
+
static int reflog_expire_config(const char *var, const char *value)
{
- if (!strcmp(var, "gc.reflogexpire"))
+ if (!strcmp(var, "gc.reflogexpire")) {
+ if (!value)
+ config_error_nonbool(var);
default_reflog_expire = approxidate(value);
- else if (!strcmp(var, "gc.reflogexpireunreachable"))
+ return 0;
+ }
+ if (!strcmp(var, "gc.reflogexpireunreachable")) {
+ if (!value)
+ config_error_nonbool(var);
default_reflog_expire_unreachable = approxidate(value);
- else
- return git_default_config(var, value);
- return 0;
+ return 0;
+ }
+ return git_default_config(var, value);
}
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
@@ -353,8 +384,20 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
putchar('\n');
}
- if (do_all)
- status |= for_each_reflog(expire_reflog, &cb);
+ if (do_all) {
+ struct collect_reflog_cb collected;
+ int i;
+
+ memset(&collected, 0, sizeof(collected));
+ for_each_reflog(collect_reflog, &collected);
+ for (i = 0; i < collected.nr; i++) {
+ struct collected_reflog *e = collected.e[i];
+ status |= expire_reflog(e->reflog, e->sha1, 0, &cb);
+ free(e);
+ }
+ free(collected.e);
+ }
+
while (i < argc) {
const char *ref = argv[i++];
unsigned char sha1[20];