Merge branch 'jk/rev-list-count-with-bitmap'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:01:03 +0000 (11:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:01:03 +0000 (11:01 -0700)
"git rev-list --count" whose walk-length is limited with "-n"
option did not work well with the counting optimized to look at the
bitmap index.

* jk/rev-list-count-with-bitmap:
  rev-list: disable bitmaps when "-n" is used with listing objects
  rev-list: "adjust" results of "--count --use-bitmap-index -n"

1  2 
builtin/rev-list.c

diff --combined builtin/rev-list.c
@@@ -81,14 -81,14 +81,14 @@@ static void show_commit(struct commit *
        if (!revs->graph)
                fputs(get_revision_mark(revs, commit), stdout);
        if (revs->abbrev_commit && revs->abbrev)
 -              fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
 +              fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev),
                      stdout);
        else
 -              fputs(sha1_to_hex(commit->object.sha1), stdout);
 +              fputs(oid_to_hex(&commit->object.oid), stdout);
        if (revs->print_parents) {
                struct commit_list *parents = commit->parents;
                while (parents) {
 -                      printf(" %s", sha1_to_hex(parents->item->object.sha1));
 +                      printf(" %s", oid_to_hex(&parents->item->object.oid));
                        parents = parents->next;
                }
        }
@@@ -97,7 -97,7 +97,7 @@@
  
                children = lookup_decoration(&revs->children, &commit->object);
                while (children) {
 -                      printf(" %s", sha1_to_hex(children->item->object.sha1));
 +                      printf(" %s", oid_to_hex(&children->item->object.oid));
                        children = children->next;
                }
        }
@@@ -180,10 -180,10 +180,10 @@@ static void finish_commit(struct commi
  static void finish_object(struct object *obj, const char *name, void *cb_data)
  {
        struct rev_list_info *info = cb_data;
 -      if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
 -              die("missing blob object '%s'", sha1_to_hex(obj->sha1));
 +      if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
 +              die("missing blob object '%s'", oid_to_hex(&obj->oid));
        if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
 -              parse_object(obj->sha1);
 +              parse_object(obj->oid.hash);
  }
  
  static void show_object(struct object *obj, const char *name, void *cb_data)
  
  static void show_edge(struct commit *commit)
  {
 -      printf("-%s\n", sha1_to_hex(commit->object.sha1));
 +      printf("-%s\n", oid_to_hex(&commit->object.oid));
  }
  
  static void print_var_str(const char *var, const char *val)
@@@ -213,7 -213,7 +213,7 @@@ static void print_var_int(const char *v
  static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
  {
        int cnt, flags = info->flags;
 -      char hex[41] = "";
 +      char hex[GIT_SHA1_HEXSZ + 1] = "";
        struct commit_list *tried;
        struct rev_info *revs = info->revs;
  
                cnt = reaches;
  
        if (revs->commits)
 -              strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
 +              sha1_to_hex_r(hex, revs->commits->item->object.oid.hash);
  
        if (flags & BISECT_SHOW_ALL) {
                traverse_commit_list(revs, show_commit, show_object, info);
@@@ -346,9 -346,6 +346,9 @@@ int cmd_rev_list(int argc, const char *
            revs.diff)
                usage(rev_list_usage);
  
 +      if (revs.show_notes)
 +              die(_("rev-list does not support display of notes"));
 +
        save_commit_buffer = (revs.verbose_header ||
                              revs.grep_filter.pattern_list ||
                              revs.grep_filter.header_list);
        if (use_bitmap_index && !revs.prune) {
                if (revs.count && !revs.left_right && !revs.cherry_mark) {
                        uint32_t commit_count;
+                       int max_count = revs.max_count;
                        if (!prepare_bitmap_walk(&revs)) {
                                count_bitmap_commit_list(&commit_count, NULL, NULL, NULL);
+                               if (max_count >= 0 && max_count < commit_count)
+                                       commit_count = max_count;
                                printf("%d\n", commit_count);
                                return 0;
                        }
-               } else if (revs.tag_objects && revs.tree_objects && revs.blob_objects) {
+               } else if (revs.max_count < 0 &&
+                          revs.tag_objects && revs.tree_objects && revs.blob_objects) {
                        if (!prepare_bitmap_walk(&revs)) {
                                traverse_bitmap_commit_list(&show_object_fast);
                                return 0;