From 25ed3412f86b136efb17689b6712d9e546cac388 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Thu, 28 Mar 2013 17:47:30 +0100 Subject: Refactor parse_loc 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. Signed-off-by: Bo Yang Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/blame-options.txt | 19 +------------------ Documentation/line-range-format.txt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 Documentation/line-range-format.txt (limited to 'Documentation') diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index b0d31df0e..6998d9f5b 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -13,24 +13,7 @@ Annotate only the given line range. and can take one of these forms: - - number -+ -If or 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 is a regex, it will search -starting at the line given by . -+ - -- +offset or -offset -+ -This is only valid for and will specify a number -of lines before or after the line given by . -+ +include::line-range-format.txt[] -l:: Show long rev (Default: off). diff --git a/Documentation/line-range-format.txt b/Documentation/line-range-format.txt new file mode 100644 index 000000000..265bc2329 --- /dev/null +++ b/Documentation/line-range-format.txt @@ -0,0 +1,18 @@ +- number ++ +If or 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 is a regex, it will search +starting at the line given by . ++ + +- +offset or -offset ++ +This is only valid for and will specify a number +of lines before or after the line given by . ++ -- cgit v1.2.1 From 12da1d1f6ffcd546a892a33302bb34fd37169022 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Thu, 28 Mar 2013 17:47:32 +0100 Subject: Implement line-history search (git log -L) This 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 Jens Lehmann Jonathan Nieder Junio C Hamano Ramsay Jones Will Palmer Apologies to everyone I forgot. Signed-off-by: Bo Yang Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Documentation') diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 69db5783c..8727c60ab 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -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 ,::: + Trace the evolution of the line range given by "," + within the . You may not give any pathspec limiters. + This is currently limited to a walk starting from a single + revision, i.e., you may only give zero or one positive + revision arguments. + + and 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. + [\--] ...:: 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. -- cgit v1.2.1 From 13b8f68c1f0b6d4ff5a7bed5a834e7e5e34a9fd0 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Thu, 28 Mar 2013 17:47:33 +0100 Subject: log -L: :pattern:file syntax to find by funcname This 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'. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/blame-options.txt | 2 +- Documentation/git-blame.txt | 6 +++--- Documentation/git-log.txt | 11 ++++++----- Documentation/line-range-format.txt | 7 +++++++ 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'Documentation') diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index 6998d9f5b..e9f984ba0 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -9,7 +9,7 @@ --show-stats:: Include additional statistics at the end of blame output. --L ,:: +-L ,, -L ::: Annotate only the given line range. and can take one of these forms: diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt index 9a05c2b3d..6cea7f1ce 100644 --- a/Documentation/git-blame.txt +++ b/Documentation/git-blame.txt @@ -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 ] [-M] [-C] [-C] [-C] [--since=] [--abbrev=] - [ | --contents | --reverse ] [--] +'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] + [-L n,m | -L :fn] [-S ] [-M] [-C] [-C] [-C] [--since=] + [--abbrev=] [ | --contents | --reverse ] [--] DESCRIPTION ----------- diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 8727c60ab..4850226aa 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -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 ,::: +-L ,:, -L :::: + Trace the evolution of the line range given by "," - within the . You may not give any pathspec limiters. - This is currently limited to a walk starting from a single - revision, i.e., you may only give zero or one positive - revision arguments. + (or the funcname regex ) within the . You may + not give any pathspec limiters. This is currently limited to + a walk starting from a single revision, i.e., you may only + give zero or one positive revision arguments. and can take one of these forms: diff --git a/Documentation/line-range-format.txt b/Documentation/line-range-format.txt index 265bc2329..3e7ce72da 100644 --- a/Documentation/line-range-format.txt +++ b/Documentation/line-range-format.txt @@ -16,3 +16,10 @@ starting at the line given by . This is only valid for and will specify a number of lines before or after the line given by . + + +- :regex ++ +If the option's argument is of the form :regex, it denotes the range +from the first funcname line that matches , up to the next +funcname line. ++ -- cgit v1.2.1 From 0f483436e9c2e03bbb80c1dc215d4d7bf8774282 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 21 Apr 2013 19:40:49 -0700 Subject: line-log: fix documentation formatting The second paragraph of the added description for the -L option " and can take one of these forms:", and the list of forms that follow the headline, were indented one level too short, due to the missing "+" to signal that the next paragraph continues the previous one. Also "You can specify this option more than once" is about the -L option, not about its various forms of starting and ending points. Move it to the end of the main text. Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Documentation') diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 4850226aa..0959f9d60 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -76,12 +76,11 @@ produced by --stat etc. 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. - + You can specify this option more than once. ++ and 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 -- cgit v1.2.1 From 499926670665570d785bc7baca4d7cd4420823dc Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 22 Apr 2013 11:36:22 +0200 Subject: git-log(1): remove --full-line-diff description This option is a remnant of an earlier log -L version, and not currently implemented. Remove it until (if at all) it is implemented again. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Documentation') diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 0959f9d60..65707ce13 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -82,10 +82,6 @@ produced by --stat etc. include::line-range-format.txt[] ---full-line-diff:: - Always print the interesting range even if the current commit - does not change any line of the range. - [\--] ...:: Show only commits that are enough to explain how the files that match the specified paths came to be. See "History -- cgit v1.2.1