git log -L
Subsystems (2)
v9 cover git log -L
Compared to the previous round at
http://thread.gmane.org/gmane.comp.version-control.git/217236
I made the following changes (numbers from v8):
[1/5] Refactor parse_loc
Based on Junio's suggestions, the refactoring is now to a new file line-range.c that line-log.c will later use. (It still irks me too much to call straight into builtin/blame.c.)
I also re-copied the existing functions, to make sure that they are the same. Junio correctly spotted some differences, and since we claim to only refactor those are bad.
[2/5] Export rewrite_parents() for 'log -L'
Unchanged.
[2.5/5] blame: introduce $ as "end of file" in -L syntax
Dropped. As Junio remarked, omitting the end is already a valid way of saying the same.
[3/5] Implement line-history search (git log -L)
Integrated Ramsay's fixes and Junio's remarks. Also made some minor cleanups. Added a perf test.
[4/5] log -L: :pattern:file syntax to find by funcname
Adjusted for changes in the earlier patches; otherwise the same.
[5/5] Speed up log -L... -M
Added to this series, I posted the same patch earlier in the side thread about the bad performance. The perf test from 4/5 neatly shows the difference.
Bo Yang (2):
Refactor parse_loc
Export rewrite_parents() for 'log -L'
Thomas Rast (3):
Implement line-history search (git log -L) log -L: :pattern:file syntax to find by funcname Speed up log -L... -M
Documentation/blame-options.txt | 21 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 23 + Documentation/line-range-format.txt | 25 + Makefile | 4 + builtin/blame.c | 99 +-- builtin/log.c | 31 + line-log.c | 1228 +++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 237 +++++++ line-range.h | 36 + log-tree.c | 4 + revision.c | 22 +- revision.h | 16 +- t/perf/p4211-line-log.sh | 34 + t/t4211-line-log.sh | 40 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-main | 68 ++ t/t4211/expect.two-ranges | 102 +++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 ++++++++++ t/t8003-blame-corner-cases.sh | 6 + 25 files changed, 2501 insertions(+), 123 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-log.c create mode 100644 line-log.h create mode 100644 line-range.c create mode 100644 line-range.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Signature · 1 line
1.8.2.241.gee8bb87
PATCH v9 1/5 Refactor parse_loc
From: Bo Yang <[email protected]>
We want to use the same style of -L n,m argument for 'git log -L' as for git-blame. Refactor the argument parsing of the range arguments from builtin/blame.c to the (new) file that will hold the 'git log -L' logic.
To accommodate different data structures in blame and log -L, the file contents are abstracted away; parse_range_arg takes a callback that it uses to get the contents of a line of the (notional) file.
The new test is for a case that made me pause during debugging: the 'blame -L with invalid end' test was the only one that noticed an outright failure to parse the end *at all*. So make a more explicit test for that.
--- Documentation/blame-options.txt | 19 +------ Documentation/line-range-format.txt | 18 +++++++ Makefile | 2 + builtin/blame.c | 99 +++---------------------------------- line-range.c | 92 ++++++++++++++++++++++++++++++++++ line-range.h | 24 +++++++++ t/t8003-blame-corner-cases.sh | 6 +++ 7 files changed, 151 insertions(+), 109 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-range.c create mode 100644 line-range.h
Documentation/blame-options.txt +1 -18
@@ -13,24 +13,7 @@ Annotate only the given line range. <start> and <end> can take one of these forms: - - number -+ -If <start> or <end> is a number, it specifies an -absolute line number (lines count from 1). -+ - -- /regex/ -+ -This form will use the first line matching the given -POSIX regex. If <end> is a regex, it will search -starting at the line given by <start>. -+ - -- +offset or -offset -+ -This is only valid for <end> and will specify a number -of lines before or after the line given by <start>. -+ +include::line-range-format.txt[] -l:: Show long rev (Default: off).
Documentation/line-range-format.txt new file +18 -0
@@ -0,0 +1,18 @@ +- number ++ +If <start> or <end> is a number, it specifies an +absolute line number (lines count from 1). ++ + +- /regex/ ++ +This form will use the first line matching the given +POSIX regex. If <end> is a regex, it will search +starting at the line given by <start>. ++ + +- +offset or -offset ++ +This is only valid for <end> and will specify a number +of lines before or after the line given by <start>. ++
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h LIB_H += log-tree.h
@@ -795,6 +796,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o
builtin/blame.c +8 -91
133 lines not on this page · raw message
line-range.c new file +92 -0
92 lines not on this page · raw message
line-range.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef LINE_RANGE_H +#define LINE_RANGE_H + +/* +* Parse one item in an -L begin,end option w.r.t. the notional file +* object 'cb_data' consisting of 'lines' lines. +* +* The 'nth_line_cb' callback is used to determine the start of the +* line 'lno' inside the 'cb_data'. The caller is expected to already +* have a suitable map at hand to make this a constant-time lookup. +* +* Returns 0 in case of success and -1 if there was an error. The +* actual range is stored in *begin and *end. The counting starts +* at 1! In case of error, the caller should show usage message. +*/ + +typedef const char *(*nth_line_fn_t )(void *data,long lno); + +extern int parse_range_arg (const char *arg, +nth_line_fn_t nth_line_cb, +void *cb_data,long lines, +long *begin,long *end); + +#endif /* LINE_RANGE_H */
t/t8003-blame-corner-cases.sh +6 -0
@@ -175,6 +175,12 @@ test_expect_success 'blame -L with invalid end' ' grep "has only 2 lines" errors ' +test_expect_success 'blame parses <end> part of -L' ' + git blame -L1,1 tres >out && + cat out && + test $(wc -l < out) -eq 1 +' + test_expect_success 'indent of line numbers, nine lines' ' git blame nine_lines >actual && test $(grep -c " " actual) = 0
Signature · 1 line
1.8.2.241.gee8bb87
PATCH v9 2/5 Export rewrite_parents() for 'log -L'
In reply to Thomas RastFrom: Bo Yang <[email protected]>
The function rewrite_one is used to rewrite a single parent of the current commit, and is used by rewrite_parents to rewrite all the parents.
Decouple the dependence between them by making rewrite_one a callback function that is passed to rewrite_parents. Then export rewrite_parents for reuse by the line history browser.
We will use this function in line-log.c.
--- revision.c | 13 ++++--------- revision.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-)
revision.c +4 -9
@@ -2173,12 +2173,6 @@ int prepare_revision_walk(struct rev_info *revs)return 0 ; } -enum rewrite_result { - rewrite_one_ok, - rewrite_one_noparents, - rewrite_one_error -}; -static enum rewrite_result rewrite_one (struct rev_info *revs,struct commit **pp) {struct commit_list *cache =NULL ;
@@ -2200,12 +2194,13 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp } } -static int rewrite_parents (struct rev_info *revs,struct commit *commit) +int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent) {struct commit_list **pp = &commit->parents;while (*pp) {struct commit_list *parent = *pp; -switch (rewrite_one (revs, &parent->item)) { +switch (rewrite_parent (revs, &parent->item)) {case rewrite_one_ok:break ;case rewrite_one_noparents:
@@ -2371,7 +2366,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)if (action == commit_show && !revs->show_all && revs->prune && revs->dense &&want_ancestry (revs)) { -if (rewrite_parents (revs, commit) <0 ) +if (rewrite_parents (revs, commit, rewrite_one) <0 )return commit_error; }return action;
revision.h +10 -0
@@ -241,4 +241,14 @@ enum commit_action {extern enum commit_action get_commit_action (struct rev_info *revs,struct commit *commit);extern enum commit_action simplify_commit (struct rev_info *revs,struct commit *commit); +enum rewrite_result { + rewrite_one_ok, + rewrite_one_noparents, + rewrite_one_error +}; + +typedef enum rewrite_result (*rewrite_parent_fn_t )(struct rev_info *revs,struct commit **pp); + +extern int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent);#endif
Signature · 1 line
1.8.2.241.gee8bb87
PATCH v9 3/5 Implement line-history search (git log -L)
In reply to Thomas RastThis is a rewrite of much of Bo's work, mainly in an effort to split it into smaller, easier to understand routines.
The algorithm is built around the struct range_set, which encodes a series of line ranges as intervals [a,b). This is used in two contexts:
* A set of lines we are tracking (which will change as we dig through history).
* To encode diffs, as pairs of ranges.
The main routine is range_set_map_across_diff(). It processes the diff between a commit C and some parent P. It determines which diff hunks are relevant to the ranges tracked in C, and computes the new ranges for P.
The algorithm is then simply to process history in topological order from newest to oldest, computing ranges and (partial) diffs. At branch points, we need to merge the ranges we are watching. We will find that many commits do not affect the chosen ranges, and mark them TREESAME (in addition to those already filtered by pathspec limiting). Another pass of history simplification then gets rid of such commits.
This is wired as an extra filtering pass in the log machinery. This currently only reduces code duplication, but should allow for other simplifications and options to be used.
Finally, we hook a diff printer into the output chain. Ideally we would wire directly into the diff logic, to optionally use features like word diff. However, that will require some major reworking of the diff chain, so we completely replace the output with our own diff for now.
As this was a GSoC project, and has quite some history by now, many people have helped. In no particular order, thanks go to
Jakub Narebski <[email protected]>
Jens Lehmann <[email protected]>
Jonathan Nieder <[email protected]>
Junio C Hamano <[email protected]>
Ramsay Jones <[email protected]>
Will Palmer <[email protected]>
Apologies to everyone I forgot.
--- Documentation/git-log.txt | 22 + Makefile | 2 + builtin/log.c | 31 + line-log.c | 1179 ++++++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 19 +- line-range.h | 11 + log-tree.c | 4 + revision.c | 9 + revision.h | 6 +- t/perf/p4211-line-log.sh | 34 ++ t/t4211-line-log.sh | 38 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-main | 68 +++ t/t4211/expect.two-ranges | 102 ++++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 +++++++++++ 20 files changed, 2145 insertions(+), 2 deletions(-) create mode 100644 line-log.c create mode 100644 line-log.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Documentation/git-log.txt +22 -0
@@ -69,6 +69,23 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. +-L <start>,<end>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" + within the <file>. 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. + +<start> and <end> can take one of these forms: + +include::line-range-format.txt[] +You can specify this option more than once. + + +--full-line-diff:: + Always print the interesting range even if the current commit + does not change any line of the range. + [\--] <path>...:: Show only commits that are enough to explain how the files that match the specified paths came to be. See "History
@@ -138,6 +155,11 @@ Examples This makes sense only when following a strict policy of merging all topic branches when staying on a single integration branch. +git log -L '/int main/',/^}/:main.c:: + + Shows how the function `main()` in the file 'main.c' evolved + over time. + `git log -3`:: Limits the number of commits to show to 3.
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-log.h LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h
@@ -796,6 +797,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-log.o LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o
builtin/log.c +31 -0
@@ -19,6 +19,7 @@#include "remote.h" #include "string-list.h" #include "parse-options.h" +#include "line-log.h" #include "branch.h" #include "streaming.h" #include "version.h"
@@ -41,6 +42,12 @@ NULL }; +struct line_opt_callback_data { +struct rev_info *rev; +const char *prefix; +struct string_list args; +}; +static int parse_decoration_style (const char *var,const char *value) {switch (git_config_maybe_bool (var, value)) {
@@ -75,6 +82,19 @@ static int decorate_callback(const struct option *opt, const char *arg, int unsereturn 0 ; } +static int log_line_range_callback (const struct option *option,const char *arg,int unset) +{ +struct line_opt_callback_data *data = option->value; + +if (!arg) +return -1 ; + + data->rev->line_level_traverse =1 ; +string_list_append (&data->args, arg); + +return 0 ; +} +static void cmd_log_init_defaults (struct rev_info *rev) {if (fmt_pretty)
@@ -97,6 +117,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, {struct userformat_want w;int quiet =0 , source =0 , mailmap =0 ; +static struct line_opt_callback_data line_cb = {NULL ,NULL ,STRING_LIST_INIT_DUP };const struct option builtin_log_options[] = {OPT_BOOLEAN (0 ,"quiet" , &quiet,N_ ("suppress diff output" )),
@@ -104,9 +125,15 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,OPT_BOOLEAN (0 ,"use-mailmap" , &mailmap,N_ ("Use mail map file" )), { OPTION_CALLBACK, 0, "decorate", NULL, NULL, N_("decorate options"), PARSE_OPT_OPTARG, decorate_callback}, +OPT_CALLBACK ('L' ,NULL , &line_cb,"n,m:file" , +"Process line range n,m in file, counting from 1" , + log_line_range_callback),OPT_END () }; + line_cb.rev = rev; + line_cb.prefix = prefix; + mailmap = use_mailmap_config; argc = parse_options(argc, argv, prefix, builtin_log_options, builtin_log_usage,
@@ -160,6 +187,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, rev->show_decorations =1 ;load_ref_decorations (decoration_style); } + +if (rev->line_level_traverse) +line_log_init (rev, line_cb.prefix, &line_cb.args); +setup_pager (); }
line-log.c new file +1179 -0
1,179 lines not on this page · raw message
line-log.h new file +49 -0
49 lines not on this page · raw message
line-range.c +18 -1
@@ -21,6 +21,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (1 < begin && (spec[0 ] =='+' || spec[0 ] =='-' )) { num =strtol (spec +1 , &term,10 );if (term != spec +1 ) { +if (!ret) +return term;if (spec[0 ] =='-' ) num =0 - num;if (0 < num)
@@ -35,7 +37,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, } num =strtol (spec, &term,10 );if (term != spec) { - *ret = num; +if (ret) + *ret = num;return term; }if (spec[0 ] !='/' )
@@ -49,6 +52,10 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (*term !='/' )return spec; +/* in the scan-only case we are not interested in the regex */ +if (!ret) +return term+1 ; +/* try [spec+1 .. term-1] as regexp */ *term =0 ; begin--;/* input is in human terms */
@@ -90,3 +97,13 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,return 0 ; } + +const char *skip_range_arg (const char *arg) +{ + arg =parse_loc (arg,NULL ,NULL ,0 ,-1 ,NULL ); + +if (*arg ==',' ) + arg =parse_loc (arg+1 ,NULL ,NULL ,0 ,0 ,NULL ); + +return arg; +}
line-range.h +11 -0
@@ -21,4 +21,15 @@ extern int parse_range_arg(const char *arg, void *cb_data, long lines, long *begin, long *end); +/* +* Scan past a range argument that could be parsed by +* 'parse_range_arg', to help the caller determine the start of the +* filename in '-L n,m:file' syntax. +* +* Returns a pointer to the first character after the 'n,m' part, or +* NULL in case the argument is obviously malformed. +*/ + +extern const char *skip_range_arg (const char *arg); +#endif /* LINE_RANGE_H */
log-tree.c +4 -0
@@ -9,6 +9,7 @@#include "string-list.h" #include "color.h" #include "gpg-interface.h" +#include "line-log.h" struct decoration name_decoration = {"object names" };
@@ -856,6 +857,9 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) log.parent =NULL ; opt->loginfo = &log; +if (opt->line_level_traverse) +return line_log_print (opt, commit); + shown =log_tree_diff (opt, commit, &log);if (!shown && opt->loginfo && opt->always_show_header) { log.parent =NULL ;
revision.c +9 -0
@@ -13,6 +13,7 @@#include "decorate.h" #include "log-tree.h" #include "string-list.h" +#include "line-log.h" #include "mailmap.h" volatile show_early_output_fn_t show_early_output;
@@ -1896,6 +1897,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->combine_merges) revs->ignore_merges =0 ; revs->diffopt.abbrev = revs->abbrev; + +if (revs->line_level_traverse) { + revs->limited =1 ; + revs->topo_order =1 ; + } +diff_setup_done (&revs->diffopt); grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED,
@@ -2166,6 +2173,8 @@ int prepare_revision_walk(struct rev_info *revs)return -1 ;if (revs->topo_order)sort_in_topological_order (&revs->commits, revs->lifo); +if (revs->line_level_traverse) +line_log_filter (revs);if (revs->simplify_merges)simplify_merges (revs);if (revs->children.name)
revision.h +5 -1
@@ -96,7 +96,8 @@ struct rev_info { cherry_mark:1, bisect:1, ancestry_path:1, - first_parent_only:1; + first_parent_only:1, + line_level_traverse:1;/* Diff flags */ unsigned int diff:1,
@@ -175,6 +176,9 @@ struct rev_info {int count_left;int count_right;int count_same; + +/* line level range that we are chasing */ +struct decoration line_log_data; };#define REV_TREE_SAME 0
t/perf/p4211-line-log.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='Tests log -L performance' +. ./perf-lib.sh + +test_perf_default_repo + +# Pick a file to log pseudo-randomly. The sort key is the blob hash, +# so it is stable. +test_expect_success 'select a file' ' + git ls-tree HEAD | grep ^100644 | + sort -k 3 | head -1 | cut -f 2 >filelist +' + +file=$(cat filelist) +export file + +test_perf 'git rev-list --topo-order (baseline)' ' + git rev-list --topo-order HEAD >/dev/null +' + +test_perf 'git log --follow (baseline for -M)' ' + git log --oneline --follow -- "$file" >/dev/null +' + +test_perf 'git log -L' ' + git log -L 1:"$file" >/dev/null +' + +test_perf 'git log -M -L' ' + git log -M -L 1:"$file" >/dev/null +' + +test_done
t/t4211-line-log.sh new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='test log -L' +. ./test-lib.sh + +test_expect_success 'setup (import history)' ' + git fast-import < "$TEST_DIRECTORY"/t4211/history.export && + git reset --hard +' + +canned_test () { + test_expect_success "$1" " + git log $1 >actual && + test_cmp \"\$TEST_DIRECTORY\"/t4211/expect.$2 actual + " +} + +canned_test "-L 4,12:a.c simple" simple-f +canned_test "-L 4,+9:a.c simple" simple-f +canned_test "-L '/long f/,/^}/:a.c' simple" simple-f + +canned_test "-L '/main/,/^}/:a.c' simple" simple-main + +canned_test "-L 1,+4:a.c simple" beginning-of-file + +canned_test "-L 20:a.c simple" end-of-file + +test_expect_success "-L 20,10000:a.c (bogus end)" ' + test_must_fail git log -L 20,10000:a.c simple 2>errors && + grep "has only.*lines" errors +' + +canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges +canned_test "-L 24,+1:a.c simple" vanishes-early + +canned_test "-L '/long f/,/^}/:b.c' move-support" move-support-f + +test_done
t/t4211/expect.beginning-of-file new file +43 -0
43 lines not on this page · raw message
t/t4211/expect.end-of-file new file +62 -0
62 lines not on this page · raw message
t/t4211/expect.move-support-f new file +40 -0
@@ -0,0 +1,40 @@ +commit 6ce3c4ff690136099bb17e1a8766b75764726ea7 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:50 2013 +0100 + + another simple change + +diff --git a/b.c b/b.c +--- a/b.c ++++ b/b.c +@@ -4,9 +4,9 @@ + long f(long x) + { + int s = 0; + while (x) { +- x >>= 1; ++ x /= 2; + s++; + } + return s; + } + +commit e6da343666244ea9e67cbe3f3bd26da860f9fe0e +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:28 2013 +0100 + + move file + +diff --git a/b.c b/b.c +--- /dev/null ++++ b/b.c +@@ -0,0 +4,9 @@ ++long f(long x) ++{ ++ int s = 0; ++ while (x) { ++ x >>= 1; ++ s++; ++ } ++ return s; ++}
t/t4211/expect.simple-f new file +59 -0
59 lines not on this page · raw message
t/t4211/expect.simple-main new file +68 -0
68 lines not on this page · raw message
t/t4211/expect.two-ranges new file +102 -0
102 lines not on this page · raw message
t/t4211/expect.vanishes-early new file +39 -0
@@ -0,0 +1,39 @@ +commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:43 2013 +0100 + + change back to complete line + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +24,1 @@ +-} +\ No newline at end of file ++/* incomplete lines are bad! */ + +commit 100b61a6f2f720f812620a9d10afb3a960ccb73c +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:10 2013 +0100 + + change to an incomplete line at end + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +22,1 @@ +-} ++} +\ No newline at end of file + +commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:44:48 2013 +0100 + + initial + +diff --git a/a.c b/a.c +--- /dev/null ++++ b/a.c +@@ -0,0 +20,1 @@ ++}
t/t4211/history.export new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.2.241.gee8bb87
Re: [PATCH v9 3/5] Implement line-history search (git log -L)
Quoted 18 lines · Thomas Rast
line-log.c new file +18
-0+void line_log_init (struct rev_info *rev,const char *prefix,struct string_list *args) +{ +struct commit *commit =NULL ; +struct line_log_data *range; + + commit =check_single_commit (rev); + range =parse_lines (commit, prefix, args); +add_line_range (rev, commit, range); + +if (!rev->diffopt.detect_rename) { +int i, count =0 ; +struct line_log_data *r = range; +const char **paths; +while (r) { + count++; + r = r->next; + } + paths =xmalloc ((count+1 )*sizeof (char *));
line-log.c line 721
Quoted 10 lines
line-log.c new file +10
-0+ r = range; +for (i =0 ; i < count; i++) { + paths[i] =xstrdup (r->spec->path); + r = r->next; + } + paths[count] =NULL ; +init_pathspec (&rev->diffopt.pathspec, paths); +free (paths); + } +}
Why not do the pathspec limitation under "-M"?
It is not like you are picking up origins of blocks of lines copied or moved from other files like "blame -C" does, so I suspect it would be simpler to mimic what --follow does, which is to (1) use the pathspec to follow the paths you care about, and then (2) when you find one or more of the paths you were following disappear in a commit, only at that point you re-check to see if there are other paths that existed in the parent that the disappeared paths were renamed from, and match with that one.
Re: [PATCH v9 3/5] Implement line-history search (git log -L)
Quoted 34 lines · Junio C Hamano
Quoted 19 lines · Thomas Rast
+void
line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args)line-log.c new file +17
-0+{ +struct commit *commit =NULL ; +struct line_log_data *range; + + commit =check_single_commit (rev); + range =parse_lines (commit, prefix, args); +add_line_range (rev, commit, range); + +if (!rev->diffopt.detect_rename) { +int i, count =0 ; +struct line_log_data *r = range; +const char **paths; +while (r) { + count++; + r = r->next; + } + paths =xmalloc ((count+1 )*sizeof (char *));line-log.c line 721
Quoted 10 lines
line-log.c new file +10
-0+ r = range; +for (i =0 ; i < count; i++) { + paths[i] =xstrdup (r->spec->path); + r = r->next; + } + paths[count] =NULL ; +init_pathspec (&rev->diffopt.pathspec, paths); +free (paths); + } +}Why not do the pathspec limitation under "-M"?
Quoted 8 lines
It is not like you are picking up origins of blocks of lines copied or moved from other files like "blame -C" does, so I suspect it would be simpler to mimic what --follow does, which is to (1) use the pathspec to follow the paths you care about, and then (2) when you find one or more of the paths you were following disappear in a commit, only at that point you re-check to see if there are other paths that existed in the parent that the disappeared paths were renamed from, and match with that one.
It's acting too soon though. The way log -L is currently wired, we do one revision walk with the pathspec filter already enabled to do the topo sorting. Wiring it in *at that point* would be equivalent to fixing --follow.
Which I plan to do Real Soon Now(tm). But let's not open too many cans of worms at the same time.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH v9 4/5 log -L: :pattern:file syntax to find by funcname
In reply to Thomas RastThis new syntax finds a funcname matching /pattern/, and then takes from there up to (but not including) the next funcname. So you can say
git log -L:main:main.c
and it will dig up the main() function and show its line-log, provided there are no other funcnames matching 'main'.
--- Documentation/blame-options.txt | 2 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 11 +-- Documentation/line-range-format.txt | 7 ++ builtin/blame.c | 2 +- line-log.c | 5 +- line-range.c | 130 +++++++++++++++++++++++++++++++++++- line-range.h | 3 +- t/t4211-line-log.sh | 2 + 9 files changed, 154 insertions(+), 14 deletions(-)
Documentation/blame-options.txt +1 -1
@@ -9,7 +9,7 @@ --show-stats:: Include additional statistics at the end of blame output. --L <start>,<end>:: +-L <start>,<end>, -L :<regex>:: Annotate only the given line range. <start> and <end> can take one of these forms:
Documentation/git-blame.txt +3 -3
@@ -8,9 +8,9 @@ git-blame - Show what revision and author last modified each line of a file SYNOPSIS -------- [verse] -'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m] - [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [--abbrev=<n>] - [<rev> | --contents <file> | --reverse <rev>] [--] <file> +'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] + [-L n,m | -L :fn] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] + [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>] [--] <file> DESCRIPTION -----------
Documentation/git-log.txt +6 -5
@@ -69,12 +69,13 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. --L <start>,<end>:<file>:: +-L <start>,<end>:<file>, -L :<regex>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" - within the <file>. 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. + (or the funcname regex <regex>) within the <file>. 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. <start> and <end> can take one of these forms:
Documentation/line-range-format.txt +7 -0
@@ -16,3 +16,10 @@ starting at the line given by <start>. This is only valid for <end> and will specify a number of lines before or after the line given by <start>. + + +- :regex ++ +If the option's argument is of the form :regex, it denotes the range +from the first funcname line that matches <regex>, up to the next +funcname line. ++
builtin/blame.c +1 -1
@@ -1940,7 +1940,7 @@ static void prepare_blame_range(struct scoreboard *sb,long lno, long *bottom, long *top) { - if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top)) + if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top, sb->path)) usage(blame_usage); }
line-log.c +3 -2
@@ -12,6 +12,7 @@#include "strbuf.h" #include "log-tree.h" #include "graph.h" +#include "userdiff.h" #include "line-log.h" static void range_set_grow (struct range_set *rs,size_t extra)
@@ -438,7 +439,6 @@ static void range_set_map_across_diff(struct range_set *out, *touched_out = touched; } -static struct commit *check_single_commit (struct rev_info *revs) {struct object *commit =NULL ;
@@ -559,7 +559,8 @@ static const char *nth_line(void *data, long line) cb_data.line_ends = ends;if (parse_range_arg (range_part, nth_line, &cb_data, - lines, &begin, &end)) + lines, &begin, &end, + spec->path))die ("malformed -L argument '%s'" , range_part);if (begin <1 ) begin =1 ;
line-range.c +129 -1
149 lines not on this page · raw message
line-range.h +2 -1
@@ -19,7 +19,8 @@extern int parse_range_arg (const char *arg,nth_line_fn_t nth_line_cb,void *cb_data,long lines, -long *begin,long *end); +long *begin,long *end, +const char *path);/* * Scan past a range argument that could be parsed by
t/t4211-line-log.sh +2 -0
@@ -18,8 +18,10 @@ canned_test () { canned_test "-L 4,12:a.c simple" simple-f canned_test "-L 4,+9:a.c simple" simple-f canned_test "-L '/long f/,/^}/:a.c' simple" simple-f +canned_test "-L :f:a.c simple" simple-f-to-main canned_test "-L '/main/,/^}/:a.c' simple" simple-main +canned_test "-L :main:a.c simple" simple-main-to-end canned_test "-L 1,+4:a.c simple" beginning-of-file
Signature · 1 line
1.8.2.241.gee8bb87
PATCH v9 5/5 Speed up log -L... -M
In reply to Thomas RastSo far log -L only used the implicit diff filtering by pathspec. If the user specifies -M, we cannot do that, and so we simply handed the whole diff queue (which is approximately 'git show --raw') to diffcore_std().
Unfortunately this is very slow. We can optimize a lot if we throw out files that we know cannot possibly be interesting, in the same spirit that the pathspec filtering reduces the number of files.
However, in this case, we have to be more careful. Because we want to look out for renames, we need to keep all filepairs where something was deleted.
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it speeds up 'log -M -L' by an order of magnitude.
--- line-log.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-)
line-log.c +52 -4
@@ -750,7 +750,50 @@ static void move_diff_queue(struct diff_queue_struct *dst,DIFF_QUEUE_CLEAR (src); } -static void queue_diffs (struct diff_options *opt, +static void filter_diffs_for_paths (struct line_log_data *range,int keep_deletions) +{ +int i; +struct diff_queue_struct outq; +DIFF_QUEUE_CLEAR (&outq); + +for (i =0 ; i < diff_queued_diff.nr; i++) { +struct diff_filepair *p = diff_queued_diff.queue[i]; +struct line_log_data *rg =NULL ; + +if (!DIFF_FILE_VALID (p->two)) { +if (keep_deletions) +diff_q (&outq, p); +else +diff_free_filepair (p); +continue ; + } +for (rg = range; rg; rg = rg->next) { +if (!strcmp (rg->spec->path, p->two->path)) +break ; + } +if (rg) +diff_q (&outq, p); +else +diff_free_filepair (p); + } +free (diff_queued_diff.queue); + diff_queued_diff = outq; +} + +static inline int diff_might_be_rename (void ) +{ +int i; +for (i =0 ; i < diff_queued_diff.nr; i++) +if (!DIFF_FILE_VALID (diff_queued_diff.queue[i]->one)) { +/* fprintf(stderr, "diff_might_be_rename found creation of: %s\n", */ +/* diff_queued_diff.queue[i]->two->path); */ +return 1 ; + } +return 0 ; +} + +static void queue_diffs (struct line_log_data *range, +struct diff_options *opt,struct diff_queue_struct *queue,struct commit *commit,struct commit *parent) {
@@ -766,7 +809,12 @@ static void queue_diffs(struct diff_options *opt,DIFF_QUEUE_CLEAR (&diff_queued_diff);diff_tree (&desc1, &desc2,"" , opt); -diffcore_std (opt); +if (opt->detect_rename) { +filter_diffs_for_paths (range,1 ); +if (diff_might_be_rename ()) +diffcore_std (opt); +filter_diffs_for_paths (range,0 ); + }move_diff_queue (queue, &diff_queued_diff);if (tree1)
@@ -1050,7 +1098,7 @@ static int process_ranges_ordinary_commit(struct rev_info *rev, struct commit *cif (commit->parents) parent = commit->parents->item; -queue_diffs (&rev->diffopt, &queue, commit, parent); +queue_diffs (range, &rev->diffopt, &queue, commit, parent); changed =process_all_files (&parent_range, rev, &queue, range);if (parent)add_line_range (rev, parent, parent_range);
@@ -1075,7 +1123,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *commfor (i =0 ; i < nparents; i++) { parents[i] = p->item; p = p->next; -queue_diffs (&rev->diffopt, &diffqueues[i], commit, parents[i]); +queue_diffs (range, &rev->diffopt, &diffqueues[i], commit, parents[i]); }for (i =0 ; i < nparents; i++) {
Signature · 1 line
1.8.2.241.gee8bb87
Re: [PATCH v9 5/5] Speed up log -L... -M
Quoted 2 lines · Thomas Rast
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it
s/using/use/
Quoted 1 line
speeds up 'log -M -L' by an order of magnitude.
Re: [PATCH v9 5/5] Speed up log -L... -M
Quoted 5 lines · Eric Sunshine
Quoted 2 lines · Thomas Rast
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it
s/using/use/
I'm not a native speaker, but I really think 'using' is more correct here. But feel free to suggest a better wording. The intention is that we should proceed in two steps: 'git log --follow' first needs to learn to adjust its pathspec filter as it walks revisions, much like I did here. Then this patch should be reverted in favor of just enabling --follow.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH v9 5/5] Speed up log -L... -M
Quoted 10 lines · Thomas Rast
Quoted 5 lines · Eric Sunshine
Quoted 2 lines · Thomas Rast
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it
s/using/use/
I'm not a native speaker, but I really think 'using' is more correct here.
Cannot...resist...grammar discussion.
I think you are both potentially right.
You might consider the two items "equivalent support" and "using that" to be two noun phrases that are objects of the preposition "by", and that the writer simply omits the second "by" after the "and". In which case you are making a noun phrase from a verb phrase, and would want to use the gerund form "using". And the sentence, simplifying out some modifiers and adding the missing "by" (which is fine to omit, but the parts of speech become much clearer with it there), looks like:
...should be replaced by equivalent support, and by using that.
However, you could also argue that the final clause is a second verb phrase for "this should" which just omits the extra "should" (which is also OK in a list. In which case "use" acts as a verb, and parses as:
...should be replaced by equivalent support, and this should just use that.
So I think it is correct either way, and though it parses slightly differently, the overall meaning is the same.
Phew. Totally not worth that much discussion, but for some reason I find these sorts of ambiguous language cases interesting.
-Peff
Re: [PATCH v9 5/5] Speed up log -L... -M
Quoted 29 lines · Jeff King
Quoted 9 lines · Thomas Rast
Quoted 5 lines · Eric Sunshine
Quoted 2 lines · Thomas Rast
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it
s/using/use/
I'm not a native speaker, but I really think 'using' is more correct here.
Cannot...resist...grammar discussion.
I think you are both potentially right.
You might consider the two items "equivalent support" and "using that" to be two noun phrases that are objects of the preposition "by", and that the writer simply omits the second "by" after the "and". In which case you are making a noun phrase from a verb phrase, and would want to use the gerund form "using". And the sentence, simplifying out some modifiers and adding the missing "by" (which is fine to omit, but the parts of speech become much clearer with it there), looks like:
...should be replaced by equivalent support, and by using that.
However, you could also argue that the final clause is a second verb phrase for "this should" which just omits the extra "should" (which is also OK in a list. In which case "use" acts as a verb, and parses as:
Quoted 8 lines
...should be replaced by equivalent support, and this should just use that.
So I think it is correct either way, and though it parses slightly differently, the overall meaning is the same.
Phew. Totally not worth that much discussion, but for some reason I find these sorts of ambiguous language cases interesting.
Wishing to avoid bike-shedding the commit message, I suggested s/using/use/ as a minor change to help clarify the grammar a bit. However, perhaps it could be rephrased as:
This is a bit hacky and should really be replaced by equivalent support in --follow, which can then be employed instead.
-- ES
cover git log -L
In reply to Thomas RastThis is a small fix to an embarrassing problem with 4/5; as Junio noticed
Quoted 1 line
Does not seem to pass its own test (
t4211-line-log.sh).
This resurrects two t/t4211/expect.* files that were missing from v9 due to a botched cleanup. Sorry for the noise.
Bo Yang (2):
Refactor parse_loc
Export rewrite_parents() for 'log -L'
Thomas Rast (3):
Implement line-history search (git log -L) log -L: :pattern:file syntax to find by funcname Speed up log -L... -M
Documentation/blame-options.txt | 21 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 23 + Documentation/line-range-format.txt | 25 + Makefile | 4 + builtin/blame.c | 99 +-- builtin/log.c | 31 + line-log.c | 1228 +++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 237 +++++++ line-range.h | 36 + log-tree.c | 4 + revision.c | 22 +- revision.h | 16 +- t/perf/p4211-line-log.sh | 34 + t/t4211-line-log.sh | 40 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-f-to-main | 100 +++ t/t4211/expect.simple-main | 68 ++ t/t4211/expect.simple-main-to-end | 70 ++ t/t4211/expect.two-ranges | 102 +++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 ++++++++++ t/t8003-blame-corner-cases.sh | 6 + 27 files changed, 2671 insertions(+), 123 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-log.c create mode 100644 line-log.h create mode 100644 line-range.c create mode 100644 line-range.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-f-to-main create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.simple-main-to-end create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Signature · 1 line
1.8.2.235.g4032450
PATCH v9 1/5 Refactor parse_loc
From: Bo Yang <[email protected]>
We want to use the same style of -L n,m argument for 'git log -L' as for git-blame. Refactor the argument parsing of the range arguments from builtin/blame.c to the (new) file that will hold the 'git log -L' logic.
To accommodate different data structures in blame and log -L, the file contents are abstracted away; parse_range_arg takes a callback that it uses to get the contents of a line of the (notional) file.
The new test is for a case that made me pause during debugging: the 'blame -L with invalid end' test was the only one that noticed an outright failure to parse the end *at all*. So make a more explicit test for that.
--- Documentation/blame-options.txt | 19 +------ Documentation/line-range-format.txt | 18 +++++++ Makefile | 2 + builtin/blame.c | 99 +++---------------------------------- line-range.c | 92 ++++++++++++++++++++++++++++++++++ line-range.h | 24 +++++++++ t/t8003-blame-corner-cases.sh | 6 +++ 7 files changed, 151 insertions(+), 109 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-range.c create mode 100644 line-range.h
Documentation/blame-options.txt +1 -18
@@ -13,24 +13,7 @@ Annotate only the given line range. <start> and <end> can take one of these forms: - - number -+ -If <start> or <end> is a number, it specifies an -absolute line number (lines count from 1). -+ - -- /regex/ -+ -This form will use the first line matching the given -POSIX regex. If <end> is a regex, it will search -starting at the line given by <start>. -+ - -- +offset or -offset -+ -This is only valid for <end> and will specify a number -of lines before or after the line given by <start>. -+ +include::line-range-format.txt[] -l:: Show long rev (Default: off).
Documentation/line-range-format.txt new file +18 -0
@@ -0,0 +1,18 @@ +- number ++ +If <start> or <end> is a number, it specifies an +absolute line number (lines count from 1). ++ + +- /regex/ ++ +This form will use the first line matching the given +POSIX regex. If <end> is a regex, it will search +starting at the line given by <start>. ++ + +- +offset or -offset ++ +This is only valid for <end> and will specify a number +of lines before or after the line given by <start>. ++
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h LIB_H += log-tree.h
@@ -795,6 +796,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o
builtin/blame.c +8 -91
133 lines not on this page · raw message
line-range.c new file +92 -0
92 lines not on this page · raw message
line-range.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef LINE_RANGE_H +#define LINE_RANGE_H + +/* +* Parse one item in an -L begin,end option w.r.t. the notional file +* object 'cb_data' consisting of 'lines' lines. +* +* The 'nth_line_cb' callback is used to determine the start of the +* line 'lno' inside the 'cb_data'. The caller is expected to already +* have a suitable map at hand to make this a constant-time lookup. +* +* Returns 0 in case of success and -1 if there was an error. The +* actual range is stored in *begin and *end. The counting starts +* at 1! In case of error, the caller should show usage message. +*/ + +typedef const char *(*nth_line_fn_t )(void *data,long lno); + +extern int parse_range_arg (const char *arg, +nth_line_fn_t nth_line_cb, +void *cb_data,long lines, +long *begin,long *end); + +#endif /* LINE_RANGE_H */
t/t8003-blame-corner-cases.sh +6 -0
@@ -175,6 +175,12 @@ test_expect_success 'blame -L with invalid end' ' grep "has only 2 lines" errors ' +test_expect_success 'blame parses <end> part of -L' ' + git blame -L1,1 tres >out && + cat out && + test $(wc -l < out) -eq 1 +' + test_expect_success 'indent of line numbers, nine lines' ' git blame nine_lines >actual && test $(grep -c " " actual) = 0
Signature · 1 line
1.8.2.235.g4032450
PATCH v9 2/5 Export rewrite_parents() for 'log -L'
In reply to Thomas RastFrom: Bo Yang <[email protected]>
The function rewrite_one is used to rewrite a single parent of the current commit, and is used by rewrite_parents to rewrite all the parents.
Decouple the dependence between them by making rewrite_one a callback function that is passed to rewrite_parents. Then export rewrite_parents for reuse by the line history browser.
We will use this function in line-log.c.
--- revision.c | 13 ++++--------- revision.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-)
revision.c +4 -9
@@ -2173,12 +2173,6 @@ int prepare_revision_walk(struct rev_info *revs)return 0 ; } -enum rewrite_result { - rewrite_one_ok, - rewrite_one_noparents, - rewrite_one_error -}; -static enum rewrite_result rewrite_one (struct rev_info *revs,struct commit **pp) {struct commit_list *cache =NULL ;
@@ -2200,12 +2194,13 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp } } -static int rewrite_parents (struct rev_info *revs,struct commit *commit) +int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent) {struct commit_list **pp = &commit->parents;while (*pp) {struct commit_list *parent = *pp; -switch (rewrite_one (revs, &parent->item)) { +switch (rewrite_parent (revs, &parent->item)) {case rewrite_one_ok:break ;case rewrite_one_noparents:
@@ -2371,7 +2366,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)if (action == commit_show && !revs->show_all && revs->prune && revs->dense &&want_ancestry (revs)) { -if (rewrite_parents (revs, commit) <0 ) +if (rewrite_parents (revs, commit, rewrite_one) <0 )return commit_error; }return action;
revision.h +10 -0
@@ -241,4 +241,14 @@ enum commit_action {extern enum commit_action get_commit_action (struct rev_info *revs,struct commit *commit);extern enum commit_action simplify_commit (struct rev_info *revs,struct commit *commit); +enum rewrite_result { + rewrite_one_ok, + rewrite_one_noparents, + rewrite_one_error +}; + +typedef enum rewrite_result (*rewrite_parent_fn_t )(struct rev_info *revs,struct commit **pp); + +extern int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent);#endif
Signature · 1 line
1.8.2.235.g4032450
PATCH v9 3/5 Implement line-history search (git log -L)
In reply to Thomas RastThis is a rewrite of much of Bo's work, mainly in an effort to split it into smaller, easier to understand routines.
The algorithm is built around the struct range_set, which encodes a series of line ranges as intervals [a,b). This is used in two contexts:
* A set of lines we are tracking (which will change as we dig through history).
* To encode diffs, as pairs of ranges.
The main routine is range_set_map_across_diff(). It processes the diff between a commit C and some parent P. It determines which diff hunks are relevant to the ranges tracked in C, and computes the new ranges for P.
The algorithm is then simply to process history in topological order from newest to oldest, computing ranges and (partial) diffs. At branch points, we need to merge the ranges we are watching. We will find that many commits do not affect the chosen ranges, and mark them TREESAME (in addition to those already filtered by pathspec limiting). Another pass of history simplification then gets rid of such commits.
This is wired as an extra filtering pass in the log machinery. This currently only reduces code duplication, but should allow for other simplifications and options to be used.
Finally, we hook a diff printer into the output chain. Ideally we would wire directly into the diff logic, to optionally use features like word diff. However, that will require some major reworking of the diff chain, so we completely replace the output with our own diff for now.
As this was a GSoC project, and has quite some history by now, many people have helped. In no particular order, thanks go to
Jakub Narebski <[email protected]>
Jens Lehmann <[email protected]>
Jonathan Nieder <[email protected]>
Junio C Hamano <[email protected]>
Ramsay Jones <[email protected]>
Will Palmer <[email protected]>
Apologies to everyone I forgot.
--- Documentation/git-log.txt | 22 + Makefile | 2 + builtin/log.c | 31 + line-log.c | 1179 ++++++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 19 +- line-range.h | 11 + log-tree.c | 4 + revision.c | 9 + revision.h | 6 +- t/perf/p4211-line-log.sh | 34 ++ t/t4211-line-log.sh | 38 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-main | 68 +++ t/t4211/expect.two-ranges | 102 ++++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 +++++++++++ 20 files changed, 2145 insertions(+), 2 deletions(-) create mode 100644 line-log.c create mode 100644 line-log.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Documentation/git-log.txt +22 -0
@@ -69,6 +69,23 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. +-L <start>,<end>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" + within the <file>. 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. + +<start> and <end> can take one of these forms: + +include::line-range-format.txt[] +You can specify this option more than once. + + +--full-line-diff:: + Always print the interesting range even if the current commit + does not change any line of the range. + [\--] <path>...:: Show only commits that are enough to explain how the files that match the specified paths came to be. See "History
@@ -138,6 +155,11 @@ Examples This makes sense only when following a strict policy of merging all topic branches when staying on a single integration branch. +git log -L '/int main/',/^}/:main.c:: + + Shows how the function `main()` in the file 'main.c' evolved + over time. + `git log -3`:: Limits the number of commits to show to 3.
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-log.h LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h
@@ -796,6 +797,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-log.o LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o
builtin/log.c +31 -0
@@ -19,6 +19,7 @@#include "remote.h" #include "string-list.h" #include "parse-options.h" +#include "line-log.h" #include "branch.h" #include "streaming.h" #include "version.h"
@@ -41,6 +42,12 @@ NULL }; +struct line_opt_callback_data { +struct rev_info *rev; +const char *prefix; +struct string_list args; +}; +static int parse_decoration_style (const char *var,const char *value) {switch (git_config_maybe_bool (var, value)) {
@@ -75,6 +82,19 @@ static int decorate_callback(const struct option *opt, const char *arg, int unsereturn 0 ; } +static int log_line_range_callback (const struct option *option,const char *arg,int unset) +{ +struct line_opt_callback_data *data = option->value; + +if (!arg) +return -1 ; + + data->rev->line_level_traverse =1 ; +string_list_append (&data->args, arg); + +return 0 ; +} +static void cmd_log_init_defaults (struct rev_info *rev) {if (fmt_pretty)
@@ -97,6 +117,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, {struct userformat_want w;int quiet =0 , source =0 , mailmap =0 ; +static struct line_opt_callback_data line_cb = {NULL ,NULL ,STRING_LIST_INIT_DUP };const struct option builtin_log_options[] = {OPT_BOOLEAN (0 ,"quiet" , &quiet,N_ ("suppress diff output" )),
@@ -104,9 +125,15 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,OPT_BOOLEAN (0 ,"use-mailmap" , &mailmap,N_ ("Use mail map file" )), { OPTION_CALLBACK, 0, "decorate", NULL, NULL, N_("decorate options"), PARSE_OPT_OPTARG, decorate_callback}, +OPT_CALLBACK ('L' ,NULL , &line_cb,"n,m:file" , +"Process line range n,m in file, counting from 1" , + log_line_range_callback),OPT_END () }; + line_cb.rev = rev; + line_cb.prefix = prefix; + mailmap = use_mailmap_config; argc = parse_options(argc, argv, prefix, builtin_log_options, builtin_log_usage,
@@ -160,6 +187,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, rev->show_decorations =1 ;load_ref_decorations (decoration_style); } + +if (rev->line_level_traverse) +line_log_init (rev, line_cb.prefix, &line_cb.args); +setup_pager (); }
line-log.c new file +1179 -0
1,179 lines not on this page · raw message
line-log.h new file +49 -0
49 lines not on this page · raw message
line-range.c +18 -1
@@ -21,6 +21,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (1 < begin && (spec[0 ] =='+' || spec[0 ] =='-' )) { num =strtol (spec +1 , &term,10 );if (term != spec +1 ) { +if (!ret) +return term;if (spec[0 ] =='-' ) num =0 - num;if (0 < num)
@@ -35,7 +37,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, } num =strtol (spec, &term,10 );if (term != spec) { - *ret = num; +if (ret) + *ret = num;return term; }if (spec[0 ] !='/' )
@@ -49,6 +52,10 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (*term !='/' )return spec; +/* in the scan-only case we are not interested in the regex */ +if (!ret) +return term+1 ; +/* try [spec+1 .. term-1] as regexp */ *term =0 ; begin--;/* input is in human terms */
@@ -90,3 +97,13 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,return 0 ; } + +const char *skip_range_arg (const char *arg) +{ + arg =parse_loc (arg,NULL ,NULL ,0 ,-1 ,NULL ); + +if (*arg ==',' ) + arg =parse_loc (arg+1 ,NULL ,NULL ,0 ,0 ,NULL ); + +return arg; +}
line-range.h +11 -0
@@ -21,4 +21,15 @@ extern int parse_range_arg(const char *arg, void *cb_data, long lines, long *begin, long *end); +/* +* Scan past a range argument that could be parsed by +* 'parse_range_arg', to help the caller determine the start of the +* filename in '-L n,m:file' syntax. +* +* Returns a pointer to the first character after the 'n,m' part, or +* NULL in case the argument is obviously malformed. +*/ + +extern const char *skip_range_arg (const char *arg); +#endif /* LINE_RANGE_H */
log-tree.c +4 -0
@@ -9,6 +9,7 @@#include "string-list.h" #include "color.h" #include "gpg-interface.h" +#include "line-log.h" struct decoration name_decoration = {"object names" };
@@ -856,6 +857,9 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) log.parent =NULL ; opt->loginfo = &log; +if (opt->line_level_traverse) +return line_log_print (opt, commit); + shown =log_tree_diff (opt, commit, &log);if (!shown && opt->loginfo && opt->always_show_header) { log.parent =NULL ;
revision.c +9 -0
@@ -13,6 +13,7 @@#include "decorate.h" #include "log-tree.h" #include "string-list.h" +#include "line-log.h" #include "mailmap.h" volatile show_early_output_fn_t show_early_output;
@@ -1896,6 +1897,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->combine_merges) revs->ignore_merges =0 ; revs->diffopt.abbrev = revs->abbrev; + +if (revs->line_level_traverse) { + revs->limited =1 ; + revs->topo_order =1 ; + } +diff_setup_done (&revs->diffopt); grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED,
@@ -2166,6 +2173,8 @@ int prepare_revision_walk(struct rev_info *revs)return -1 ;if (revs->topo_order)sort_in_topological_order (&revs->commits, revs->lifo); +if (revs->line_level_traverse) +line_log_filter (revs);if (revs->simplify_merges)simplify_merges (revs);if (revs->children.name)
revision.h +5 -1
@@ -96,7 +96,8 @@ struct rev_info { cherry_mark:1, bisect:1, ancestry_path:1, - first_parent_only:1; + first_parent_only:1, + line_level_traverse:1;/* Diff flags */ unsigned int diff:1,
@@ -175,6 +176,9 @@ struct rev_info {int count_left;int count_right;int count_same; + +/* line level range that we are chasing */ +struct decoration line_log_data; };#define REV_TREE_SAME 0
t/perf/p4211-line-log.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='Tests log -L performance' +. ./perf-lib.sh + +test_perf_default_repo + +# Pick a file to log pseudo-randomly. The sort key is the blob hash, +# so it is stable. +test_expect_success 'select a file' ' + git ls-tree HEAD | grep ^100644 | + sort -k 3 | head -1 | cut -f 2 >filelist +' + +file=$(cat filelist) +export file + +test_perf 'git rev-list --topo-order (baseline)' ' + git rev-list --topo-order HEAD >/dev/null +' + +test_perf 'git log --follow (baseline for -M)' ' + git log --oneline --follow -- "$file" >/dev/null +' + +test_perf 'git log -L' ' + git log -L 1:"$file" >/dev/null +' + +test_perf 'git log -M -L' ' + git log -M -L 1:"$file" >/dev/null +' + +test_done
t/t4211-line-log.sh new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='test log -L' +. ./test-lib.sh + +test_expect_success 'setup (import history)' ' + git fast-import < "$TEST_DIRECTORY"/t4211/history.export && + git reset --hard +' + +canned_test () { + test_expect_success "$1" " + git log $1 >actual && + test_cmp \"\$TEST_DIRECTORY\"/t4211/expect.$2 actual + " +} + +canned_test "-L 4,12:a.c simple" simple-f +canned_test "-L 4,+9:a.c simple" simple-f +canned_test "-L '/long f/,/^}/:a.c' simple" simple-f + +canned_test "-L '/main/,/^}/:a.c' simple" simple-main + +canned_test "-L 1,+4:a.c simple" beginning-of-file + +canned_test "-L 20:a.c simple" end-of-file + +test_expect_success "-L 20,10000:a.c (bogus end)" ' + test_must_fail git log -L 20,10000:a.c simple 2>errors && + grep "has only.*lines" errors +' + +canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges +canned_test "-L 24,+1:a.c simple" vanishes-early + +canned_test "-L '/long f/,/^}/:b.c' move-support" move-support-f + +test_done
t/t4211/expect.beginning-of-file new file +43 -0
43 lines not on this page · raw message
t/t4211/expect.end-of-file new file +62 -0
62 lines not on this page · raw message
t/t4211/expect.move-support-f new file +40 -0
@@ -0,0 +1,40 @@ +commit 6ce3c4ff690136099bb17e1a8766b75764726ea7 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:50 2013 +0100 + + another simple change + +diff --git a/b.c b/b.c +--- a/b.c ++++ b/b.c +@@ -4,9 +4,9 @@ + long f(long x) + { + int s = 0; + while (x) { +- x >>= 1; ++ x /= 2; + s++; + } + return s; + } + +commit e6da343666244ea9e67cbe3f3bd26da860f9fe0e +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:28 2013 +0100 + + move file + +diff --git a/b.c b/b.c +--- /dev/null ++++ b/b.c +@@ -0,0 +4,9 @@ ++long f(long x) ++{ ++ int s = 0; ++ while (x) { ++ x >>= 1; ++ s++; ++ } ++ return s; ++}
t/t4211/expect.simple-f new file +59 -0
59 lines not on this page · raw message
t/t4211/expect.simple-main new file +68 -0
68 lines not on this page · raw message
t/t4211/expect.two-ranges new file +102 -0
102 lines not on this page · raw message
t/t4211/expect.vanishes-early new file +39 -0
@@ -0,0 +1,39 @@ +commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:43 2013 +0100 + + change back to complete line + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +24,1 @@ +-} +\ No newline at end of file ++/* incomplete lines are bad! */ + +commit 100b61a6f2f720f812620a9d10afb3a960ccb73c +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:10 2013 +0100 + + change to an incomplete line at end + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +22,1 @@ +-} ++} +\ No newline at end of file + +commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:44:48 2013 +0100 + + initial + +diff --git a/a.c b/a.c +--- /dev/null ++++ b/a.c +@@ -0,0 +20,1 @@ ++}
t/t4211/history.export new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.2.235.g4032450
Re: [PATCH v9a 3/5] Implement line-history search (git log -L)
Quoted 34 lines
t/t4211-line-log.sh new file +28
-0@@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='test log -L' +. ./test-lib.sh + +test_expect_success 'setup (import history)' ' + git fast-import < "$TEST_DIRECTORY"/t4211/history.export && + git reset --hard +' + +canned_test () { + test_expect_success "$1" " + git log $1 >actual && + test_cmp \"\$TEST_DIRECTORY\"/t4211/expect.$2 actual + " +} + +canned_test "-L 4,12:a.c simple" simple-f +canned_test "-L 4,+9:a.c simple" simple-f +canned_test "-L '/long f/,/^}/:a.c' simple" simple-f + +canned_test "-L '/main/,/^}/:a.c' simple" simple-main + +canned_test "-L 1,+4:a.c simple" beginning-of-file + +canned_test "-L 20:a.c simple" end-of-file + +test_expect_success "-L 20,10000:a.c (bogus end)" '
t/t4211-line-log.sh line 38
Quoted 10 lines
t/t4211-line-log.sh new file +10
-0+ test_must_fail git log -L 20,10000:a.c simple 2>errors && + grep "has only.*lines" errors +' + +canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges +canned_test "-L 24,+1:a.c simple" vanishes-early + +canned_test "-L '/long f/,/^}/:b.c' move-support" move-support-f + +test_done
Hi Thomas,
You should probably add some failing tests (for example when the input parameters are not correct), and as a matter of fact, I have the following segfault with v9:
Starting program: /home/antoine/code/git/git-log -M -L :git.c [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x000000000050164d in parse_range_funcname (arg=0x84f2d0 ":git.c",
nth_line_cb=0, cb_data=0x0, lines=0, begin=0x0, end=0x0, path=0x0)
at line-range.c:160
#2 0x0000000000501d28 in skip_range_arg (arg=0x84f2d0 ":git.c")
at line-range.c:229
#3 0x00000000004fda78 in parse_lines (commit=0x86ea60, prefix=0x0,
args=0x7fad48) at line-log.c:544
#4 0x00000000004fd75a in line_log_init (rev=0x7fffffffd9a8, prefix=0x0,
args=0x7fad48) at line-log.c:701
#5 0x0000000000457189 in cmd_log_init_finish (argc=1, argv=0x7fffffffe238,
prefix=0x0, rev=0x7fffffffd9a8, opt=0x7fffffffd988) at builtin/log.c:192
#6 0x0000000000455d2c in cmd_log_init (argc=4, argv=0x7fffffffe238,
prefix=0x0, rev=0x7fffffffd9a8, opt=0x7fffffffd988) at builtin/log.c:201
#7 0x0000000000457250 in cmd_log (argc=4, argv=0x7fffffffe238, prefix=0x0)
at builtin/log.c:612
#8 0x00000000004056cf in run_builtin (p=0x7f7af8, argc=4,
argv=0x7fffffffe238) at git.c:281
#9 0x00000000004047aa in handle_internal_command (argc=4,
argv=0x7fffffffe238) at git.c:443#10 0x0000000000404506 in main (argc=4, argv=0x7fffffffe238) at git.c:532
Re: [PATCH v9a 3/5] Implement line-history search (git log -L)
Quoted 1 line
You should probably add some failing tests
I guess it should be "failure" tests, not failing tests.
v10 cover git log -L
In reply to Antoine PelisseFrom: Thomas Rast <[email protected]>
This adds a bunch of fixes and failing tests for invalid -L arguments; as Antoine discovered, some variations would segfault v9.
I also changed the beginning of parse_range_funcname (in patch 4/5), which now also lets you backslash-escape a : in a funcname regex. The old version was based on the assumption that there could only be a ':' in the string if we were coming from scan_range_arg, which made it a bit hard to read.
Bo Yang (2):
Refactor parse_loc
Export rewrite_parents() for 'log -L'
Thomas Rast (3):
Implement line-history search (git log -L) log -L: :pattern:file syntax to find by funcname Speed up log -L... -M
Documentation/blame-options.txt | 21 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 23 + Documentation/line-range-format.txt | 25 + Makefile | 4 + builtin/blame.c | 99 +-- builtin/log.c | 31 + line-log.c | 1228 +++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 243 +++++++ line-range.h | 36 + log-tree.c | 4 + revision.c | 22 +- revision.h | 16 +- t/perf/p4211-line-log.sh | 34 + t/t4211-line-log.sh | 53 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-f-to-main | 100 +++ t/t4211/expect.simple-main | 68 ++ t/t4211/expect.simple-main-to-end | 70 ++ t/t4211/expect.two-ranges | 102 +++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 ++++++++++ t/t8003-blame-corner-cases.sh | 6 + 27 files changed, 2690 insertions(+), 123 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-log.c create mode 100644 line-log.h create mode 100644 line-range.c create mode 100644 line-range.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-f-to-main create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.simple-main-to-end create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v10 1/5 Refactor parse_loc
From: Bo Yang <[email protected]>
We want to use the same style of -L n,m argument for 'git log -L' as for git-blame. Refactor the argument parsing of the range arguments from builtin/blame.c to the (new) file that will hold the 'git log -L' logic.
To accommodate different data structures in blame and log -L, the file contents are abstracted away; parse_range_arg takes a callback that it uses to get the contents of a line of the (notional) file.
The new test is for a case that made me pause during debugging: the 'blame -L with invalid end' test was the only one that noticed an outright failure to parse the end *at all*. So make a more explicit test for that.
--- Documentation/blame-options.txt | 19 +------ Documentation/line-range-format.txt | 18 +++++++ Makefile | 2 + builtin/blame.c | 99 +++---------------------------------- line-range.c | 92 ++++++++++++++++++++++++++++++++++ line-range.h | 24 +++++++++ t/t8003-blame-corner-cases.sh | 6 +++ 7 files changed, 151 insertions(+), 109 deletions(-) create mode 100644 Documentation/line-range-format.txt create mode 100644 line-range.c create mode 100644 line-range.h
Documentation/blame-options.txt +1 -18
@@ -13,24 +13,7 @@ Annotate only the given line range. <start> and <end> can take one of these forms: - - number -+ -If <start> or <end> is a number, it specifies an -absolute line number (lines count from 1). -+ - -- /regex/ -+ -This form will use the first line matching the given -POSIX regex. If <end> is a regex, it will search -starting at the line given by <start>. -+ - -- +offset or -offset -+ -This is only valid for <end> and will specify a number -of lines before or after the line given by <start>. -+ +include::line-range-format.txt[] -l:: Show long rev (Default: off).
Documentation/line-range-format.txt new file +18 -0
@@ -0,0 +1,18 @@ +- number ++ +If <start> or <end> is a number, it specifies an +absolute line number (lines count from 1). ++ + +- /regex/ ++ +This form will use the first line matching the given +POSIX regex. If <end> is a regex, it will search +starting at the line given by <start>. ++ + +- +offset or -offset ++ +This is only valid for <end> and will specify a number +of lines before or after the line given by <start>. ++
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h LIB_H += log-tree.h
@@ -795,6 +796,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o
builtin/blame.c +8 -91
133 lines not on this page · raw message
line-range.c new file +92 -0
92 lines not on this page · raw message
line-range.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef LINE_RANGE_H +#define LINE_RANGE_H + +/* +* Parse one item in an -L begin,end option w.r.t. the notional file +* object 'cb_data' consisting of 'lines' lines. +* +* The 'nth_line_cb' callback is used to determine the start of the +* line 'lno' inside the 'cb_data'. The caller is expected to already +* have a suitable map at hand to make this a constant-time lookup. +* +* Returns 0 in case of success and -1 if there was an error. The +* actual range is stored in *begin and *end. The counting starts +* at 1! In case of error, the caller should show usage message. +*/ + +typedef const char *(*nth_line_fn_t )(void *data,long lno); + +extern int parse_range_arg (const char *arg, +nth_line_fn_t nth_line_cb, +void *cb_data,long lines, +long *begin,long *end); + +#endif /* LINE_RANGE_H */
t/t8003-blame-corner-cases.sh +6 -0
@@ -175,6 +175,12 @@ test_expect_success 'blame -L with invalid end' ' grep "has only 2 lines" errors ' +test_expect_success 'blame parses <end> part of -L' ' + git blame -L1,1 tres >out && + cat out && + test $(wc -l < out) -eq 1 +' + test_expect_success 'indent of line numbers, nine lines' ' git blame nine_lines >actual && test $(grep -c " " actual) = 0
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v10 2/5 Export rewrite_parents() for 'log -L'
In reply to Thomas RastFrom: Bo Yang <[email protected]>
The function rewrite_one is used to rewrite a single parent of the current commit, and is used by rewrite_parents to rewrite all the parents.
Decouple the dependence between them by making rewrite_one a callback function that is passed to rewrite_parents. Then export rewrite_parents for reuse by the line history browser.
We will use this function in line-log.c.
--- revision.c | 13 ++++--------- revision.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-)
revision.c +4 -9
@@ -2173,12 +2173,6 @@ int prepare_revision_walk(struct rev_info *revs)return 0 ; } -enum rewrite_result { - rewrite_one_ok, - rewrite_one_noparents, - rewrite_one_error -}; -static enum rewrite_result rewrite_one (struct rev_info *revs,struct commit **pp) {struct commit_list *cache =NULL ;
@@ -2200,12 +2194,13 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp } } -static int rewrite_parents (struct rev_info *revs,struct commit *commit) +int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent) {struct commit_list **pp = &commit->parents;while (*pp) {struct commit_list *parent = *pp; -switch (rewrite_one (revs, &parent->item)) { +switch (rewrite_parent (revs, &parent->item)) {case rewrite_one_ok:break ;case rewrite_one_noparents:
@@ -2371,7 +2366,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)if (action == commit_show && !revs->show_all && revs->prune && revs->dense &&want_ancestry (revs)) { -if (rewrite_parents (revs, commit) <0 ) +if (rewrite_parents (revs, commit, rewrite_one) <0 )return commit_error; }return action;
revision.h +10 -0
@@ -241,4 +241,14 @@ enum commit_action {extern enum commit_action get_commit_action (struct rev_info *revs,struct commit *commit);extern enum commit_action simplify_commit (struct rev_info *revs,struct commit *commit); +enum rewrite_result { + rewrite_one_ok, + rewrite_one_noparents, + rewrite_one_error +}; + +typedef enum rewrite_result (*rewrite_parent_fn_t )(struct rev_info *revs,struct commit **pp); + +extern int rewrite_parents (struct rev_info *revs,struct commit *commit, +rewrite_parent_fn_t rewrite_parent);#endif
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v10 3/5 Implement line-history search (git log -L)
In reply to Thomas RastThis is a rewrite of much of Bo's work, mainly in an effort to split it into smaller, easier to understand routines.
The algorithm is built around the struct range_set, which encodes a series of line ranges as intervals [a,b). This is used in two contexts:
* A set of lines we are tracking (which will change as we dig through history).
* To encode diffs, as pairs of ranges.
The main routine is range_set_map_across_diff(). It processes the diff between a commit C and some parent P. It determines which diff hunks are relevant to the ranges tracked in C, and computes the new ranges for P.
The algorithm is then simply to process history in topological order from newest to oldest, computing ranges and (partial) diffs. At branch points, we need to merge the ranges we are watching. We will find that many commits do not affect the chosen ranges, and mark them TREESAME (in addition to those already filtered by pathspec limiting). Another pass of history simplification then gets rid of such commits.
This is wired as an extra filtering pass in the log machinery. This currently only reduces code duplication, but should allow for other simplifications and options to be used.
Finally, we hook a diff printer into the output chain. Ideally we would wire directly into the diff logic, to optionally use features like word diff. However, that will require some major reworking of the diff chain, so we completely replace the output with our own diff for now.
As this was a GSoC project, and has quite some history by now, many people have helped. In no particular order, thanks go to
Jakub Narebski <[email protected]>
Jens Lehmann <[email protected]>
Jonathan Nieder <[email protected]>
Junio C Hamano <[email protected]>
Ramsay Jones <[email protected]>
Will Palmer <[email protected]>
Apologies to everyone I forgot.
--- Documentation/git-log.txt | 22 + Makefile | 2 + builtin/log.c | 31 + line-log.c | 1179 ++++++++++++++++++++++++++++++++++++++ line-log.h | 49 ++ line-range.c | 19 +- line-range.h | 11 + log-tree.c | 4 + revision.c | 9 + revision.h | 6 +- t/perf/p4211-line-log.sh | 34 ++ t/t4211-line-log.sh | 49 ++ t/t4211/expect.beginning-of-file | 43 ++ t/t4211/expect.end-of-file | 62 ++ t/t4211/expect.move-support-f | 40 ++ t/t4211/expect.simple-f | 59 ++ t/t4211/expect.simple-main | 68 +++ t/t4211/expect.two-ranges | 102 ++++ t/t4211/expect.vanishes-early | 39 ++ t/t4211/history.export | 330 +++++++++++ 20 files changed, 2156 insertions(+), 2 deletions(-) create mode 100644 line-log.c create mode 100644 line-log.h create mode 100755 t/perf/p4211-line-log.sh create mode 100755 t/t4211-line-log.sh create mode 100644 t/t4211/expect.beginning-of-file create mode 100644 t/t4211/expect.end-of-file create mode 100644 t/t4211/expect.move-support-f create mode 100644 t/t4211/expect.simple-f create mode 100644 t/t4211/expect.simple-main create mode 100644 t/t4211/expect.two-ranges create mode 100644 t/t4211/expect.vanishes-early create mode 100644 t/t4211/history.export
Documentation/git-log.txt +22 -0
@@ -69,6 +69,23 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. +-L <start>,<end>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" + within the <file>. 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. + +<start> and <end> can take one of these forms: + +include::line-range-format.txt[] +You can specify this option more than once. + + +--full-line-diff:: + Always print the interesting range even if the current commit + does not change any line of the range. + [\--] <path>...:: Show only commits that are enough to explain how the files that match the specified paths came to be. See "History
@@ -138,6 +155,11 @@ Examples This makes sense only when following a strict policy of merging all topic branches when staying on a single integration branch. +git log -L '/int main/',/^}/:main.c:: + + Shows how the function `main()` in the file 'main.c' evolved + over time. + `git log -3`:: Limits the number of commits to show to 3.
Makefile +2 -0
@@ -667,6 +667,7 @@ LIB_H += help.h LIB_H += http.h LIB_H += kwset.h LIB_H += levenshtein.h +LIB_H += line-log.h LIB_H += line-range.h LIB_H += list-objects.h LIB_H += ll-merge.h
@@ -796,6 +797,7 @@ LIB_OBJS += hex.o LIB_OBJS += ident.o LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o +LIB_OBJS += line-log.o LIB_OBJS += line-range.o LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o
builtin/log.c +31 -0
@@ -19,6 +19,7 @@#include "remote.h" #include "string-list.h" #include "parse-options.h" +#include "line-log.h" #include "branch.h" #include "streaming.h" #include "version.h"
@@ -41,6 +42,12 @@ NULL }; +struct line_opt_callback_data { +struct rev_info *rev; +const char *prefix; +struct string_list args; +}; +static int parse_decoration_style (const char *var,const char *value) {switch (git_config_maybe_bool (var, value)) {
@@ -75,6 +82,19 @@ static int decorate_callback(const struct option *opt, const char *arg, int unsereturn 0 ; } +static int log_line_range_callback (const struct option *option,const char *arg,int unset) +{ +struct line_opt_callback_data *data = option->value; + +if (!arg) +return -1 ; + + data->rev->line_level_traverse =1 ; +string_list_append (&data->args, arg); + +return 0 ; +} +static void cmd_log_init_defaults (struct rev_info *rev) {if (fmt_pretty)
@@ -97,6 +117,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, {struct userformat_want w;int quiet =0 , source =0 , mailmap =0 ; +static struct line_opt_callback_data line_cb = {NULL ,NULL ,STRING_LIST_INIT_DUP };const struct option builtin_log_options[] = {OPT_BOOLEAN (0 ,"quiet" , &quiet,N_ ("suppress diff output" )),
@@ -104,9 +125,15 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,OPT_BOOLEAN (0 ,"use-mailmap" , &mailmap,N_ ("Use mail map file" )), { OPTION_CALLBACK, 0, "decorate", NULL, NULL, N_("decorate options"), PARSE_OPT_OPTARG, decorate_callback}, +OPT_CALLBACK ('L' ,NULL , &line_cb,"n,m:file" , +"Process line range n,m in file, counting from 1" , + log_line_range_callback),OPT_END () }; + line_cb.rev = rev; + line_cb.prefix = prefix; + mailmap = use_mailmap_config; argc = parse_options(argc, argv, prefix, builtin_log_options, builtin_log_usage,
@@ -160,6 +187,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, rev->show_decorations =1 ;load_ref_decorations (decoration_style); } + +if (rev->line_level_traverse) +line_log_init (rev, line_cb.prefix, &line_cb.args); +setup_pager (); }
line-log.c new file +1179 -0
1,179 lines not on this page · raw message
line-log.h new file +49 -0
49 lines not on this page · raw message
line-range.c +18 -1
@@ -21,6 +21,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (1 < begin && (spec[0 ] =='+' || spec[0 ] =='-' )) { num =strtol (spec +1 , &term,10 );if (term != spec +1 ) { +if (!ret) +return term;if (spec[0 ] =='-' ) num =0 - num;if (0 < num)
@@ -35,7 +37,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, } num =strtol (spec, &term,10 );if (term != spec) { - *ret = num; +if (ret) + *ret = num;return term; }if (spec[0 ] !='/' )
@@ -49,6 +52,10 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,if (*term !='/' )return spec; +/* in the scan-only case we are not interested in the regex */ +if (!ret) +return term+1 ; +/* try [spec+1 .. term-1] as regexp */ *term =0 ; begin--;/* input is in human terms */
@@ -90,3 +97,13 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,return 0 ; } + +const char *skip_range_arg (const char *arg) +{ + arg =parse_loc (arg,NULL ,NULL ,0 ,-1 ,NULL ); + +if (*arg ==',' ) + arg =parse_loc (arg+1 ,NULL ,NULL ,0 ,0 ,NULL ); + +return arg; +}
line-range.h +11 -0
@@ -21,4 +21,15 @@ extern int parse_range_arg(const char *arg, void *cb_data, long lines, long *begin, long *end); +/* +* Scan past a range argument that could be parsed by +* 'parse_range_arg', to help the caller determine the start of the +* filename in '-L n,m:file' syntax. +* +* Returns a pointer to the first character after the 'n,m' part, or +* NULL in case the argument is obviously malformed. +*/ + +extern const char *skip_range_arg (const char *arg); +#endif /* LINE_RANGE_H */
log-tree.c +4 -0
@@ -9,6 +9,7 @@#include "string-list.h" #include "color.h" #include "gpg-interface.h" +#include "line-log.h" struct decoration name_decoration = {"object names" };
@@ -853,6 +854,9 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) log.parent =NULL ; opt->loginfo = &log; +if (opt->line_level_traverse) +return line_log_print (opt, commit); + shown =log_tree_diff (opt, commit, &log);if (!shown && opt->loginfo && opt->always_show_header) { log.parent =NULL ;
revision.c +9 -0
@@ -13,6 +13,7 @@#include "decorate.h" #include "log-tree.h" #include "string-list.h" +#include "line-log.h" #include "mailmap.h" volatile show_early_output_fn_t show_early_output;
@@ -1896,6 +1897,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->combine_merges) revs->ignore_merges =0 ; revs->diffopt.abbrev = revs->abbrev; + +if (revs->line_level_traverse) { + revs->limited =1 ; + revs->topo_order =1 ; + } +diff_setup_done (&revs->diffopt); grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED,
@@ -2166,6 +2173,8 @@ int prepare_revision_walk(struct rev_info *revs)return -1 ;if (revs->topo_order)sort_in_topological_order (&revs->commits, revs->lifo); +if (revs->line_level_traverse) +line_log_filter (revs);if (revs->simplify_merges)simplify_merges (revs);if (revs->children.name)
revision.h +5 -1
@@ -96,7 +96,8 @@ struct rev_info { cherry_mark:1, bisect:1, ancestry_path:1, - first_parent_only:1; + first_parent_only:1, + line_level_traverse:1;/* Diff flags */ unsigned int diff:1,
@@ -175,6 +176,9 @@ struct rev_info {int count_left;int count_right;int count_same; + +/* line level range that we are chasing */ +struct decoration line_log_data; };#define REV_TREE_SAME 0
t/perf/p4211-line-log.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='Tests log -L performance' +. ./perf-lib.sh + +test_perf_default_repo + +# Pick a file to log pseudo-randomly. The sort key is the blob hash, +# so it is stable. +test_expect_success 'select a file' ' + git ls-tree HEAD | grep ^100644 | + sort -k 3 | head -1 | cut -f 2 >filelist +' + +file=$(cat filelist) +export file + +test_perf 'git rev-list --topo-order (baseline)' ' + git rev-list --topo-order HEAD >/dev/null +' + +test_perf 'git log --follow (baseline for -M)' ' + git log --oneline --follow -- "$file" >/dev/null +' + +test_perf 'git log -L' ' + git log -L 1:"$file" >/dev/null +' + +test_perf 'git log -M -L' ' + git log -M -L 1:"$file" >/dev/null +' + +test_done
t/t4211-line-log.sh new file +49 -0
49 lines not on this page · raw message
t/t4211/expect.beginning-of-file new file +43 -0
43 lines not on this page · raw message
t/t4211/expect.end-of-file new file +62 -0
62 lines not on this page · raw message
t/t4211/expect.move-support-f new file +40 -0
@@ -0,0 +1,40 @@ +commit 6ce3c4ff690136099bb17e1a8766b75764726ea7 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:50 2013 +0100 + + another simple change + +diff --git a/b.c b/b.c +--- a/b.c ++++ b/b.c +@@ -4,9 +4,9 @@ + long f(long x) + { + int s = 0; + while (x) { +- x >>= 1; ++ x /= 2; + s++; + } + return s; + } + +commit e6da343666244ea9e67cbe3f3bd26da860f9fe0e +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:49:28 2013 +0100 + + move file + +diff --git a/b.c b/b.c +--- /dev/null ++++ b/b.c +@@ -0,0 +4,9 @@ ++long f(long x) ++{ ++ int s = 0; ++ while (x) { ++ x >>= 1; ++ s++; ++ } ++ return s; ++}
t/t4211/expect.simple-f new file +59 -0
59 lines not on this page · raw message
t/t4211/expect.simple-main new file +68 -0
68 lines not on this page · raw message
t/t4211/expect.two-ranges new file +102 -0
102 lines not on this page · raw message
t/t4211/expect.vanishes-early new file +39 -0
@@ -0,0 +1,39 @@ +commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83 +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:43 2013 +0100 + + change back to complete line + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +24,1 @@ +-} +\ No newline at end of file ++/* incomplete lines are bad! */ + +commit 100b61a6f2f720f812620a9d10afb3a960ccb73c +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:48:10 2013 +0100 + + change to an incomplete line at end + +diff --git a/a.c b/a.c +--- a/a.c ++++ b/a.c +@@ -22,1 +22,1 @@ +-} ++} +\ No newline at end of file + +commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a +Author: Thomas Rast <[email protected]> +Date: Thu Feb 28 10:44:48 2013 +0100 + + initial + +diff --git a/a.c b/a.c +--- /dev/null ++++ b/a.c +@@ -0,0 +20,1 @@ ++}
t/t4211/history.export new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v10 4/5 log -L: :pattern:file syntax to find by funcname
In reply to Thomas RastThis new syntax finds a funcname matching /pattern/, and then takes from there up to (but not including) the next funcname. So you can say
git log -L:main:main.c
and it will dig up the main() function and show its line-log, provided there are no other funcnames matching 'main'.
--- Documentation/blame-options.txt | 2 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 11 +-- Documentation/line-range-format.txt | 7 ++ builtin/blame.c | 2 +- line-log.c | 5 +- line-range.c | 136 +++++++++++++++++++++++++++++++++++- line-range.h | 3 +- t/t4211-line-log.sh | 4 ++ t/t4211/expect.simple-f-to-main | 100 ++++++++++++++++++++++++++ t/t4211/expect.simple-main-to-end | 70 +++++++++++++++++++ 11 files changed, 332 insertions(+), 14 deletions(-) create mode 100644 t/t4211/expect.simple-f-to-main create mode 100644 t/t4211/expect.simple-main-to-end
Documentation/blame-options.txt +1 -1
@@ -9,7 +9,7 @@ --show-stats:: Include additional statistics at the end of blame output. --L <start>,<end>:: +-L <start>,<end>, -L :<regex>:: Annotate only the given line range. <start> and <end> can take one of these forms:
Documentation/git-blame.txt +3 -3
@@ -8,9 +8,9 @@ git-blame - Show what revision and author last modified each line of a file SYNOPSIS -------- [verse] -'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m] - [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [--abbrev=<n>] - [<rev> | --contents <file> | --reverse <rev>] [--] <file> +'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] + [-L n,m | -L :fn] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] + [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>] [--] <file> DESCRIPTION -----------
Documentation/git-log.txt +6 -5
@@ -69,12 +69,13 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. --L <start>,<end>:<file>:: +-L <start>,<end>:<file>, -L :<regex>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" - within the <file>. 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. + (or the funcname regex <regex>) within the <file>. 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. <start> and <end> can take one of these forms:
Documentation/line-range-format.txt +7 -0
@@ -16,3 +16,10 @@ starting at the line given by <start>. This is only valid for <end> and will specify a number of lines before or after the line given by <start>. + + +- :regex ++ +If the option's argument is of the form :regex, it denotes the range +from the first funcname line that matches <regex>, up to the next +funcname line. ++
builtin/blame.c +1 -1
@@ -1940,7 +1940,7 @@ static void prepare_blame_range(struct scoreboard *sb,long lno, long *bottom, long *top) { - if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top)) + if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top, sb->path)) usage(blame_usage); }
line-log.c +3 -2
@@ -12,6 +12,7 @@#include "strbuf.h" #include "log-tree.h" #include "graph.h" +#include "userdiff.h" #include "line-log.h" static void range_set_grow (struct range_set *rs,size_t extra)
@@ -438,7 +439,6 @@ static void range_set_map_across_diff(struct range_set *out, *touched_out = touched; } -static struct commit *check_single_commit (struct rev_info *revs) {struct object *commit =NULL ;
@@ -559,7 +559,8 @@ static const char *nth_line(void *data, long line) cb_data.line_ends = ends;if (parse_range_arg (range_part, nth_line, &cb_data, - lines, &begin, &end)) + lines, &begin, &end, + spec->path))die ("malformed -L argument '%s'" , range_part);if (begin <1 ) begin =1 ;
line-range.c +135 -1
155 lines not on this page · raw message
line-range.h +2 -1
@@ -19,7 +19,8 @@extern int parse_range_arg (const char *arg,nth_line_fn_t nth_line_cb,void *cb_data,long lines, -long *begin,long *end); +long *begin,long *end, +const char *path);/* * Scan past a range argument that could be parsed by
t/t4211-line-log.sh +4 -0
@@ -25,8 +25,10 @@ test_bad_opts () { canned_test "-L 4,12:a.c simple" simple-f canned_test "-L 4,+9:a.c simple" simple-f canned_test "-L '/long f/,/^}/:a.c' simple" simple-f +canned_test "-L :f:a.c simple" simple-f-to-main canned_test "-L '/main/,/^}/:a.c' simple" simple-main +canned_test "-L :main:a.c simple" simple-main-to-end canned_test "-L 1,+4:a.c simple" beginning-of-file
@@ -45,5 +47,7 @@ test_bad_opts "-L 1:simple" "There is no path" test_bad_opts "-L '/foo:b.c'" "argument.*not of the form" test_bad_opts "-L 1000:b.c" "has only.*lines" test_bad_opts "-L 1,1000:b.c" "has only.*lines" +test_bad_opts "-L :b.c" "argument.*not of the form" +test_bad_opts "-L :foo:b.c" "no match" test_done
t/t4211/expect.simple-f-to-main new file +100 -0
100 lines not on this page · raw message
t/t4211/expect.simple-main-to-end new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v10 5/5 Speed up log -L... -M
In reply to Thomas RastSo far log -L only used the implicit diff filtering by pathspec. If the user specifies -M, we cannot do that, and so we simply handed the whole diff queue (which is approximately 'git show --raw') to diffcore_std().
Unfortunately this is very slow. We can optimize a lot if we throw out files that we know cannot possibly be interesting, in the same spirit that the pathspec filtering reduces the number of files.
However, in this case, we have to be more careful. Because we want to look out for renames, we need to keep all filepairs where something was deleted.
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it speeds up 'log -M -L' by an order of magnitude.
--- line-log.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-)
line-log.c +52 -4
@@ -750,7 +750,50 @@ static void move_diff_queue(struct diff_queue_struct *dst,DIFF_QUEUE_CLEAR (src); } -static void queue_diffs (struct diff_options *opt, +static void filter_diffs_for_paths (struct line_log_data *range,int keep_deletions) +{ +int i; +struct diff_queue_struct outq; +DIFF_QUEUE_CLEAR (&outq); + +for (i =0 ; i < diff_queued_diff.nr; i++) { +struct diff_filepair *p = diff_queued_diff.queue[i]; +struct line_log_data *rg =NULL ; + +if (!DIFF_FILE_VALID (p->two)) { +if (keep_deletions) +diff_q (&outq, p); +else +diff_free_filepair (p); +continue ; + } +for (rg = range; rg; rg = rg->next) { +if (!strcmp (rg->spec->path, p->two->path)) +break ; + } +if (rg) +diff_q (&outq, p); +else +diff_free_filepair (p); + } +free (diff_queued_diff.queue); + diff_queued_diff = outq; +} + +static inline int diff_might_be_rename (void ) +{ +int i; +for (i =0 ; i < diff_queued_diff.nr; i++) +if (!DIFF_FILE_VALID (diff_queued_diff.queue[i]->one)) { +/* fprintf(stderr, "diff_might_be_rename found creation of: %s\n", */ +/* diff_queued_diff.queue[i]->two->path); */ +return 1 ; + } +return 0 ; +} + +static void queue_diffs (struct line_log_data *range, +struct diff_options *opt,struct diff_queue_struct *queue,struct commit *commit,struct commit *parent) {
@@ -766,7 +809,12 @@ static void queue_diffs(struct diff_options *opt,DIFF_QUEUE_CLEAR (&diff_queued_diff);diff_tree (&desc1, &desc2,"" , opt); -diffcore_std (opt); +if (opt->detect_rename) { +filter_diffs_for_paths (range,1 ); +if (diff_might_be_rename ()) +diffcore_std (opt); +filter_diffs_for_paths (range,0 ); + }move_diff_queue (queue, &diff_queued_diff);if (tree1)
@@ -1050,7 +1098,7 @@ static int process_ranges_ordinary_commit(struct rev_info *rev, struct commit *cif (commit->parents) parent = commit->parents->item; -queue_diffs (&rev->diffopt, &queue, commit, parent); +queue_diffs (range, &rev->diffopt, &queue, commit, parent); changed =process_all_files (&parent_range, rev, &queue, range);if (parent)add_line_range (rev, parent, parent_range);
@@ -1075,7 +1123,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *commfor (i =0 ; i < nparents; i++) { parents[i] = p->item; p = p->next; -queue_diffs (&rev->diffopt, &diffqueues[i], commit, parents[i]); +queue_diffs (range, &rev->diffopt, &diffqueues[i], commit, parents[i]); }for (i =0 ; i < nparents; i++) {
Signature · 1 line
1.8.2.446.g2b4de83
PATCH v9 4/5 log -L: :pattern:file syntax to find by funcname
In reply to Thomas RastThis new syntax finds a funcname matching /pattern/, and then takes from there up to (but not including) the next funcname. So you can say
git log -L:main:main.c
and it will dig up the main() function and show its line-log, provided there are no other funcnames matching 'main'.
--- Documentation/blame-options.txt | 2 +- Documentation/git-blame.txt | 6 +- Documentation/git-log.txt | 11 +-- Documentation/line-range-format.txt | 7 ++ builtin/blame.c | 2 +- line-log.c | 5 +- line-range.c | 130 +++++++++++++++++++++++++++++++++++- line-range.h | 3 +- t/t4211-line-log.sh | 2 + t/t4211/expect.simple-f-to-main | 100 +++++++++++++++++++++++++++ t/t4211/expect.simple-main-to-end | 70 +++++++++++++++++++ 11 files changed, 324 insertions(+), 14 deletions(-) create mode 100644 t/t4211/expect.simple-f-to-main create mode 100644 t/t4211/expect.simple-main-to-end
Documentation/blame-options.txt +1 -1
@@ -9,7 +9,7 @@ --show-stats:: Include additional statistics at the end of blame output. --L <start>,<end>:: +-L <start>,<end>, -L :<regex>:: Annotate only the given line range. <start> and <end> can take one of these forms:
Documentation/git-blame.txt +3 -3
@@ -8,9 +8,9 @@ git-blame - Show what revision and author last modified each line of a file SYNOPSIS -------- [verse] -'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m] - [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [--abbrev=<n>] - [<rev> | --contents <file> | --reverse <rev>] [--] <file> +'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] + [-L n,m | -L :fn] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] + [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>] [--] <file> DESCRIPTION -----------
Documentation/git-log.txt +6 -5
@@ -69,12 +69,13 @@ produced by --stat etc. Note that only message is considered, if also a diff is shown its size is not included. --L <start>,<end>:<file>:: +-L <start>,<end>:<file>, -L :<regex>:<file>:: + Trace the evolution of the line range given by "<start>,<end>" - within the <file>. 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. + (or the funcname regex <regex>) within the <file>. 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. <start> and <end> can take one of these forms:
Documentation/line-range-format.txt +7 -0
@@ -16,3 +16,10 @@ starting at the line given by <start>. This is only valid for <end> and will specify a number of lines before or after the line given by <start>. + + +- :regex ++ +If the option's argument is of the form :regex, it denotes the range +from the first funcname line that matches <regex>, up to the next +funcname line. ++
builtin/blame.c +1 -1
@@ -1940,7 +1940,7 @@ static void prepare_blame_range(struct scoreboard *sb,long lno, long *bottom, long *top) { - if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top)) + if (parse_range_arg(bottomtop, nth_line_cb, sb, lno, bottom, top, sb->path)) usage(blame_usage); }
line-log.c +3 -2
@@ -12,6 +12,7 @@#include "strbuf.h" #include "log-tree.h" #include "graph.h" +#include "userdiff.h" #include "line-log.h" static void range_set_grow (struct range_set *rs,size_t extra)
@@ -438,7 +439,6 @@ static void range_set_map_across_diff(struct range_set *out, *touched_out = touched; } -static struct commit *check_single_commit (struct rev_info *revs) {struct object *commit =NULL ;
@@ -559,7 +559,8 @@ static const char *nth_line(void *data, long line) cb_data.line_ends = ends;if (parse_range_arg (range_part, nth_line, &cb_data, - lines, &begin, &end)) + lines, &begin, &end, + spec->path))die ("malformed -L argument '%s'" , range_part);if (begin <1 ) begin =1 ;
line-range.c +129 -1
149 lines not on this page · raw message
line-range.h +2 -1
@@ -19,7 +19,8 @@extern int parse_range_arg (const char *arg,nth_line_fn_t nth_line_cb,void *cb_data,long lines, -long *begin,long *end); +long *begin,long *end, +const char *path);/* * Scan past a range argument that could be parsed by
t/t4211-line-log.sh +2 -0
@@ -18,8 +18,10 @@ canned_test () { canned_test "-L 4,12:a.c simple" simple-f canned_test "-L 4,+9:a.c simple" simple-f canned_test "-L '/long f/,/^}/:a.c' simple" simple-f +canned_test "-L :f:a.c simple" simple-f-to-main canned_test "-L '/main/,/^}/:a.c' simple" simple-main +canned_test "-L :main:a.c simple" simple-main-to-end canned_test "-L 1,+4:a.c simple" beginning-of-file
t/t4211/expect.simple-f-to-main new file +100 -0
100 lines not on this page · raw message
t/t4211/expect.simple-main-to-end new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.8.2.235.g4032450
PATCH v9 5/5 Speed up log -L... -M
In reply to Thomas RastSo far log -L only used the implicit diff filtering by pathspec. If the user specifies -M, we cannot do that, and so we simply handed the whole diff queue (which is approximately 'git show --raw') to diffcore_std().
Unfortunately this is very slow. We can optimize a lot if we throw out files that we know cannot possibly be interesting, in the same spirit that the pathspec filtering reduces the number of files.
However, in this case, we have to be more careful. Because we want to look out for renames, we need to keep all filepairs where something was deleted.
This is a bit hacky and should really be replaced by equivalent support in --follow, and just using that. However, in the meantime it speeds up 'log -M -L' by an order of magnitude.
--- line-log.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-)
line-log.c +52 -4
@@ -750,7 +750,50 @@ static void move_diff_queue(struct diff_queue_struct *dst,DIFF_QUEUE_CLEAR (src); } -static void queue_diffs (struct diff_options *opt, +static void filter_diffs_for_paths (struct line_log_data *range,int keep_deletions) +{ +int i; +struct diff_queue_struct outq; +DIFF_QUEUE_CLEAR (&outq); + +for (i =0 ; i < diff_queued_diff.nr; i++) { +struct diff_filepair *p = diff_queued_diff.queue[i]; +struct line_log_data *rg =NULL ; + +if (!DIFF_FILE_VALID (p->two)) { +if (keep_deletions) +diff_q (&outq, p); +else +diff_free_filepair (p); +continue ; + } +for (rg = range; rg; rg = rg->next) { +if (!strcmp (rg->spec->path, p->two->path)) +break ; + } +if (rg) +diff_q (&outq, p); +else +diff_free_filepair (p); + } +free (diff_queued_diff.queue); + diff_queued_diff = outq; +} + +static inline int diff_might_be_rename (void ) +{ +int i; +for (i =0 ; i < diff_queued_diff.nr; i++) +if (!DIFF_FILE_VALID (diff_queued_diff.queue[i]->one)) { +/* fprintf(stderr, "diff_might_be_rename found creation of: %s\n", */ +/* diff_queued_diff.queue[i]->two->path); */ +return 1 ; + } +return 0 ; +} + +static void queue_diffs (struct line_log_data *range, +struct diff_options *opt,struct diff_queue_struct *queue,struct commit *commit,struct commit *parent) {
@@ -766,7 +809,12 @@ static void queue_diffs(struct diff_options *opt,DIFF_QUEUE_CLEAR (&diff_queued_diff);diff_tree (&desc1, &desc2,"" , opt); -diffcore_std (opt); +if (opt->detect_rename) { +filter_diffs_for_paths (range,1 ); +if (diff_might_be_rename ()) +diffcore_std (opt); +filter_diffs_for_paths (range,0 ); + }move_diff_queue (queue, &diff_queued_diff);if (tree1)
@@ -1050,7 +1098,7 @@ static int process_ranges_ordinary_commit(struct rev_info *rev, struct commit *cif (commit->parents) parent = commit->parents->item; -queue_diffs (&rev->diffopt, &queue, commit, parent); +queue_diffs (range, &rev->diffopt, &queue, commit, parent); changed =process_all_files (&parent_range, rev, &queue, range);if (parent)add_line_range (rev, parent, parent_range);
@@ -1075,7 +1123,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *commfor (i =0 ; i < nparents; i++) { parents[i] = p->item; p = p->next; -queue_diffs (&rev->diffopt, &diffqueues[i], commit, parents[i]); +queue_diffs (range, &rev->diffopt, &diffqueues[i], commit, parents[i]); }for (i =0 ; i < nparents; i++) {
Signature · 1 line
1.8.2.235.g4032450