Merge branch 'jc/simplify-progress'
authorJunio C Hamano <gitster@pobox.com>
Thu, 24 Aug 2017 17:20:02 +0000 (10:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Aug 2017 17:20:02 +0000 (10:20 -0700)
The API to start showing progress meter after a short delay has
been simplified.

* jc/simplify-progress:
progress: simplify "delayed" progress API

1  2 
builtin/fsck.c
builtin/log.c
builtin/rev-list.c
unpack-trees.c
diff --combined builtin/fsck.c
index b0964a8d3499a6a288985f92ade5568356bd6a56,0031439fc4a0e9b0cefad9ff70de976054c86d44..0ab13848a4937e826a5881d774d7a50c2526641a
@@@ -19,8 -19,6 +19,8 @@@
  #define REACHABLE 0x0001
  #define SEEN      0x0002
  #define HAS_OBJ   0x0004
 +/* This flag is set if something points to this object. */
 +#define USED      0x0008
  
  static int show_root;
  static int show_tags;
@@@ -170,7 -168,18 +170,7 @@@ static void mark_object_reachable(struc
  
  static int traverse_one_object(struct object *obj)
  {
 -      int result;
 -      struct tree *tree = NULL;
 -
 -      if (obj->type == OBJ_TREE) {
 -              tree = (struct tree *)obj;
 -              if (parse_tree(tree) < 0)
 -                      return 1; /* error already displayed */
 -      }
 -      result = fsck_walk(obj, obj, &fsck_walk_options);
 -      if (tree)
 -              free_tree_buffer(tree);
 -      return result;
 +      return fsck_walk(obj, obj, &fsck_walk_options);
  }
  
  static int traverse_reachable(void)
        unsigned int nr = 0;
        int result = 0;
        if (show_progress)
-               progress = start_progress_delay(_("Checking connectivity"), 0, 0, 2);
+               progress = start_delayed_progress(_("Checking connectivity"), 0);
        while (pending.nr) {
                struct object_array_entry *entry;
                struct object *obj;
@@@ -197,7 -206,7 +197,7 @@@ static int mark_used(struct object *obj
  {
        if (!obj)
                return 1;
 -      obj->used = 1;
 +      obj->flags |= USED;
        return 0;
  }
  
@@@ -246,7 -255,7 +246,7 @@@ static void check_unreachable_object(st
        }
  
        /*
 -       * "!used" means that nothing at all points to it, including
 +       * "!USED" means that nothing at all points to it, including
         * other unreachable objects. In other words, it's the "tip"
         * of some set of unreachable objects, usually a commit that
         * got dropped.
         * deleted a branch by mistake, this is a prime candidate to
         * start looking at, for example.
         */
 -      if (!obj->used) {
 +      if (!(obj->flags & USED)) {
                if (show_dangling)
                        printf("dangling %s %s\n", printable_type(obj),
                               describe_object(obj));
@@@ -326,8 -335,6 +326,8 @@@ static void check_connectivity(void
  
  static int fsck_obj(struct object *obj)
  {
 +      int err;
 +
        if (obj->flags & SEEN)
                return 0;
        obj->flags |= SEEN;
  
        if (fsck_walk(obj, NULL, &fsck_obj_options))
                objerror(obj, "broken links");
 -      if (fsck_object(obj, NULL, 0, &fsck_obj_options))
 -              return -1;
 -
 -      if (obj->type == OBJ_TREE) {
 -              struct tree *item = (struct tree *) obj;
 -
 -              free_tree_buffer(item);
 -      }
 +      err = fsck_object(obj, NULL, 0, &fsck_obj_options);
 +      if (err)
 +              goto out;
  
        if (obj->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *) obj;
  
 -              free_commit_buffer(commit);
 -
                if (!commit->parents && show_root)
                        printf("root %s\n", describe_object(&commit->object));
        }
                }
        }
  
 -      return 0;
 +out:
 +      if (obj->type == OBJ_TREE)
 +              free_tree_buffer((struct tree *)obj);
 +      if (obj->type == OBJ_COMMIT)
 +              free_commit_buffer((struct commit *)obj);
 +      return err;
  }
  
  static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
                errors_found |= ERROR_OBJECT;
                return error("%s: object corrupt or missing", oid_to_hex(oid));
        }
 -      obj->flags = HAS_OBJ;
 +      obj->flags &= ~(REACHABLE | SEEN);
 +      obj->flags |= HAS_OBJ;
        return fsck_obj(obj);
  }
  
@@@ -400,7 -408,7 +400,7 @@@ static void fsck_handle_reflog_oid(cons
                                add_decoration(fsck_walk_options.object_names,
                                        obj,
                                        xstrfmt("%s@{%"PRItime"}", refname, timestamp));
 -                      obj->used = 1;
 +                      obj->flags |= USED;
                        mark_object_reachable(obj);
                } else {
                        error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
@@@ -448,7 -456,7 +448,7 @@@ static int fsck_handle_ref(const char *
                errors_found |= ERROR_REFS;
        }
        default_refs++;
 -      obj->used = 1;
 +      obj->flags |= USED;
        if (name_objects)
                add_decoration(fsck_walk_options.object_names,
                        obj, xstrdup(refname));
@@@ -516,8 -524,7 +516,8 @@@ static int fsck_loose(const struct obje
                return 0; /* keep checking other objects */
        }
  
 -      obj->flags = HAS_OBJ;
 +      obj->flags &= ~(REACHABLE | SEEN);
 +      obj->flags |= HAS_OBJ;
        if (fsck_obj(obj))
                errors_found |= ERROR_OBJECT;
        return 0;
@@@ -599,7 -606,7 +599,7 @@@ static int fsck_cache_tree(struct cache
                        errors_found |= ERROR_REFS;
                        return 1;
                }
 -              obj->used = 1;
 +              obj->flags |= USED;
                if (name_objects)
                        add_decoration(fsck_walk_options.object_names,
                                obj, xstrdup(":"));
@@@ -660,7 -667,7 +660,7 @@@ static struct option fsck_opts[] = 
  
  int cmd_fsck(int argc, const char **argv, const char *prefix)
  {
 -      int i, heads;
 +      int i;
        struct alternate_object_database *alt;
  
        errors_found = 0;
                }
        }
  
 -      heads = 0;
        for (i = 0; i < argc; i++) {
                const char *arg = argv[i];
 -              unsigned char sha1[20];
 -              if (!get_sha1(arg, sha1)) {
 -                      struct object *obj = lookup_object(sha1);
 +              struct object_id oid;
 +              if (!get_oid(arg, &oid)) {
 +                      struct object *obj = lookup_object(oid.hash);
  
                        if (!obj || !(obj->flags & HAS_OBJ)) {
 -                              error("%s: object missing", sha1_to_hex(sha1));
 +                              error("%s: object missing", oid_to_hex(&oid));
                                errors_found |= ERROR_OBJECT;
                                continue;
                        }
  
 -                      obj->used = 1;
 +                      obj->flags |= USED;
                        if (name_objects)
                                add_decoration(fsck_walk_options.object_names,
                                        obj, xstrdup(arg));
                        mark_object_reachable(obj);
 -                      heads++;
                        continue;
                }
                error("invalid parameter: expected sha1, got '%s'", arg);
                        if (!blob)
                                continue;
                        obj = &blob->object;
 -                      obj->used = 1;
 +                      obj->flags |= USED;
                        if (name_objects)
                                add_decoration(fsck_walk_options.object_names,
                                        obj,
diff --combined builtin/log.c
index 25c0808409abce661d89896ceef490f15bb0b57e,c6362cf92ed799696128a5da6c802813db62fbcf..f8cccbc96403a791ff9d4641bac1c30b621c0d5e
@@@ -27,7 -27,6 +27,7 @@@
  #include "version.h"
  #include "mailmap.h"
  #include "gpg-interface.h"
 +#include "progress.h"
  
  /* Set a default date-time format for git log ("log.date" config variable) */
  static const char *default_date_mode = NULL;
@@@ -59,9 -58,9 +59,9 @@@ static int auto_decoration_style(void
        return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
  }
  
 -static int parse_decoration_style(const char *var, const char *value)
 +static int parse_decoration_style(const char *value)
  {
 -      switch (git_config_maybe_bool(var, value)) {
 +      switch (git_parse_maybe_bool(value)) {
        case 1:
                return DECORATE_SHORT_REFS;
        case 0:
@@@ -83,7 -82,7 +83,7 @@@ static int decorate_callback(const stru
        if (unset)
                decoration_style = 0;
        else if (arg)
 -              decoration_style = parse_decoration_style("command line", arg);
 +              decoration_style = parse_decoration_style(arg);
        else
                decoration_style = DECORATE_SHORT_REFS;
  
@@@ -373,14 -372,11 +373,14 @@@ static int cmd_log_walk(struct rev_inf
                         */
                        rev->max_count++;
                if (!rev->reflog_info) {
 -                      /* we allow cycles in reflog ancestry */
 +                      /*
 +                       * We may show a given commit multiple times when
 +                       * walking the reflogs.
 +                       */
                        free_commit_buffer(commit);
 +                      free_commit_list(commit->parents);
 +                      commit->parents = NULL;
                }
 -              free_commit_list(commit->parents);
 -              commit->parents = NULL;
                if (saved_nrl < rev->diffopt.needed_rename_limit)
                        saved_nrl = rev->diffopt.needed_rename_limit;
                if (rev->diffopt.degraded_cc_to_c)
@@@ -413,7 -409,7 +413,7 @@@ static int git_log_config(const char *v
        if (!strcmp(var, "log.date"))
                return git_config_string(&default_date_mode, var, value);
        if (!strcmp(var, "log.decorate")) {
 -              decoration_style = parse_decoration_style(var, value);
 +              decoration_style = parse_decoration_style(value);
                if (decoration_style < 0)
                        decoration_style = 0; /* maybe warn? */
                return 0;
@@@ -488,8 -484,8 +488,8 @@@ static int show_blob_object(const struc
            !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
                return stream_blob_to_fd(1, oid, NULL, 0);
  
 -      if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
 -                                oidc.hash, &obj_context))
 +      if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
 +                               &oidc, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path ||
            !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
@@@ -825,7 -821,7 +825,7 @@@ static int git_format_config(const cha
                return 0;
        }
        if (!strcmp(var, "format.from")) {
 -              int b = git_config_maybe_bool(var, value);
 +              int b = git_parse_maybe_bool(value);
                free(from);
                if (b < 0)
                        from = xstrdup(value);
@@@ -1423,8 -1419,6 +1423,8 @@@ int cmd_format_patch(int argc, const ch
        char *branch_name = NULL;
        char *base_commit = NULL;
        struct base_tree_info bases;
 +      int show_progress = 0;
 +      struct progress *progress = NULL;
  
        const struct option builtin_format_patch_options[] = {
                { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
                OPT_FILENAME(0, "signature-file", &signature_file,
                                N_("add a signature from a file")),
                OPT__QUIET(&quiet, N_("don't print the patch filenames")),
 +              OPT_BOOL(0, "progress", &show_progress,
 +                       N_("show progress while generating patches")),
                OPT_END()
        };
  
                start_number--;
        }
        rev.add_signoff = do_signoff;
-               progress = start_progress_delay(_("Generating patches"), total, 0, 2);
 +
 +      if (show_progress)
++              progress = start_delayed_progress(_("Generating patches"), total);
        while (0 <= --nr) {
                int shown;
 +              display_progress(progress, total - nr);
                commit = list[nr];
                rev.nr = total - nr + (start_number - 1);
                /* Make the second and subsequent mails replies to the first */
                if (!use_stdout)
                        fclose(rev.diffopt.file);
        }
 +      stop_progress(&progress);
        free(list);
        free(branch_name);
        string_list_clear(&extra_to, 0);
diff --combined builtin/rev-list.c
index 95b4128250c850eb130fbdfea2407bad819a85b8,dfad8e847a75ec85d59f8e8e1a3fe0bbe97ce751..c1c74d4a7956430fca46fd743946280daf2f0f3f
@@@ -11,7 -11,6 +11,7 @@@
  #include "graph.h"
  #include "bisect.h"
  #include "progress.h"
 +#include "reflog-walk.h"
  
  static const char rev_list_usage[] =
  "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@@ -123,7 -122,6 +123,7 @@@ static void show_commit(struct commit *
                ctx.date_mode_explicit = revs->date_mode_explicit;
                ctx.fmt = revs->commit_format;
                ctx.output_encoding = get_log_output_encoding();
 +              ctx.color = revs->diffopt.use_color;
                pretty_print_commit(&ctx, commit, &buf);
                if (buf.len) {
                        if (revs->commit_format != CMIT_FMT_ONELINE)
@@@ -350,10 -348,9 +350,10 @@@ int cmd_rev_list(int argc, const char *
                /* Only --header was specified */
                revs.commit_format = CMIT_FMT_RAW;
  
 -      if ((!revs.commits &&
 +      if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
             (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
 -            !revs.pending.nr)) ||
 +            !revs.pending.nr) &&
 +           !revs.rev_input_given) ||
            revs.diff)
                usage(rev_list_usage);
  
                revs.limited = 1;
  
        if (show_progress)
-               progress = start_progress_delay(show_progress, 0, 0, 2);
+               progress = start_delayed_progress(show_progress, 0);
  
        if (use_bitmap_index && !revs.prune) {
                if (revs.count && !revs.left_right && !revs.cherry_mark) {
diff --combined unpack-trees.c
index 5d5590eee591c6c4a8d92b1e22bbef57a5f41833,e5ae7fe183204b5306d67147a5a1cd5c454ba627..78590f1bfa7c895d3a269c6efe9114ddbb1b23eb
@@@ -286,7 -286,7 +286,7 @@@ static void reload_gitmodules_file(stru
        for (i = 0; i < index->cache_nr; i++) {
                struct cache_entry *ce = index->cache[i];
                if (ce->ce_flags & CE_UPDATE) {
 -                      int r = strcmp(ce->name, ".gitmodules");
 +                      int r = strcmp(ce->name, GITMODULES_FILE);
                        if (r < 0)
                                continue;
                        else if (r == 0) {
@@@ -343,8 -343,7 +343,7 @@@ static struct progress *get_progress(st
                        total++;
        }
  
-       return start_progress_delay(_("Checking out files"),
-                                   total, 50, 1);
+       return start_delayed_progress(_("Checking out files"), total);
  }
  
  static int check_updates(struct unpack_trees_options *o)
        if (should_update_submodules() && o->update && !o->dry_run)
                reload_gitmodules_file(index, &state);
  
 +      enable_delayed_checkout(&state);
        for (i = 0; i < index->cache_nr; i++) {
                struct cache_entry *ce = index->cache[i];
  
                        }
                }
        }
 +      errs |= finish_delayed_checkout(&state);
        stop_progress(&progress);
        if (o->update)
                git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
@@@ -662,10 -659,10 +661,10 @@@ static int traverse_trees_recursive(in
                else if (i > 1 && are_same_oid(&names[i], &names[i - 2]))
                        t[i] = t[i - 2];
                else {
 -                      const unsigned char *sha1 = NULL;
 +                      const struct object_id *oid = NULL;
                        if (dirmask & 1)
 -                              sha1 = names[i].oid->hash;
 -                      buf[nr_buf++] = fill_tree_descriptor(t+i, sha1);
 +                              oid = names[i].oid;
 +                      buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
                }
        }