Merge branch 'sb/blame-color'
authorJunio C Hamano <gitster@pobox.com>
Mon, 18 Jun 2018 17:18:45 +0000 (10:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Jun 2018 17:18:45 +0000 (10:18 -0700)
Leakfix.

* sb/blame-color:
blame: release string_list after use in parse_color_fields()

1  2 
builtin/blame.c
diff --combined builtin/blame.c
index 4202584f97922f39f8631e23b01981ed5687b793,dc7870a56172b6aedd15df5a3dd21485442c1077..3295718841aab1051ee8bdde0b1fc0aa26ae5f00
@@@ -411,6 -411,7 +411,7 @@@ static void parse_color_fields(const ch
                die (_("must end with a color"));
  
        colorfield[colorfield_nr].hop = TIME_MAX;
+       string_list_clear(&l, 0);
  }
  
  static void setup_default_color_by_age(void)
@@@ -584,7 -585,7 +585,7 @@@ static int read_ancestry(const char *gr
  
  static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect)
  {
 -      const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
 +      const char *uniq = find_unique_abbrev(&suspect->commit->object.oid,
                                              auto_abbrev);
        int len = strlen(uniq);
        if (auto_abbrev < len)
@@@ -758,15 -759,6 +759,15 @@@ static int blame_move_callback(const st
        return 0;
  }
  
 +static int is_a_rev(const char *name)
 +{
 +      struct object_id oid;
 +
 +      if (get_oid(name, &oid))
 +              return 0;
 +      return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
 +}
 +
  int cmd_blame(int argc, const char **argv, const char *prefix)
  {
        struct rev_info revs;
        for (;;) {
                switch (parse_options_step(&ctx, options, blame_opt_usage)) {
                case PARSE_OPT_HELP:
 +              case PARSE_OPT_ERROR:
                        exit(129);
                case PARSE_OPT_DONE:
                        if (ctx.argv[0])
@@@ -967,15 -958,16 +968,15 @@@ parse_done
        } else {
                if (argc < 2)
                        usage_with_options(blame_opt_usage, options);
 -              path = add_prefix(prefix, argv[argc - 1]);
 -              if (argc == 3 && !file_exists(path)) { /* (2b) */
 +              if (argc == 3 && is_a_rev(argv[argc - 1])) { /* (2b) */
                        path = add_prefix(prefix, argv[1]);
                        argv[1] = argv[2];
 +              } else {        /* (2a) */
 +                      if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree())
 +                              die("missing <path> to blame");
 +                      path = add_prefix(prefix, argv[argc - 1]);
                }
                argv[argc - 1] = "--";
 -
 -              setup_work_tree();
 -              if (!file_exists(path))
 -                      die_errno("cannot stat path '%s'", path);
        }
  
        revs.disable_stdin = 1;