From: Junio C Hamano Date: Wed, 27 Dec 2006 07:47:40 +0000 (-0800) Subject: Merge branch 'jc/fsck-reflog' X-Git-Tag: v1.5.0-rc1~188 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e8b4029f990907e24fac0e7772ee19ee6dd55c1c?hp=-c Merge branch 'jc/fsck-reflog' * jc/fsck-reflog: Add git-reflog to .gitignore reflog expire: do not punt on tags that point at non commits. reflog expire: prune commits that are not incomplete Don't crash during repack of a reflog with pruned commits. git reflog expire Move in_merge_bases() to commit.c reflog: fix warning message. Teach git-repack to preserve objects referred to by reflog entries. Protect commits recorded in reflog from pruning. add for_each_reflog_ent() iterator --- e8b4029f990907e24fac0e7772ee19ee6dd55c1c diff --combined .gitignore index 98e513de53,255789a8b6..60e5002bd5 --- a/.gitignore +++ b/.gitignore @@@ -2,7 -2,6 +2,7 @@@ GIT-CFLAG GIT-VERSION-FILE git git-add +git-add--interactive git-am git-annotate git-apply @@@ -11,7 -10,6 +11,7 @@@ git-applypatc git-archimport git-archive git-bisect +git-blame git-branch git-cat-file git-check-ref-format @@@ -89,6 -87,7 +89,7 @@@ git-quiltimpor git-read-tree git-rebase git-receive-pack + git-reflog git-relink git-repack git-repo-config @@@ -154,3 -153,4 +155,3 @@@ config.statu config.mak.autogen config.mak.append configure -git-blame diff --combined Makefile index 475047f100,d4d8590b6e..52d4a3a86a --- a/Makefile +++ b/Makefile @@@ -79,6 -79,9 +79,6 @@@ all # # Define NO_ICONV if your libc does not properly support iconv. # -# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses -# a missing newline at the end of the file. -# # Define USE_NSEC below if you want git to care about sub-second file mtimes # and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and # it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely @@@ -170,8 -173,8 +170,8 @@@ SCRIPT_SH = git-lost-found.sh git-quiltimport.sh SCRIPT_PERL = \ + git-add--interactive.perl \ git-archimport.perl git-cvsimport.perl git-relink.perl \ - git-rerere.perl \ git-cvsserver.perl \ git-svnimport.perl git-cvsexportcommit.perl \ git-send-email.perl git-svn.perl @@@ -230,8 -233,7 +230,8 @@@ LIB_H = archive.h blob.h cache.h commit.h csum-file.h delta.h grep.h \ diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ - tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h + tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \ + utf8.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \ @@@ -250,8 -252,7 +250,8 @@@ LIB_OBJS = revision.o pager.o tree-walk.o xdiff-interface.o \ write_or_die.o trace.o list-objects.o grep.o \ alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \ - color.o wt-status.o archive-zip.o archive-tar.o + color.o wt-status.o archive-zip.o archive-tar.o \ + utf8.o BUILTIN_OBJS = \ builtin-add.o \ @@@ -287,8 -288,8 +287,9 @@@ builtin-prune-packed.o \ builtin-push.o \ builtin-read-tree.o \ + builtin-reflog.o \ builtin-repo-config.o \ + builtin-rerere.o \ builtin-rev-list.o \ builtin-rev-parse.o \ builtin-rm.o \ @@@ -549,6 -550,9 +550,6 @@@ els endif endif endif -ifdef NO_ACCURATE_DIFF - BASIC_CFLAGS += -DNO_ACCURATE_DIFF -endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif @@@ -827,8 -831,6 +828,8 @@@ install: al install-doc: $(MAKE) -C Documentation install +quick-install-doc: + $(MAKE) -C Documentation quick-install diff --combined builtin.h index 8ffd8b2653,fdc0907eca..df72d09447 --- a/builtin.h +++ b/builtin.h @@@ -51,8 -51,8 +51,9 @@@ extern int cmd_prune(int argc, const ch extern int cmd_prune_packed(int argc, const char **argv, const char *prefix); extern int cmd_push(int argc, const char **argv, const char *prefix); extern int cmd_read_tree(int argc, const char **argv, const char *prefix); + extern int cmd_reflog(int argc, const char **argv, const char *prefix); extern int cmd_repo_config(int argc, const char **argv, const char *prefix); +extern int cmd_rerere(int argc, const char **argv, const char *prefix); extern int cmd_rev_list(int argc, const char **argv, const char *prefix); extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); extern int cmd_rm(int argc, const char **argv, const char *prefix); diff --combined git.c index e732a098fc,5822296e6e..50ebd869ad --- a/git.c +++ b/git.c @@@ -59,10 -59,8 +59,10 @@@ static int handle_options(const char** } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { setup_pager(); } else if (!strcmp(cmd, "--git-dir")) { - if (*argc < 1) - return -1; + if (*argc < 2) { + fprintf(stderr, "No directory given for --git-dir.\n" ); + usage(git_usage_string); + } setenv("GIT_DIR", (*argv)[1], 1); (*argv)++; (*argc)--; @@@ -246,8 -244,8 +246,9 @@@ static void handle_internal_command(in { "prune-packed", cmd_prune_packed, RUN_SETUP }, { "push", cmd_push, RUN_SETUP }, { "read-tree", cmd_read_tree, RUN_SETUP }, + { "reflog", cmd_reflog, RUN_SETUP }, { "repo-config", cmd_repo_config }, + { "rerere", cmd_rerere, RUN_SETUP }, { "rev-list", cmd_rev_list, RUN_SETUP }, { "rev-parse", cmd_rev_parse, RUN_SETUP }, { "rm", cmd_rm, RUN_SETUP }, diff --combined revision.c index e7eccd9180,4f6de2dfdd..af9f87418c --- a/revision.c +++ b/revision.c @@@ -464,21 -464,69 +464,69 @@@ static void limit_list(struct rev_info revs->commits = newlist; } - static int all_flags; - static struct rev_info *all_revs; + struct all_refs_cb { + int all_flags; + int warned_bad_reflog; + struct rev_info *all_revs; + const char *name_for_errormsg; + }; static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) { - struct object *object = get_reference(all_revs, path, sha1, all_flags); - add_pending_object(all_revs, object, ""); + struct all_refs_cb *cb = cb_data; + struct object *object = get_reference(cb->all_revs, path, sha1, + cb->all_flags); + add_pending_object(cb->all_revs, object, ""); return 0; } static void handle_all(struct rev_info *revs, unsigned flags) { - all_revs = revs; - all_flags = flags; - for_each_ref(handle_one_ref, NULL); + struct all_refs_cb cb; + cb.all_revs = revs; + cb.all_flags = flags; + for_each_ref(handle_one_ref, &cb); + } + + static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data) + { + struct all_refs_cb *cb = cb_data; + if (!is_null_sha1(sha1)) { + struct object *o = parse_object(sha1); + if (o) { + o->flags |= cb->all_flags; + add_pending_object(cb->all_revs, o, ""); + } + else if (!cb->warned_bad_reflog) { + warn("reflog of '%s' references pruned commits", + cb->name_for_errormsg); + cb->warned_bad_reflog = 1; + } + } + } + + static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data) + { + handle_one_reflog_commit(osha1, cb_data); + handle_one_reflog_commit(nsha1, cb_data); + return 0; + } + + static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data) + { + struct all_refs_cb *cb = cb_data; + cb->warned_bad_reflog = 0; + cb->name_for_errormsg = path; + for_each_reflog_ent(path, handle_one_reflog_ent, cb_data); + return 0; + } + + static void handle_reflog(struct rev_info *revs, unsigned flags) + { + struct all_refs_cb cb; + cb.all_revs = revs; + cb.all_flags = flags; + for_each_ref(handle_one_reflog, &cb); } static int add_parents_only(struct rev_info *revs, const char *arg, int flags) @@@ -526,7 -574,6 +574,7 @@@ void init_revisions(struct rev_info *re revs->prefix = prefix; revs->max_age = -1; revs->min_age = -1; + revs->skip_count = -1; revs->max_count = -1; revs->prune_fn = NULL; @@@ -763,10 -810,6 +811,10 @@@ int setup_revisions(int argc, const cha revs->max_count = atoi(arg + 12); continue; } + if (!strncmp(arg, "--skip=", 7)) { + revs->skip_count = atoi(arg + 7); + continue; + } /* accept -, like traditional "head" */ if ((*arg == '-') && isdigit(arg[1])) { revs->max_count = atoi(arg + 1); @@@ -810,6 -853,10 +858,10 @@@ handle_all(revs, flags); continue; } + if (!strcmp(arg, "--reflog")) { + handle_reflog(revs, flags); + continue; + } if (!strcmp(arg, "--not")) { flags ^= UNINTERESTING; continue; @@@ -1134,11 -1181,23 +1186,11 @@@ static int commit_match(struct commit * commit->buffer, strlen(commit->buffer)); } -struct commit *get_revision(struct rev_info *revs) +static struct commit *get_revision_1(struct rev_info *revs) { - struct commit_list *list = revs->commits; - - if (!list) + if (!revs->commits) return NULL; - /* Check the max_count ... */ - switch (revs->max_count) { - case -1: - break; - case 0: - return NULL; - default: - revs->max_count--; - } - do { struct commit_list *entry = revs->commits; struct commit *commit = entry->item; @@@ -1205,28 -1264,3 +1257,28 @@@ } while (revs->commits); return NULL; } + +struct commit *get_revision(struct rev_info *revs) +{ + struct commit *c = NULL; + + if (0 < revs->skip_count) { + while ((c = get_revision_1(revs)) != NULL) { + if (revs->skip_count-- <= 0) + break; + } + } + + /* Check the max_count ... */ + switch (revs->max_count) { + case -1: + break; + case 0: + return NULL; + default: + revs->max_count--; + } + if (c) + return c; + return get_revision_1(revs); +}