Merge branch 'jk/maint-reflog-bottom' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 14 Dec 2010 15:35:50 +0000 (07:35 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Dec 2010 15:35:50 +0000 (07:35 -0800)
* jk/maint-reflog-bottom:
reflogs: clear flags properly in corner case

1  2 
reflog-walk.c
revision.c
diff --combined reflog-walk.c
index 4879615cad7527dc5346cd1a85bd56b9d11e052b,0cf2f7dbad8b7662f4cdd08f398f7fe1ab874d8e..5d81d39a525830f6bacba88143ab6a4552748441
@@@ -162,7 -162,7 +162,7 @@@ int add_reflog_for_walk(struct reflog_w
        } else
                recno = 0;
  
 -      item = string_list_lookup(branch, &info->complete_reflogs);
 +      item = string_list_lookup(&info->complete_reflogs, branch);
        if (item)
                reflogs = item->util;
        else {
                }
                if (!reflogs || reflogs->nr == 0)
                        return -1;
 -              string_list_insert(branch, &info->complete_reflogs)->util
 +              string_list_insert(&info->complete_reflogs, branch)->util
                        = reflogs;
        }
  
@@@ -239,7 -239,6 +239,6 @@@ void fake_reflog_parent(struct reflog_w
  
        commit->parents = xcalloc(sizeof(struct commit_list), 1);
        commit->parents->item = commit_info->commit;
-       commit->object.flags &= ~(ADDED | SEEN | SHOWN);
  }
  
  void get_reflog_selector(struct strbuf *sb,
diff --combined revision.c
index b1c18906badc5fc4ce3af48daa7c226365e3c08f,890aeaeb6dd5847e64b827747cb402629fb4e20b..ded881263ba0ff703d9fd468e6785270ea68df5f
@@@ -646,93 -646,6 +646,93 @@@ static int still_interesting(struct com
        return slop-1;
  }
  
 +/*
 + * "rev-list --ancestry-path A..B" computes commits that are ancestors
 + * of B but not ancestors of A but further limits the result to those
 + * that are descendants of A.  This takes the list of bottom commits and
 + * the result of "A..B" without --ancestry-path, and limits the latter
 + * further to the ones that can reach one of the commits in "bottom".
 + */
 +static void limit_to_ancestry(struct commit_list *bottom, struct commit_list *list)
 +{
 +      struct commit_list *p;
 +      struct commit_list *rlist = NULL;
 +      int made_progress;
 +
 +      /*
 +       * Reverse the list so that it will be likely that we would
 +       * process parents before children.
 +       */
 +      for (p = list; p; p = p->next)
 +              commit_list_insert(p->item, &rlist);
 +
 +      for (p = bottom; p; p = p->next)
 +              p->item->object.flags |= TMP_MARK;
 +
 +      /*
 +       * Mark the ones that can reach bottom commits in "list",
 +       * in a bottom-up fashion.
 +       */
 +      do {
 +              made_progress = 0;
 +              for (p = rlist; p; p = p->next) {
 +                      struct commit *c = p->item;
 +                      struct commit_list *parents;
 +                      if (c->object.flags & (TMP_MARK | UNINTERESTING))
 +                              continue;
 +                      for (parents = c->parents;
 +                           parents;
 +                           parents = parents->next) {
 +                              if (!(parents->item->object.flags & TMP_MARK))
 +                                      continue;
 +                              c->object.flags |= TMP_MARK;
 +                              made_progress = 1;
 +                              break;
 +                      }
 +              }
 +      } while (made_progress);
 +
 +      /*
 +       * NEEDSWORK: decide if we want to remove parents that are
 +       * not marked with TMP_MARK from commit->parents for commits
 +       * in the resulting list.  We may not want to do that, though.
 +       */
 +
 +      /*
 +       * The ones that are not marked with TMP_MARK are uninteresting
 +       */
 +      for (p = list; p; p = p->next) {
 +              struct commit *c = p->item;
 +              if (c->object.flags & TMP_MARK)
 +                      continue;
 +              c->object.flags |= UNINTERESTING;
 +      }
 +
 +      /* We are done with the TMP_MARK */
 +      for (p = list; p; p = p->next)
 +              p->item->object.flags &= ~TMP_MARK;
 +      for (p = bottom; p; p = p->next)
 +              p->item->object.flags &= ~TMP_MARK;
 +      free_commit_list(rlist);
 +}
 +
 +/*
 + * Before walking the history, keep the set of "negative" refs the
 + * caller has asked to exclude.
 + *
 + * This is used to compute "rev-list --ancestry-path A..B", as we need
 + * to filter the result of "A..B" further to the ones that can actually
 + * reach A.
 + */
 +static struct commit_list *collect_bottom_commits(struct commit_list *list)
 +{
 +      struct commit_list *elem, *bottom = NULL;
 +      for (elem = list; elem; elem = elem->next)
 +              if (elem->item->object.flags & UNINTERESTING)
 +                      commit_list_insert(elem->item, &bottom);
 +      return bottom;
 +}
 +
  static int limit_list(struct rev_info *revs)
  {
        int slop = SLOP;
        struct commit_list *list = revs->commits;
        struct commit_list *newlist = NULL;
        struct commit_list **p = &newlist;
 +      struct commit_list *bottom = NULL;
 +
 +      if (revs->ancestry_path) {
 +              bottom = collect_bottom_commits(list);
 +              if (!bottom)
 +                      die("--ancestry-path given but there are no bottom commits");
 +      }
  
        while (list) {
                struct commit_list *entry = list;
        if (revs->cherry_pick)
                cherry_pick_list(newlist, revs);
  
 +      if (bottom) {
 +              limit_to_ancestry(bottom, newlist);
 +              free_commit_list(bottom);
 +      }
 +
        revs->commits = newlist;
        return 0;
  }
@@@ -820,12 -721,12 +820,12 @@@ static void init_all_refs_cb(struct all
        cb->all_flags = flags;
  }
  
 -static void handle_refs(struct rev_info *revs, unsigned flags,
 -              int (*for_each)(each_ref_fn, void *))
 +static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
 +              int (*for_each)(const char *, each_ref_fn, void *))
  {
        struct all_refs_cb cb;
        init_all_refs_cb(&cb, revs, flags);
 -      for_each(handle_one_ref, &cb);
 +      for_each(submodule, handle_one_ref, &cb);
  }
  
  static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
@@@ -1148,8 -1049,6 +1148,8 @@@ static int handle_revision_opt(struct r
                               int *unkc, const char **unkv)
  {
        const char *arg = argv[0];
 +      const char *optarg;
 +      int argcount;
  
        /* pseudo revision arguments */
        if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") ||
                return 1;
        }
  
 -      if (!prefixcmp(arg, "--max-count=")) {
 -              revs->max_count = atoi(arg + 12);
 -      } else if (!prefixcmp(arg, "--skip=")) {
 -              revs->skip_count = atoi(arg + 7);
 +      if ((argcount = parse_long_opt("max-count", argv, &optarg))) {
 +              revs->max_count = atoi(optarg);
 +              revs->no_walk = 0;
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("skip", argv, &optarg))) {
 +              revs->skip_count = atoi(optarg);
 +              return argcount;
        } else if ((*arg == '-') && isdigit(arg[1])) {
        /* accept -<digit>, like traditional "head" */
                revs->max_count = atoi(arg + 1);
 +              revs->no_walk = 0;
        } else if (!strcmp(arg, "-n")) {
                if (argc <= 1)
                        return error("-n requires an argument");
                revs->max_count = atoi(argv[1]);
 +              revs->no_walk = 0;
                return 2;
        } else if (!prefixcmp(arg, "-n")) {
                revs->max_count = atoi(arg + 2);
 -      } else if (!prefixcmp(arg, "--max-age=")) {
 -              revs->max_age = atoi(arg + 10);
 -      } else if (!prefixcmp(arg, "--since=")) {
 -              revs->max_age = approxidate(arg + 8);
 -      } else if (!prefixcmp(arg, "--after=")) {
 -              revs->max_age = approxidate(arg + 8);
 -      } else if (!prefixcmp(arg, "--min-age=")) {
 -              revs->min_age = atoi(arg + 10);
 -      } else if (!prefixcmp(arg, "--before=")) {
 -              revs->min_age = approxidate(arg + 9);
 -      } else if (!prefixcmp(arg, "--until=")) {
 -              revs->min_age = approxidate(arg + 8);
 +              revs->no_walk = 0;
 +      } else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
 +              revs->max_age = atoi(optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("since", argv, &optarg))) {
 +              revs->max_age = approxidate(optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("after", argv, &optarg))) {
 +              revs->max_age = approxidate(optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("min-age", argv, &optarg))) {
 +              revs->min_age = atoi(optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("before", argv, &optarg))) {
 +              revs->min_age = approxidate(optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("until", argv, &optarg))) {
 +              revs->min_age = approxidate(optarg);
 +              return argcount;
        } else if (!strcmp(arg, "--first-parent")) {
                revs->first_parent_only = 1;
 +      } else if (!strcmp(arg, "--ancestry-path")) {
 +              revs->ancestry_path = 1;
 +              revs->simplify_history = 0;
 +              revs->limited = 1;
        } else if (!strcmp(arg, "-g") || !strcmp(arg, "--walk-reflogs")) {
                init_reflog_walk(&revs->reflog_info);
        } else if (!strcmp(arg, "--default")) {
                revs->boundary = 1;
        } else if (!strcmp(arg, "--left-right")) {
                revs->left_right = 1;
 +      } else if (!strcmp(arg, "--count")) {
 +              revs->count = 1;
        } else if (!strcmp(arg, "--cherry-pick")) {
                revs->cherry_pick = 1;
                revs->limited = 1;
                revs->pretty_given = 1;
                get_commit_format(arg+8, revs);
        } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
 +              /*
 +               * Detached form ("--pretty X" as opposed to "--pretty=X")
 +               * not allowed, since the argument is optional.
 +               */
                revs->verbose_header = 1;
                revs->pretty_given = 1;
                get_commit_format(arg+9, revs);
                else
                        strbuf_addstr(&buf, "refs/notes/");
                strbuf_addstr(&buf, arg+13);
 -              string_list_append(strbuf_detach(&buf, NULL),
 -                                 revs->notes_opt.extra_notes_refs);
 +              string_list_append(revs->notes_opt.extra_notes_refs,
 +                                 strbuf_detach(&buf, NULL));
        } else if (!strcmp(arg, "--no-notes")) {
                revs->show_notes = 0;
                revs->show_notes_given = 1;
        } else if (!strcmp(arg, "--relative-date")) {
                revs->date_mode = DATE_RELATIVE;
                revs->date_mode_explicit = 1;
 -      } else if (!strncmp(arg, "--date=", 7)) {
 -              revs->date_mode = parse_date_format(arg + 7);
 +      } else if ((argcount = parse_long_opt("date", argv, &optarg))) {
 +              revs->date_mode = parse_date_format(optarg);
                revs->date_mode_explicit = 1;
 +              return argcount;
        } else if (!strcmp(arg, "--log-size")) {
                revs->show_log_size = 1;
        }
        /*
         * Grepping the commit log
         */
 -      else if (!prefixcmp(arg, "--author=")) {
 -              add_header_grep(revs, GREP_HEADER_AUTHOR, arg+9);
 -      } else if (!prefixcmp(arg, "--committer=")) {
 -              add_header_grep(revs, GREP_HEADER_COMMITTER, arg+12);
 -      } else if (!prefixcmp(arg, "--grep=")) {
 -              add_message_grep(revs, arg+7);
 +      else if ((argcount = parse_long_opt("author", argv, &optarg))) {
 +              add_header_grep(revs, GREP_HEADER_AUTHOR, optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("committer", argv, &optarg))) {
 +              add_header_grep(revs, GREP_HEADER_COMMITTER, optarg);
 +              return argcount;
 +      } else if ((argcount = parse_long_opt("grep", argv, &optarg))) {
 +              add_message_grep(revs, optarg);
 +              return argcount;
        } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
                revs->grep_filter.regflags |= REG_EXTENDED;
        } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
                revs->grep_filter.fixed = 1;
        } else if (!strcmp(arg, "--all-match")) {
                revs->grep_filter.all_match = 1;
 -      } else if (!prefixcmp(arg, "--encoding=")) {
 -              arg += 11;
 -              if (strcmp(arg, "none"))
 -                      git_log_output_encoding = xstrdup(arg);
 +      } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
 +              if (strcmp(optarg, "none"))
 +                      git_log_output_encoding = xstrdup(optarg);
                else
                        git_log_output_encoding = "";
 +              return argcount;
        } else if (!strcmp(arg, "--reverse")) {
                revs->reverse ^= 1;
        } else if (!strcmp(arg, "--children")) {
@@@ -1435,14 -1308,14 +1435,14 @@@ void parse_revision_opt(struct rev_inf
        ctx->argc -= n;
  }
  
 -static int for_each_bad_bisect_ref(each_ref_fn fn, void *cb_data)
 +static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
  {
 -      return for_each_ref_in("refs/bisect/bad", fn, cb_data);
 +      return for_each_ref_in_submodule(submodule, "refs/bisect/bad", fn, cb_data);
  }
  
 -static int for_each_good_bisect_ref(each_ref_fn fn, void *cb_data)
 +static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
  {
 -      return for_each_ref_in("refs/bisect/good", fn, cb_data);
 +      return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
  }
  
  static void append_prune_data(const char ***prune_data, const char **av)
@@@ -1484,12 -1357,6 +1484,12 @@@ int setup_revisions(int argc, const cha
  {
        int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
        const char **prune_data = NULL;
 +      const char *submodule = NULL;
 +      const char *optarg;
 +      int argcount;
 +
 +      if (opt)
 +              submodule = opt->submodule;
  
        /* First, search for "--" */
        seen_dashdash = 0;
                        int opts;
  
                        if (!strcmp(arg, "--all")) {
 -                              handle_refs(revs, flags, for_each_ref);
 -                              handle_refs(revs, flags, head_ref);
 +                              handle_refs(submodule, revs, flags, for_each_ref_submodule);
 +                              handle_refs(submodule, revs, flags, head_ref_submodule);
                                continue;
                        }
                        if (!strcmp(arg, "--branches")) {
 -                              handle_refs(revs, flags, for_each_branch_ref);
 +                              handle_refs(submodule, revs, flags, for_each_branch_ref_submodule);
                                continue;
                        }
                        if (!strcmp(arg, "--bisect")) {
 -                              handle_refs(revs, flags, for_each_bad_bisect_ref);
 -                              handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
 +                              handle_refs(submodule, revs, flags, for_each_bad_bisect_ref);
 +                              handle_refs(submodule, revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
                                revs->bisect = 1;
                                continue;
                        }
                        if (!strcmp(arg, "--tags")) {
 -                              handle_refs(revs, flags, for_each_tag_ref);
 +                              handle_refs(submodule, revs, flags, for_each_tag_ref_submodule);
                                continue;
                        }
                        if (!strcmp(arg, "--remotes")) {
 -                              handle_refs(revs, flags, for_each_remote_ref);
 +                              handle_refs(submodule, revs, flags, for_each_remote_ref_submodule);
                                continue;
                        }
 -                      if (!prefixcmp(arg, "--glob=")) {
 +                      if ((argcount = parse_long_opt("glob", argv + i, &optarg))) {
                                struct all_refs_cb cb;
 +                              i += argcount - 1;
                                init_all_refs_cb(&cb, revs, flags);
 -                              for_each_glob_ref(handle_one_ref, arg + 7, &cb);
 +                              for_each_glob_ref(handle_one_ref, optarg, &cb);
                                continue;
                        }
                        if (!prefixcmp(arg, "--branches=")) {
@@@ -1915,7 -1781,7 +1915,7 @@@ int prepare_revision_walk(struct rev_in
  enum rewrite_result {
        rewrite_one_ok,
        rewrite_one_noparents,
 -      rewrite_one_error,
 +      rewrite_one_error
  };
  
  static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp)
@@@ -2030,8 -1896,10 +2030,10 @@@ static struct commit *get_revision_1(st
                revs->commits = entry->next;
                free(entry);
  
-               if (revs->reflog_info)
+               if (revs->reflog_info) {
                        fake_reflog_parent(revs->reflog_info, commit);
+                       commit->object.flags &= ~(ADDED | SEEN | SHOWN);
+               }
  
                /*
                 * If we haven't done the list limiting, we need to look at