Skip to content

Commit 3d1aa56

Browse files
committed
blame: pay attention to --no-follow
If you know your history did not have renames, or if you care only about the history after a large rename that happened some time ago, "git blame --no-follow $path" is a way to tell the command not to bother about renames. When you use -C, the lines that came from the renamed file will still be found without the whole-file rename detection, so it is not all that interesting either way, though. Signed-off-by: Junio C Hamano <[email protected]>
1 parent aebbcf5 commit 3d1aa56

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

builtin/blame.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int blank_boundary;
4242
static int incremental;
4343
static int xdl_opts;
4444
static int abbrev = -1;
45+
static int no_whole_file_rename;
4546

4647
static enum date_mode blame_date_mode = DATE_ISO8601;
4748
static size_t blame_date_width;
@@ -1226,7 +1227,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
12261227
* The first pass looks for unrenamed path to optimize for
12271228
* common cases, then we look for renames in the second pass.
12281229
*/
1229-
for (pass = 0; pass < 2; pass++) {
1230+
for (pass = 0; pass < 2 - no_whole_file_rename; pass++) {
12301231
struct origin *(*find)(struct scoreboard *,
12311232
struct commit *, struct origin *);
12321233
find = pass ? find_rename : find_origin;
@@ -2344,6 +2345,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
23442345
init_revisions(&revs, NULL);
23452346
revs.date_mode = blame_date_mode;
23462347
DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
2348+
DIFF_OPT_SET(&revs.diffopt, FOLLOW_RENAMES);
23472349

23482350
save_commit_buffer = 0;
23492351
dashdash_pos = 0;
@@ -2367,6 +2369,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
23672369
parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
23682370
}
23692371
parse_done:
2372+
no_whole_file_rename = !DIFF_OPT_TST(&revs.diffopt, FOLLOW_RENAMES);
2373+
DIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);
23702374
argc = parse_options_end(&ctx);
23712375

23722376
if (0 < abbrev)

0 commit comments

Comments
 (0)