X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-blame.c;h=35471fc2615992451c8c5b51a346fe171029b572;hb=f02153696fc319c3c6dba2c27a5f7aed98eec465;hp=3442d282aab208720ba11cebce30b89c55238ddd;hpb=07c785dbb799ce7fa74686e776cd07d69c3ce01e;p=git.git diff --git a/builtin-blame.c b/builtin-blame.c index 3442d282a..35471fc26 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -20,13 +20,12 @@ #include "mailmap.h" static char blame_usage[] = -"git-blame [-c] [-b] [-l] [--root] [-x] [-t] [-f] [-n] [-s] [-p] [-L n,m] [-S ] [-M] [-C] [-C] [--contents ] [--incremental] [commit] [--] file\n" +"git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-L n,m] [-S ] [-M] [-C] [-C] [--contents ] [--incremental] [commit] [--] file\n" " -c Use the same output mode as git-annotate (Default: off)\n" " -b Show blank SHA-1 for boundary commits (Default: off)\n" " -l Show long commit SHA1 (Default: off)\n" " --root Do not treat root commits as boundaries (Default: off)\n" " -t Show raw timestamp (Default: off)\n" -" -x Do not use .mailmap file\n" " -f, --show-name Show original filename (Default: auto)\n" " -n, --show-number Show original linenumber (Default: off)\n" " -s Suppress author name and timestamp (Default: off)\n" @@ -46,7 +45,6 @@ static int show_root; static int blank_boundary; static int incremental; static int cmd_is_annotate; -static int no_mailmap; static struct path_list mailmap; #ifndef DEBUG @@ -61,6 +59,7 @@ static int num_commits; #define PICKAXE_BLAME_MOVE 01 #define PICKAXE_BLAME_COPY 02 #define PICKAXE_BLAME_COPY_HARDER 04 +#define PICKAXE_BLAME_COPY_HARDEST 010 /* * blame for a blame_entry with score lower than these thresholds @@ -896,6 +895,39 @@ static void copy_split_if_better(struct scoreboard *sb, memcpy(best_so_far, this, sizeof(struct blame_entry [3])); } +/* + * We are looking at a part of the final image represented by + * ent (tlno and same are offset by ent->s_lno). + * tlno is where we are looking at in the final image. + * up to (but not including) same match preimage. + * plno is where we are looking at in the preimage. + * + * <-------------- final image ----------------------> + * <------ent------> + * ^tlno ^same + * <---------preimage-----> + * ^plno + * + * All line numbers are 0-based. + */ +static void handle_split(struct scoreboard *sb, + struct blame_entry *ent, + int tlno, int plno, int same, + struct origin *parent, + struct blame_entry *split) +{ + if (ent->num_lines <= tlno) + return; + if (tlno < same) { + struct blame_entry this[3]; + tlno += ent->s_lno; + same += ent->s_lno; + split_overlap(this, ent, tlno, plno, same, parent); + copy_split_if_better(sb, split, this); + decref_split(this); + } +} + /* * Find the lines from parent that are the same as ent so that * we can pass blames to it. file_p has the blob contents for @@ -928,26 +960,21 @@ static void find_copy_in_blob(struct scoreboard *sb, patch = compare_buffer(file_p, &file_o, 1); + /* + * file_o is a part of final image we are annotating. + * file_p partially may match that image. + */ memset(split, 0, sizeof(struct blame_entry [3])); plno = tlno = 0; for (i = 0; i < patch->num; i++) { struct chunk *chunk = &patch->chunks[i]; - /* tlno to chunk->same are the same as ent */ - if (ent->num_lines <= tlno) - break; - if (tlno < chunk->same) { - struct blame_entry this[3]; - split_overlap(this, ent, - tlno + ent->s_lno, plno, - chunk->same + ent->s_lno, - parent); - copy_split_if_better(sb, split, this); - decref_split(this); - } + handle_split(sb, ent, tlno, plno, chunk->same, parent, split); plno = chunk->p_next; tlno = chunk->t_next; } + /* remainder, if any, all match the preimage */ + handle_split(sb, ent, tlno, plno, ent->num_lines, parent, split); free_patch(patch); } @@ -1057,8 +1084,9 @@ static int find_copy_in_parent(struct scoreboard *sb, * and this code needs to be after diff_setup_done(), which * usually makes find-copies-harder imply copy detection. */ - if ((opt & PICKAXE_BLAME_COPY_HARDER) && - (!porigin || strcmp(target->path, porigin->path))) + if ((opt & PICKAXE_BLAME_COPY_HARDEST) + || ((opt & PICKAXE_BLAME_COPY_HARDER) + && (!porigin || strcmp(target->path, porigin->path)))) diff_opts.find_copies_harder = 1; if (is_null_sha1(target->commit->object.sha1)) @@ -2138,6 +2166,15 @@ int cmd_blame(int argc, const char **argv, const char *prefix) blame_move_score = parse_score(arg+2); } else if (!prefixcmp(arg, "-C")) { + /* + * -C enables copy from removed files; + * -C -C enables copy from existing files, but only + * when blaming a new file; + * -C -C -C enables copy from existing files for + * everybody + */ + if (opt & PICKAXE_BLAME_COPY_HARDER) + opt |= PICKAXE_BLAME_COPY_HARDEST; if (opt & PICKAXE_BLAME_COPY) opt |= PICKAXE_BLAME_COPY_HARDER; opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE; @@ -2173,9 +2210,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix) else if (!strcmp("-p", arg) || !strcmp("--porcelain", arg)) output_option |= OUTPUT_PORCELAIN; - else if (!strcmp("-x", arg) || - !strcmp("--no-mailmap", arg)) - no_mailmap = 1; else if (!strcmp("--", arg)) { seen_dashdash = 1; i++; @@ -2375,8 +2409,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) die("reading graft file %s failed: %s", revs_file, strerror(errno)); - if (!no_mailmap) - read_mailmap(&mailmap, ".mailmap", NULL); + read_mailmap(&mailmap, ".mailmap", NULL); assign_blame(&sb, &revs, opt);