From f9c8d8cbbea9cc55d26058a1de767731600ded44 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:40 +0000 Subject: doc: log, gitk: move '-L' description to 'line-range-options.txt' The description of the '-L' option for `git log` and `gitk` is almost the same, but is repeated in both 'git-log.txt' and 'gitk.txt' (the difference being that 'git-log.txt' lists the option with a space after '-L', while 'gitk.txt' lists it as stuck and notes that `gitk` only understands the stuck form). Reduce duplication by creating a new file, 'line-range-options.txt', and include it in both files. To simplify the presentation, only list the stuck form for both commands, and remove the note about `gitk` only understanding the stuck form. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 2b8ac5f..dd189a3 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -77,20 +77,7 @@ produced by `--stat`, etc. Intended to speed up tools that read log messages from `git log` output by allowing them to allocate space in advance. --L ,::: --L :::: - Trace the evolution of the line range given by "," - (or the function name regex ) within the . You may - not give any pathspec limiters. This is currently limited to - a walk starting from a single revision, i.e., you may only - give zero or one positive revision arguments, and - and (or ) must exist in the starting revision. - You can specify this option more than once. Implies `--patch`. - Patch output can be suppressed using `--no-patch`, but other diff formats - (namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`, - `--name-only`, `--name-status`, `--check`) are not currently implemented. -+ -include::line-range-format.txt[] +include::line-range-options.txt[] :: Show only commits in the specified revision range. When no diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index c653ebb..d50e9ed 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -98,25 +98,7 @@ linkgit:git-rev-list[1] for a complete list. (See "History simplification" in linkgit:git-log[1] for a more detailed explanation.) --L,::: --L:::: - - Trace the evolution of the line range given by "," - (or the function name regex ) within the . You may - not give any pathspec limiters. This is currently limited to - a walk starting from a single revision, i.e., you may only - give zero or one positive revision arguments, and - and (or ) must exist in the starting revision. - You can specify this option more than once. Implies `--patch`. - Patch output can be suppressed using `--no-patch`, but other diff formats - (namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`, - `--name-only`, `--name-status`, `--check`) are not currently implemented. -+ -*Note:* gitk (unlike linkgit:git-log[1]) currently only understands -this option if you specify it "glued together" with its argument. Do -*not* put a space after `-L`. -+ -include::line-range-format.txt[] +include::line-range-options.txt[] :: diff --git a/Documentation/line-range-options.txt b/Documentation/line-range-options.txt new file mode 100644 index 0000000..266263f --- /dev/null +++ b/Documentation/line-range-options.txt @@ -0,0 +1,15 @@ +-L,::: +-L:::: + + Trace the evolution of the line range given by "," + (or the function name regex ) within the . You may + not give any pathspec limiters. This is currently limited to + a walk starting from a single revision, i.e., you may only + give zero or one positive revision arguments, and + and (or ) must exist in the starting revision. + You can specify this option more than once. Implies `--patch`. + Patch output can be suppressed using `--no-patch`, but other diff formats + (namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`, + `--name-only`, `--name-status`, `--check`) are not currently implemented. ++ +include::line-range-format.txt[] -- cgit v0.10.2-6-g49f6 From fd5c74e7818a478fac66d821c38c4c2275c77da6 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:41 +0000 Subject: doc: line-range: improve formatting Improve the formatting of the description of the line-range option '-L' for `git log`, `gitk` and `git blame`: - Use bold for , and - Use backticks for literals Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index 88750af..48bf0ee 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -14,8 +14,8 @@ Annotate only the given line range. May be specified multiple times. Overlapping ranges are allowed. + - and are optional. ``-L '' or ``-L ,'' spans from - to end of file. ``-L ,'' spans from start of file to . +'' and '' are optional. `-L ` or `-L ,` spans from +'' to end of file. `-L ,` spans from start of file to ''. + include::line-range-format.txt[] diff --git a/Documentation/line-range-format.txt b/Documentation/line-range-format.txt index 829676f..43759ee 100644 --- a/Documentation/line-range-format.txt +++ b/Documentation/line-range-format.txt @@ -1,30 +1,30 @@ - and can take one of these forms: +'' and '' can take one of these forms: - number + -If or is a number, it specifies an +If '' or '' is a number, it specifies an absolute line number (lines count from 1). + -- /regex/ +- `/regex/` + This form will use the first line matching the given -POSIX regex. If is a regex, it will search from the end of +POSIX regex. If '' is a regex, it will search from the end of the previous `-L` range, if any, otherwise from the start of file. -If is ``^/regex/'', it will search from the start of file. -If is a regex, it will search -starting at the line given by . +If '' is `^/regex/`, it will search from the start of file. +If '' is a regex, it will search +starting at the line given by ''. + - +offset or -offset + -This is only valid for and will specify a number -of lines before or after the line given by . +This is only valid for '' and will specify a number +of lines before or after the line given by ''. + -If ``:'' is given in place of and , it is a +If `:` is given in place of '' and '', it is a regular expression that denotes the range from the first funcname line -that matches , up to the next funcname line. ``:'' +that matches '', up to the next funcname line. `:` searches from the end of the previous `-L` range, if any, otherwise -from the start of file. ``^:'' searches from the start of +from the start of file. `^:` searches from the start of file. diff --git a/Documentation/line-range-options.txt b/Documentation/line-range-options.txt index 266263f..1c90127 100644 --- a/Documentation/line-range-options.txt +++ b/Documentation/line-range-options.txt @@ -1,12 +1,12 @@ -L,::: -L:::: - Trace the evolution of the line range given by "," - (or the function name regex ) within the . You may + Trace the evolution of the line range given by ',' + (or the function name regex '') within the ''. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments, and - and (or ) must exist in the starting revision. + '' and '' (or '') must exist in the starting revision. You can specify this option more than once. Implies `--patch`. Patch output can be suppressed using `--no-patch`, but other diff formats (namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`, -- cgit v0.10.2-6-g49f6 From a4514a46d9c85278ae4a350442dd4a160ff1f3cf Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:42 +0000 Subject: blame-options.txt: also mention 'funcname' in '-L' description Make it clearer that a function can be blamed by feeding `git blame` '-L :' by mentioning it at the beginnning of the description of the '-L' option. Also, in 'line-range-options.txt', which is used for git-log(1) and gitk(1), do not parenthesize the mention of the ':' mode, to place it on equal footing with the ',' mode. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index 48bf0ee..dc3bceb 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -11,8 +11,9 @@ -L ,:: -L ::: - Annotate only the given line range. May be specified multiple times. - Overlapping ranges are allowed. + Annotate only the line range given by ',', + or by the function name regex ''. + May be specified multiple times. Overlapping ranges are allowed. + '' and '' are optional. `-L ` or `-L ,` spans from '' to end of file. `-L ,` spans from start of file to ''. diff --git a/Documentation/line-range-options.txt b/Documentation/line-range-options.txt index 1c90127..8e295a6 100644 --- a/Documentation/line-range-options.txt +++ b/Documentation/line-range-options.txt @@ -1,8 +1,8 @@ -L,::: -L:::: - Trace the evolution of the line range given by ',' - (or the function name regex '') within the ''. You may + Trace the evolution of the line range given by ',', + or by the function name regex '', within the ''. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments, and -- cgit v0.10.2-6-g49f6 From 0cce88f1e4b0ccbdc804db8b522aeb11b0f2b199 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:43 +0000 Subject: doc: add more pointers to gitattributes(5) for userdiff Several Git commands can make use of the builtin userdiff patterns, but it's not obvious in the documentation. Add pointers to the 'Defining a custom hunk header' part of gitattributes(5) in the description of the following options: - the '--function-context' option of `git diff` and friends - the '--function-context' option of `git grep` - the '-L :' option of `git log`, `gitk` and `git blame` In 'git-grep.txt', take the opportunity to use backticks in the description of '--show-function', and improve the wording of the desription of '--function-context'. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 573fb9b..72b558c 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -695,7 +695,10 @@ endif::git-format-patch[] -W:: --function-context:: - Show whole surrounding functions of changes. + Show whole function as context lines for each change. + The function names are determined in the same way as + `git diff` works out patch hunk headers (see 'Defining a + custom hunk-header' in linkgit:gitattributes[5]). ifndef::git-format-patch[] ifndef::git-log[] diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 6077ff0..4e0ba82 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -241,7 +241,7 @@ providing this option will cause it to die. --show-function:: Show the preceding line that contains the function name of the match, unless the matching line is a function name itself. - The name is determined in the same way as 'git diff' works out + The name is determined in the same way as `git diff` works out patch hunk headers (see 'Defining a custom hunk-header' in linkgit:gitattributes[5]). @@ -266,7 +266,9 @@ providing this option will cause it to die. Show the surrounding text from the previous line containing a function name up to the one before the next function name, effectively showing the whole function in which the match was - found. + found. The function names are determined in the same way as + `git diff` works out patch hunk headers (see 'Defining a + custom hunk-header' in linkgit:gitattributes[5]). --threads :: Number of grep worker threads to use. diff --git a/Documentation/line-range-format.txt b/Documentation/line-range-format.txt index 43759ee..9b51e9f 100644 --- a/Documentation/line-range-format.txt +++ b/Documentation/line-range-format.txt @@ -27,4 +27,6 @@ regular expression that denotes the range from the first funcname line that matches '', up to the next funcname line. `:` searches from the end of the previous `-L` range, if any, otherwise from the start of file. `^:` searches from the start of -file. +file. The function names are determined in the same way as `git diff` +works out patch hunk headers (see 'Defining a custom hunk-header' +in linkgit:gitattributes[5]). -- cgit v0.10.2-6-g49f6 From 180d641d7d71ba45a140e9c83777d30be59c4274 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:44 +0000 Subject: line-log: mention both modes in 'blame' and 'log' short help 'git blame -h' and 'git log -h' both show '-L ' and describe this option as "Process only line range n,m, counting from 1". No hint is given that a function name regex can also be used. Use instead, and expand the description of the option to mention both modes. Remove "counting from 1" as it's uneeded; it's uncommon to refer to the first line of a file as "line 0". Also, for 'git log', improve the wording to better reflect the long help. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/builtin/blame.c b/builtin/blame.c index b5036ab..484e194 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -891,7 +891,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) OPT_STRING(0, "contents", &contents_from, N_("file"), N_("Use 's contents as the final image")), OPT_CALLBACK_F('C', NULL, &opt, N_("score"), N_("Find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback), OPT_CALLBACK_F('M', NULL, &opt, N_("score"), N_("Find line movements within and across files"), PARSE_OPT_OPTARG, blame_move_callback), - OPT_STRING_LIST('L', NULL, &range_list, N_("n,m"), N_("Process only line range n,m, counting from 1")), + OPT_STRING_LIST('L', NULL, &range_list, N_("range"), + N_("Process only line range , or function :")), OPT__ABBREV(&abbrev), OPT_END() }; diff --git a/builtin/log.c b/builtin/log.c index 0a7ed4b..c87ce09 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -183,8 +183,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, N_("pattern"), N_("do not decorate refs that match ")), OPT_CALLBACK_F(0, "decorate", NULL, NULL, N_("decorate options"), PARSE_OPT_OPTARG, decorate_callback), - OPT_CALLBACK('L', NULL, &line_cb, "n,m:file", - N_("Process line range n,m in file, counting from 1"), + OPT_CALLBACK('L', NULL, &line_cb, "range:file", + N_("Trace the evolution of line range , or function : in "), log_line_range_callback), OPT_END() }; -- cgit v0.10.2-6-g49f6 From 9466e3809d2b5f9605918c56d63f21b17e98e230 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:45 +0000 Subject: blame: enable funcname blaming with userdiff driver In blame.c::cmd_blame, we send the 'path' field of the 'sb' 'struct blame_scoreboard' as the 'path' argument to 'line-range.c::parse_range_arg', but 'sb.path' is not set yet; it's set to the local variable 'path' a few lines later at line 1137. This 'path' argument is only used in 'parse_range_arg' if we are blaming a funcname, i.e. `git blame -L : `, and in that case it is sent to 'parse_range_funcname', where it is used to determine if a userdiff driver should be used for said to match the given funcname. Since 'path' is yet unset, the userdiff driver is never used, so we fall back to the default funcname regex, which is usually not appropriate for paths that are set to use a specific userdiff driver, and thus either we match some unrelated lines, or we die with fatal: -L parameter '' starting at line 1: no match This has been the case ever since `git blame` learned to blame a funcname in 13b8f68c1f (log -L: :pattern:file syntax to find by funcname, 2013-03-28). Enable funcname blaming for paths using specific userdiff drivers by initializing 'sb.path' earlier in 'cmd_blame', when some of its other fields are initialized, so that it is set when passed to 'parse_range_arg'. Add a regression test in 'annotate-tests.sh', which is sourced in t8001-annotate.sh and t8002-blame.sh, leveraging an existing file used to test the userdiff patterns in t4018-diff-funcname. Also, use 'sb.path' instead of 'path' when constructing the error message at line 1114, for consistency. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/builtin/blame.c b/builtin/blame.c index 484e194..e74bcf7 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1083,6 +1083,7 @@ parse_done: sb.contents_from = contents_from; sb.reverse = reverse; sb.repo = the_repository; + sb.path = path; build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list); string_list_clear(&ignore_revs_file_list, 0); string_list_clear(&ignore_rev_list, 0); @@ -1112,7 +1113,7 @@ parse_done: if ((!lno && (top || bottom)) || lno < bottom) die(Q_("file %s has only %lu line", "file %s has only %lu lines", - lno), path, lno); + lno), sb.path, lno); if (bottom < 1) bottom = 1; if (top < 1 || lno < top) @@ -1137,7 +1138,6 @@ parse_done: string_list_clear(&range_list, 0); sb.ent = NULL; - sb.path = path; if (blame_move_score) sb.move_score = blame_move_score; diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index d933af5..3aee61d 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -479,6 +479,24 @@ test_expect_success 'blame -L ^:RE (absolute: end-of-file)' ' check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1 ' +test_expect_success 'setup -L :funcname with userdiff driver' ' + echo "fortran-* diff=fortran" >.gitattributes && + fortran_file=fortran-external-function && + orig_file="$TEST_DIRECTORY/t4018/$fortran_file" && + cp $orig_file . && + git add $fortran_file && + GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \ + git commit -m "add fortran file" && + sed -e "s/ChangeMe/IWasChanged/" <"$orig_file" >$fortran_file && + git add $fortran_file && + GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \ + git commit -m "change fortran file" +' + +test_expect_success 'blame -L :funcname with userdiff driver' ' + check_count -f fortran-external-function -L:RIGHT A 7 B 1 +' + test_expect_success 'setup incremental' ' ( GIT_AUTHOR_NAME=I && -- cgit v0.10.2-6-g49f6 From 88894aaeeae92e8cb41143cc2e045f50289dc790 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:46 +0000 Subject: blame: simplify 'setup_scoreboard' interface The previous commit moved the initialization of 'sb.path' in 'builtin/blame.c::cmd_blame' before the call to 'blame.c::setup_scoreboard'. Since 'cmd_blame' is the only caller of 'setup_scoreboard', it is now unnecessary for 'setup_scoreboard' to receive 'path' as a separate argument, as 'sb.path' is already initialized. Remove this argument from setup_scoreboard's interface and use the 'path' field of the 'sb' 'struct blame_scoreboard' instead. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/blame.c b/blame.c index de7b5d4..2d92af5 100644 --- a/blame.c +++ b/blame.c @@ -2764,7 +2764,6 @@ void init_scoreboard(struct blame_scoreboard *sb) } void setup_scoreboard(struct blame_scoreboard *sb, - const char *path, struct blame_origin **orig) { const char *final_commit_name = NULL; @@ -2803,7 +2802,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, setup_work_tree(); sb->final = fake_working_tree_commit(sb->repo, &sb->revs->diffopt, - path, sb->contents_from); + sb->path, sb->contents_from); add_pending_object(sb->revs, &(sb->final->object), ":"); } @@ -2846,12 +2845,12 @@ void setup_scoreboard(struct blame_scoreboard *sb, sb->final_buf_size = o->file.size; } else { - o = get_origin(sb->final, path); + o = get_origin(sb->final, sb->path); if (fill_blob_sha1_and_mode(sb->repo, o)) - die(_("no such path %s in %s"), path, final_commit_name); + die(_("no such path %s in %s"), sb->path, final_commit_name); if (sb->revs->diffopt.flags.allow_textconv && - textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf, + textconv_object(sb->repo, sb->path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf, &sb->final_buf_size)) ; else @@ -2861,7 +2860,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, if (!sb->final_buf) die(_("cannot read blob %s for path %s"), oid_to_hex(&o->blob_oid), - path); + sb->path); } sb->num_read_blob++; prepare_lines(sb); diff --git a/blame.h b/blame.h index b6bbee4..e8c185c 100644 --- a/blame.h +++ b/blame.h @@ -181,7 +181,6 @@ const char *blame_nth_line(struct blame_scoreboard *sb, long lno); void init_scoreboard(struct blame_scoreboard *sb); void setup_scoreboard(struct blame_scoreboard *sb, - const char *path, struct blame_origin **orig); void setup_blame_bloom_data(struct blame_scoreboard *sb, const char *path); diff --git a/builtin/blame.c b/builtin/blame.c index e74bcf7..2a9f77b 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1087,7 +1087,7 @@ parse_done: build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list); string_list_clear(&ignore_revs_file_list, 0); string_list_clear(&ignore_rev_list, 0); - setup_scoreboard(&sb, path, &o); + setup_scoreboard(&sb, &o); /* * Changed-path Bloom filters are disabled when looking -- cgit v0.10.2-6-g49f6 From 3af31e87868d46363359148db5243f46d49029e8 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 1 Nov 2020 17:28:47 +0000 Subject: blame: simplify 'setup_blame_bloom_data' interface The penultimate commit moved the initialization of 'sb.path' in 'builtin/blame.c::cmd_blame' before the call to 'blame.c::setup_blame_bloom_data'. Since 'cmd_blame' is the only caller of 'setup_blame_bloom_data', it is now unnecessary for 'setup_blame_bloom_data' to receive 'path' as a separate argument, as 'sb.path' is already initialized. Remove this argument from setup_blame_bloom_data's interface and use the 'path' field of the 'sb' 'struct blame_scoreboard' instead. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano diff --git a/blame.c b/blame.c index 2d92af5..9156ebe 100644 --- a/blame.c +++ b/blame.c @@ -2887,8 +2887,7 @@ struct blame_entry *blame_entry_prepend(struct blame_entry *head, return new_head; } -void setup_blame_bloom_data(struct blame_scoreboard *sb, - const char *path) +void setup_blame_bloom_data(struct blame_scoreboard *sb) { struct blame_bloom_data *bd; struct bloom_filter_settings *bs; @@ -2908,7 +2907,7 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb, bd->nr = 0; ALLOC_ARRAY(bd->keys, bd->alloc); - add_bloom_key(bd, path); + add_bloom_key(bd, sb->path); sb->bloom_data = bd; } diff --git a/blame.h b/blame.h index e8c185c..38bde53 100644 --- a/blame.h +++ b/blame.h @@ -182,8 +182,7 @@ const char *blame_nth_line(struct blame_scoreboard *sb, long lno); void init_scoreboard(struct blame_scoreboard *sb); void setup_scoreboard(struct blame_scoreboard *sb, struct blame_origin **orig); -void setup_blame_bloom_data(struct blame_scoreboard *sb, - const char *path); +void setup_blame_bloom_data(struct blame_scoreboard *sb); void cleanup_scoreboard(struct blame_scoreboard *sb); struct blame_entry *blame_entry_prepend(struct blame_entry *head, diff --git a/builtin/blame.c b/builtin/blame.c index 2a9f77b..6f7e324 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1094,7 +1094,7 @@ parse_done: * for copies. */ if (!(opt & PICKAXE_BLAME_COPY)) - setup_blame_bloom_data(&sb, path); + setup_blame_bloom_data(&sb); lno = sb.num_lines; -- cgit v0.10.2-6-g49f6