1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 14:57:52 +01:00
git/line-log.h
Thomas Rast 31c6191831 log -L: store the path instead of a diff_filespec
line_log_data has held a diff_filespec* since the very early versions
of the code.  However, the only place in the code where we actually
need the full filespec is parse_range_arg(); in all other cases, we
are only interested in the path, so there is hardly a reason to store
a filespec.  Even worse, it causes a lot of redundant ->spec->path
pointer dereferencing.

And *even* worse, it caused the following bug.  If you merge a rename
with a modification to the old filename, like so:

  * Merge
  | \
  |  * Modify foo
  |  |
  *  | Rename foo->bar
  | /
  * Create foo

we internally -- in process_ranges_merge_commit() -- scan all parents.
We are mainly looking for one that doesn't have any modifications, so
that we can assign all the blame to it and simplify away the merge.
In doing so, we run the normal machinery on all parents in a loop.
For each parent, we prepare a "working set" line_log_data by making a
copy with line_log_data_copy(), which does *not* make a copy of the
spec.

Now suppose the rename is the first parent.  The diff machinery tells
us that the filepair is ('foo', 'bar').  We duly update the path we
are interested in:

  rg->spec->path = xstrdup(pair->one->path);

But that 'struct spec' is shared between the output line_log_data and
the original input line_log_data.  So we just wrecked the state of
process_ranges_merge_commit().  When we get around to the second
parent, the ranges tell us we are interested in a file 'foo' while the
commits touch 'bar'.

So most of this patch is just s/->spec->path/->path/ and associated
management changes.  This implicitly fixes the bug because we removed
the shared parts between input and output of line_log_data_copy(); it
is now safe to overwrite the path in the copy.

There's one only somewhat related change: the comment in
process_all_files() explains the reasoning behind using 'range' there.
That bit of half-correct code had me sidetracked for a while.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-12 11:37:03 -07:00

53 lines
1.3 KiB
C

#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 path.
*
* For simplicity, even though this is highly redundant, each
* line_log_data owns its 'path'.
*/
struct line_log_data {
struct line_log_data *next;
char *path;
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 */