git-pickaxe: split find_origin() into find_rename() and find_origin().
When a merge adds a new file from the second parent, the earlier code tried to find renames in the first parent before noticing that the vertion from the second parent was added without modification. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 30, 2006 at 17:17 UTC
f69e743d97cdb3f6647ea0620a22311e7bf36051
1 file changed
+43
-25
builtin-pickaxe.c
+43
-25
@@ -211,7 +211,6 @@ static struct origin *find_origin(struct scoreboard *sb,
211
{
212
struct origin *porigin = NULL;
213
struct diff_options diff_opts;
214
- int i;
214
const char *paths[2];
215
216
/* See if the origin->path is different between parent
@@ -260,10 +259,17 @@ static struct origin *find_origin(struct scoreboard *sb,
259
}
260
}
261
diff_flush(&diff_opts);
263
- if (porigin)
264
- return porigin;
262
+ return porigin;
263
+}
264
266
- /* Otherwise we would look for a rename */
265
+static struct origin *find_rename(struct scoreboard *sb,
266
+ struct commit *parent,
267
+ struct origin *origin)
268
+{
269
+ struct origin *porigin = NULL;
270
+ struct diff_options diff_opts;
271
+ int i;
272
+ const char *paths[2];
273
274
diff_setup(&diff_opts);
275
diff_opts.recursive = 1;
@@ -875,34 +881,46 @@ static int find_copy_in_parent(struct scoreboard *sb,
881
882
static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
883
{
878
- int i;
884
+ int i, pass;
885
struct commit *commit = origin->commit;
886
struct commit_list *parent;
887
struct origin *parent_origin[MAXPARENT], *porigin;
888
889
memset(parent_origin, 0, sizeof(parent_origin));
884
- for (i = 0, parent = commit->parents;
885
- i < MAXPARENT && parent;
886
- parent = parent->next, i++) {
887
- struct commit *p = parent->item;
890
889
- if (parse_commit(p))
890
- continue;
891
- porigin = find_origin(sb, parent->item, origin);
892
- if (!porigin)
893
- continue;
894
- if (!hashcmp(porigin->blob_sha1, origin->blob_sha1)) {
895
- struct blame_entry *e;
896
- for (e = sb->ent; e; e = e->next)
897
- if (e->suspect == origin) {
898
- origin_incref(porigin);
899
- origin_decref(e->suspect);
900
- e->suspect = porigin;
901
- }
902
- origin_decref(porigin);
903
- goto finish;
891
+ /* The first pass looks for unrenamed path to optimize for
892
+ * common cases, then we look for renames in the second pass.
893
+ */
894
+ for (pass = 0; pass < 2; pass++) {
895
+ struct origin *(*find)(struct scoreboard *,
896
+ struct commit *, struct origin *);
897
+ find = pass ? find_rename : find_origin;
898
+
899
+ for (i = 0, parent = commit->parents;
900
+ i < MAXPARENT && parent;
901
+ parent = parent->next, i++) {
902
+ struct commit *p = parent->item;
903
+
904
+ if (parent_origin[i])
905
+ continue;
906
+ if (parse_commit(p))
907
+ continue;
908
+ porigin = find(sb, parent->item, origin);
909
+ if (!porigin)
910
+ continue;
911
+ if (!hashcmp(porigin->blob_sha1, origin->blob_sha1)) {
912
+ struct blame_entry *e;
913
+ for (e = sb->ent; e; e = e->next)
914
+ if (e->suspect == origin) {
915
+ origin_incref(porigin);
916
+ origin_decref(e->suspect);
917
+ e->suspect = porigin;
918
+ }
919
+ origin_decref(porigin);
920
+ goto finish;
921
+ }
922
+ parent_origin[i] = porigin;
923
}
905
- parent_origin[i] = porigin;
924
}
925
926
for (i = 0, parent = commit->parents;