From: Junio C Hamano Date: Fri, 20 Jul 2018 21:42:53 +0000 (-0700) Subject: Merge branch 'sb/blame-color' into jk/banned-function X-Git-Tag: v2.19.0-rc0~68^2~4 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b20a3cbb887be494a93d54858052f0a4f8df17c1?ds=inline;hp=-c Merge branch 'sb/blame-color' into jk/banned-function * sb/blame-color: blame: prefer xsnprintf to strcpy for colors --- b20a3cbb887be494a93d54858052f0a4f8df17c1 diff --combined builtin/blame.c index 921d127f29,758cd39dd1..468b17c30c --- a/builtin/blame.c +++ b/builtin/blame.c @@@ -9,7 -9,6 +9,7 @@@ #include "config.h" #include "color.h" #include "builtin.h" +#include "repository.h" #include "commit.h" #include "diff.h" #include "revision.h" @@@ -24,7 -23,6 +24,7 @@@ #include "line-log.h" #include "dir.h" #include "progress.h" +#include "object-store.h" #include "blame.h" #include "string-list.h" @@@ -545,7 -543,7 +545,7 @@@ static void output(struct blame_scorebo struct commit *commit = ent->suspect->commit; if (commit->object.flags & MORE_THAN_ONE_PATH) continue; - for (suspect = commit->util; suspect; suspect = suspect->next) { + for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) { if (suspect->guilty && count++) { commit->object.flags |= MORE_THAN_ONE_PATH; break; @@@ -578,7 -576,7 +578,7 @@@ static int read_ancestry(const char *gr /* The format is just "Commit Parent1 Parent2 ...\n" */ struct commit_graft *graft = read_graft_line(&buf); if (graft) - register_commit_graft(graft, 0); + register_commit_graft(the_repository, graft, 0); } fclose(fp); strbuf_release(&buf); @@@ -587,7 -585,7 +587,7 @@@ 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) @@@ -761,15 -759,6 +761,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; @@@ -844,7 -833,6 +844,7 @@@ 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]) @@@ -970,15 -958,16 +970,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 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; @@@ -1071,7 -1060,9 +1071,9 @@@ find_alignment(&sb, &output_option); if (!*repeated_meta_color && (output_option & OUTPUT_COLOR_LINE)) - strcpy(repeated_meta_color, GIT_COLOR_CYAN); + xsnprintf(repeated_meta_color, + sizeof(repeated_meta_color), + "%s", GIT_COLOR_CYAN); } if (output_option & OUTPUT_ANNOTATE_COMPAT) output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);