Skip to content

Commit 3f6dc9c

Browse files
committed
Merge branch 'pb/blame-funcname-range-userdiff'
"git blame -L :funcname -- path" did not work well for a path for which a userdiff driver is defined. * pb/blame-funcname-range-userdiff: blame: simplify 'setup_blame_bloom_data' interface blame: simplify 'setup_scoreboard' interface blame: enable funcname blaming with userdiff driver line-log: mention both modes in 'blame' and 'log' short help doc: add more pointers to gitattributes(5) for userdiff blame-options.txt: also mention 'funcname' in '-L' description doc: line-range: improve formatting doc: log, gitk: move '-L' description to 'line-range-options.txt'
2 parents a1f9595 + 3af31e8 commit 3f6dc9c

File tree

12 files changed

+79
-72
lines changed

12 files changed

+79
-72
lines changed

Documentation/blame-options.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
-L <start>,<end>::
1313
-L :<funcname>::
14-
Annotate only the given line range. May be specified multiple times.
15-
Overlapping ranges are allowed.
14+
Annotate only the line range given by '<start>,<end>',
15+
or by the function name regex '<funcname>'.
16+
May be specified multiple times. Overlapping ranges are allowed.
1617
+
17-
<start> and <end> are optional. ``-L <start>'' or ``-L <start>,'' spans from
18-
<start> to end of file. ``-L ,<end>'' spans from start of file to <end>.
18+
'<start>' and '<end>' are optional. `-L <start>` or `-L <start>,` spans from
19+
'<start>' to end of file. `-L ,<end>` spans from start of file to '<end>'.
1920
+
2021
include::line-range-format.txt[]
2122

Documentation/diff-options.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,10 @@ endif::git-format-patch[]
704704

705705
-W::
706706
--function-context::
707-
Show whole surrounding functions of changes.
707+
Show whole function as context lines for each change.
708+
The function names are determined in the same way as
709+
`git diff` works out patch hunk headers (see 'Defining a
710+
custom hunk-header' in linkgit:gitattributes[5]).
708711

709712
ifndef::git-format-patch[]
710713
ifndef::git-log[]

Documentation/git-grep.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ providing this option will cause it to die.
241241
--show-function::
242242
Show the preceding line that contains the function name of
243243
the match, unless the matching line is a function name itself.
244-
The name is determined in the same way as 'git diff' works out
244+
The name is determined in the same way as `git diff` works out
245245
patch hunk headers (see 'Defining a custom hunk-header' in
246246
linkgit:gitattributes[5]).
247247

@@ -266,7 +266,9 @@ providing this option will cause it to die.
266266
Show the surrounding text from the previous line containing a
267267
function name up to the one before the next function name,
268268
effectively showing the whole function in which the match was
269-
found.
269+
found. The function names are determined in the same way as
270+
`git diff` works out patch hunk headers (see 'Defining a
271+
custom hunk-header' in linkgit:gitattributes[5]).
270272

271273
--threads <num>::
272274
Number of grep worker threads to use.

Documentation/git-log.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,7 @@ produced by `--stat`, etc.
7777
Intended to speed up tools that read log messages from `git log`
7878
output by allowing them to allocate space in advance.
7979

80-
-L <start>,<end>:<file>::
81-
-L :<funcname>:<file>::
82-
Trace the evolution of the line range given by "<start>,<end>"
83-
(or the function name regex <funcname>) within the <file>. You may
84-
not give any pathspec limiters. This is currently limited to
85-
a walk starting from a single revision, i.e., you may only
86-
give zero or one positive revision arguments, and
87-
<start> and <end> (or <funcname>) must exist in the starting revision.
88-
You can specify this option more than once. Implies `--patch`.
89-
Patch output can be suppressed using `--no-patch`, but other diff formats
90-
(namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`,
91-
`--name-only`, `--name-status`, `--check`) are not currently implemented.
92-
+
93-
include::line-range-format.txt[]
80+
include::line-range-options.txt[]
9481

9582
<revision range>::
9683
Show only commits in the specified revision range. When no

Documentation/gitk.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,7 @@ linkgit:git-rev-list[1] for a complete list.
9898
(See "History simplification" in linkgit:git-log[1] for a more
9999
detailed explanation.)
100100

101-
-L<start>,<end>:<file>::
102-
-L:<funcname>:<file>::
103-
104-
Trace the evolution of the line range given by "<start>,<end>"
105-
(or the function name regex <funcname>) within the <file>. You may
106-
not give any pathspec limiters. This is currently limited to
107-
a walk starting from a single revision, i.e., you may only
108-
give zero or one positive revision arguments, and
109-
<start> and <end> (or <funcname>) must exist in the starting revision.
110-
You can specify this option more than once. Implies `--patch`.
111-
Patch output can be suppressed using `--no-patch`, but other diff formats
112-
(namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`,
113-
`--name-only`, `--name-status`, `--check`) are not currently implemented.
114-
+
115-
*Note:* gitk (unlike linkgit:git-log[1]) currently only understands
116-
this option if you specify it "glued together" with its argument. Do
117-
*not* put a space after `-L`.
118-
+
119-
include::line-range-format.txt[]
101+
include::line-range-options.txt[]
120102

121103
<revision range>::
122104

Documentation/line-range-format.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
<start> and <end> can take one of these forms:
1+
'<start>' and '<end>' can take one of these forms:
22

33
- number
44
+
5-
If <start> or <end> is a number, it specifies an
5+
If '<start>' or '<end>' is a number, it specifies an
66
absolute line number (lines count from 1).
77
+
88

9-
- /regex/
9+
- `/regex/`
1010
+
1111
This form will use the first line matching the given
12-
POSIX regex. If <start> is a regex, it will search from the end of
12+
POSIX regex. If '<start>' is a regex, it will search from the end of
1313
the previous `-L` range, if any, otherwise from the start of file.
14-
If <start> is ``^/regex/'', it will search from the start of file.
15-
If <end> is a regex, it will search
16-
starting at the line given by <start>.
14+
If '<start>' is `^/regex/`, it will search from the start of file.
15+
If '<end>' is a regex, it will search
16+
starting at the line given by '<start>'.
1717
+
1818

1919
- +offset or -offset
2020
+
21-
This is only valid for <end> and will specify a number
22-
of lines before or after the line given by <start>.
21+
This is only valid for '<end>' and will specify a number
22+
of lines before or after the line given by '<start>'.
2323

2424
+
25-
If ``:<funcname>'' is given in place of <start> and <end>, it is a
25+
If `:<funcname>` is given in place of '<start>' and '<end>', it is a
2626
regular expression that denotes the range from the first funcname line
27-
that matches <funcname>, up to the next funcname line. ``:<funcname>''
27+
that matches '<funcname>', up to the next funcname line. `:<funcname>`
2828
searches from the end of the previous `-L` range, if any, otherwise
29-
from the start of file. ``^:<funcname>'' searches from the start of
30-
file.
29+
from the start of file. `^:<funcname>` searches from the start of
30+
file. The function names are determined in the same way as `git diff`
31+
works out patch hunk headers (see 'Defining a custom hunk-header'
32+
in linkgit:gitattributes[5]).

Documentation/line-range-options.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-L<start>,<end>:<file>::
2+
-L:<funcname>:<file>::
3+
4+
Trace the evolution of the line range given by '<start>,<end>',
5+
or by the function name regex '<funcname>', within the '<file>'. You may
6+
not give any pathspec limiters. This is currently limited to
7+
a walk starting from a single revision, i.e., you may only
8+
give zero or one positive revision arguments, and
9+
'<start>' and '<end>' (or '<funcname>') must exist in the starting revision.
10+
You can specify this option more than once. Implies `--patch`.
11+
Patch output can be suppressed using `--no-patch`, but other diff formats
12+
(namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`,
13+
`--name-only`, `--name-status`, `--check`) are not currently implemented.
14+
+
15+
include::line-range-format.txt[]

blame.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,6 @@ void init_scoreboard(struct blame_scoreboard *sb)
27642764
}
27652765

27662766
void setup_scoreboard(struct blame_scoreboard *sb,
2767-
const char *path,
27682767
struct blame_origin **orig)
27692768
{
27702769
const char *final_commit_name = NULL;
@@ -2803,7 +2802,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28032802
setup_work_tree();
28042803
sb->final = fake_working_tree_commit(sb->repo,
28052804
&sb->revs->diffopt,
2806-
path, sb->contents_from);
2805+
sb->path, sb->contents_from);
28072806
add_pending_object(sb->revs, &(sb->final->object), ":");
28082807
}
28092808

@@ -2846,12 +2845,12 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28462845
sb->final_buf_size = o->file.size;
28472846
}
28482847
else {
2849-
o = get_origin(sb->final, path);
2848+
o = get_origin(sb->final, sb->path);
28502849
if (fill_blob_sha1_and_mode(sb->repo, o))
2851-
die(_("no such path %s in %s"), path, final_commit_name);
2850+
die(_("no such path %s in %s"), sb->path, final_commit_name);
28522851

28532852
if (sb->revs->diffopt.flags.allow_textconv &&
2854-
textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
2853+
textconv_object(sb->repo, sb->path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
28552854
&sb->final_buf_size))
28562855
;
28572856
else
@@ -2861,7 +2860,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28612860
if (!sb->final_buf)
28622861
die(_("cannot read blob %s for path %s"),
28632862
oid_to_hex(&o->blob_oid),
2864-
path);
2863+
sb->path);
28652864
}
28662865
sb->num_read_blob++;
28672866
prepare_lines(sb);
@@ -2888,8 +2887,7 @@ struct blame_entry *blame_entry_prepend(struct blame_entry *head,
28882887
return new_head;
28892888
}
28902889

2891-
void setup_blame_bloom_data(struct blame_scoreboard *sb,
2892-
const char *path)
2890+
void setup_blame_bloom_data(struct blame_scoreboard *sb)
28932891
{
28942892
struct blame_bloom_data *bd;
28952893
struct bloom_filter_settings *bs;
@@ -2909,7 +2907,7 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb,
29092907
bd->nr = 0;
29102908
ALLOC_ARRAY(bd->keys, bd->alloc);
29112909

2912-
add_bloom_key(bd, path);
2910+
add_bloom_key(bd, sb->path);
29132911

29142912
sb->bloom_data = bd;
29152913
}

blame.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,8 @@ const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
181181

182182
void init_scoreboard(struct blame_scoreboard *sb);
183183
void setup_scoreboard(struct blame_scoreboard *sb,
184-
const char *path,
185184
struct blame_origin **orig);
186-
void setup_blame_bloom_data(struct blame_scoreboard *sb,
187-
const char *path);
185+
void setup_blame_bloom_data(struct blame_scoreboard *sb);
188186
void cleanup_scoreboard(struct blame_scoreboard *sb);
189187

190188
struct blame_entry *blame_entry_prepend(struct blame_entry *head,

builtin/blame.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
891891
OPT_STRING(0, "contents", &contents_from, N_("file"), N_("Use <file>'s contents as the final image")),
892892
OPT_CALLBACK_F('C', NULL, &opt, N_("score"), N_("Find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback),
893893
OPT_CALLBACK_F('M', NULL, &opt, N_("score"), N_("Find line movements within and across files"), PARSE_OPT_OPTARG, blame_move_callback),
894-
OPT_STRING_LIST('L', NULL, &range_list, N_("n,m"), N_("Process only line range n,m, counting from 1")),
894+
OPT_STRING_LIST('L', NULL, &range_list, N_("range"),
895+
N_("Process only line range <start>,<end> or function :<funcname>")),
895896
OPT__ABBREV(&abbrev),
896897
OPT_END()
897898
};
@@ -1082,17 +1083,18 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10821083
sb.contents_from = contents_from;
10831084
sb.reverse = reverse;
10841085
sb.repo = the_repository;
1086+
sb.path = path;
10851087
build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
10861088
string_list_clear(&ignore_revs_file_list, 0);
10871089
string_list_clear(&ignore_rev_list, 0);
1088-
setup_scoreboard(&sb, path, &o);
1090+
setup_scoreboard(&sb, &o);
10891091

10901092
/*
10911093
* Changed-path Bloom filters are disabled when looking
10921094
* for copies.
10931095
*/
10941096
if (!(opt & PICKAXE_BLAME_COPY))
1095-
setup_blame_bloom_data(&sb, path);
1097+
setup_blame_bloom_data(&sb);
10961098

10971099
lno = sb.num_lines;
10981100

@@ -1111,7 +1113,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
11111113
if ((!lno && (top || bottom)) || lno < bottom)
11121114
die(Q_("file %s has only %lu line",
11131115
"file %s has only %lu lines",
1114-
lno), path, lno);
1116+
lno), sb.path, lno);
11151117
if (bottom < 1)
11161118
bottom = 1;
11171119
if (top < 1 || lno < top)
@@ -1136,7 +1138,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
11361138
string_list_clear(&range_list, 0);
11371139

11381140
sb.ent = NULL;
1139-
sb.path = path;
11401141

11411142
if (blame_move_score)
11421143
sb.move_score = blame_move_score;

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
183183
N_("pattern"), N_("do not decorate refs that match <pattern>")),
184184
OPT_CALLBACK_F(0, "decorate", NULL, NULL, N_("decorate options"),
185185
PARSE_OPT_OPTARG, decorate_callback),
186-
OPT_CALLBACK('L', NULL, &line_cb, "n,m:file",
187-
N_("Process line range n,m in file, counting from 1"),
186+
OPT_CALLBACK('L', NULL, &line_cb, "range:file",
187+
N_("Trace the evolution of line range <start>,<end> or function :<funcname> in <file>"),
188188
log_line_range_callback),
189189
OPT_END()
190190
};

t/annotate-tests.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,24 @@ test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
479479
check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
480480
'
481481

482+
test_expect_success 'setup -L :funcname with userdiff driver' '
483+
echo "fortran-* diff=fortran" >.gitattributes &&
484+
fortran_file=fortran-external-function &&
485+
orig_file="$TEST_DIRECTORY/t4018/$fortran_file" &&
486+
cp $orig_file . &&
487+
git add $fortran_file &&
488+
GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="[email protected]" \
489+
git commit -m "add fortran file" &&
490+
sed -e "s/ChangeMe/IWasChanged/" <"$orig_file" >$fortran_file &&
491+
git add $fortran_file &&
492+
GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="[email protected]" \
493+
git commit -m "change fortran file"
494+
'
495+
496+
test_expect_success 'blame -L :funcname with userdiff driver' '
497+
check_count -f fortran-external-function -L:RIGHT A 7 B 1
498+
'
499+
482500
test_expect_success 'setup incremental' '
483501
(
484502
GIT_AUTHOR_NAME=I &&

0 commit comments

Comments
 (0)