path: root/line-log.h
diff options
authorThomas Rast <>2013-03-28 16:47:32 (GMT)
committerJunio C Hamano <>2013-03-28 17:29:22 (GMT)
commit12da1d1f6ffcd546a892a33302bb34fd37169022 (patch)
treea70c5244b7b27d77c9c58d48a4e88215a956d731 /line-log.h
parentc7edcae06ed90ec0567179a78d7d1170e610c042 (diff)
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 <>
Diffstat (limited to 'line-log.h')
1 files changed, 49 insertions, 0 deletions
diff --git a/line-log.h b/line-log.h
new file mode 100644
index 0000000..9acd123
--- /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 */