diff options
author | Thomas Rast <trast@student.ethz.ch> | 2013-03-28 17:47:32 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-28 10:29:22 -0700 |
commit | 12da1d1f6ffcd546a892a33302bb34fd37169022 (patch) | |
tree | a70c5244b7b27d77c9c58d48a4e88215a956d731 /line-log.h | |
parent | c7edcae06ed90ec0567179a78d7d1170e610c042 (diff) | |
download | git-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-log.h')
-rw-r--r-- | line-log.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/line-log.h b/line-log.h new file mode 100644 index 0000000000..9acd12361a --- /dev/null +++ b/line-log.h @@ -0,0 +1,49 @@ +#ifndef LINE_LOG_H +#define LINE_LOG_H + +#include "diffcore.h" + +struct rev_info; +struct commit; + +/* A range [start,end]. Lines are numbered starting at 0, and the + * ranges include start but exclude end. */ +struct range { + long start, end; +}; + +/* A set of ranges. The ranges must always be disjoint and sorted. */ +struct range_set { + int alloc, nr; + struct range *ranges; +}; + +/* A diff, encoded as the set of pre- and post-image ranges where the + * files differ. A pair of ranges corresponds to a hunk. */ +struct diff_ranges { + struct range_set parent; + struct range_set target; +}; + +/* Linked list of interesting files and their associated ranges. The + * list must be kept sorted by spec->path */ +struct line_log_data { + struct line_log_data *next; + struct diff_filespec *spec; + char status; + struct range_set ranges; + int arg_alloc, arg_nr; + const char **args; + struct diff_filepair *pair; + struct diff_ranges diff; +}; + +extern void line_log_data_init(struct line_log_data *r); + +extern void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args); + +extern int line_log_filter(struct rev_info *rev); + +extern int line_log_print(struct rev_info *rev, struct commit *commit); + +#endif /* LINE_LOG_H */ |