summaryrefslogtreecommitdiff
path: root/line-range.c
diff options
context:
space:
mode:
authorThomas Rast <trast@student.ethz.ch>2013-03-28 17:47:32 +0100
committerJunio C Hamano <gitster@pobox.com>2013-03-28 10:29:22 -0700
commit12da1d1f6ffcd546a892a33302bb34fd37169022 (patch)
treea70c5244b7b27d77c9c58d48a4e88215a956d731 /line-range.c
parentc7edcae06ed90ec0567179a78d7d1170e610c042 (diff)
downloadgit-12da1d1f6ffcd546a892a33302bb34fd37169022.tar.gz
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 <jnareb@gmail.com> Jens Lehmann <Jens.Lehmann@web.de> Jonathan Nieder <jrnieder@gmail.com> Junio C Hamano <gitster@pobox.com> Ramsay Jones <ramsay@ramsay1.demon.co.uk> Will Palmer <wmpalmer@gmail.com> Apologies to everyone I forgot. Signed-off-by: Bo Yang <struggleyb.nku@gmail.com> Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'line-range.c')
-rw-r--r--line-range.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/line-range.c b/line-range.c
index 5a226abdd0..7a7ca3c2bd 100644
--- a/line-range.c
+++ b/line-range.c
@@ -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;
+}