git-pickaxe: do not confuse two origins that are the same.
It used to be that we can compare the address of the origin structure to determine if they are the same because they are always registered with scoreboard. After introduction of the loop to try finding the best split, that is not true anymore. The current code has rather serious leaks with origin structure, but more importantly it gets confused when two origins that points at the same commit and same path. We might eventually have to refcount and gc origin, but let's fix the correctness issue first. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 21, 2006 at 00:41 UTC
46014766bdacec8ad22355ce78898b895bf172d6
1 file changed
+25
-20
builtin-pickaxe.c
+25
-20
@@ -113,12 +113,20 @@ struct scoreboard {
113
int *lineno;
114
};
115
116
+static int cmp_suspect(struct origin *a, struct origin *b)
117
+{
118
+ int cmp = hashcmp(a->commit->object.sha1, b->commit->object.sha1);
119
+ if (cmp)
120
+ return cmp;
121
+ return strcmp(a->path, b->path);
122
+}
123
+
124
static void coalesce(struct scoreboard *sb)
125
{
126
struct blame_entry *ent, *next;
127
128
for (ent = sb->ent; ent && (next = ent->next); ent = next) {
121
- if (ent->suspect == next->suspect &&
129
+ if (!cmp_suspect(ent->suspect, next->suspect) &&
130
ent->guilty == next->guilty &&
131
ent->s_lno + ent->num_lines == next->s_lno) {
132
ent->num_lines += next->num_lines;
@@ -126,6 +134,7 @@ static void coalesce(struct scoreboard *sb)
134
if (ent->next)
135
ent->next->prev = ent;
136
free(next);
137
+ ent->score = 0;
138
next = ent; /* again */
139
}
140
}
@@ -498,7 +507,7 @@ static int find_last_in_target(struct scoreboard *sb, struct origin *target)
507
int last_in_target = -1;
508
509
for (e = sb->ent; e; e = e->next) {
501
- if (e->guilty || e->suspect != target)
510
+ if (e->guilty || cmp_suspect(e->suspect, target))
511
continue;
512
if (last_in_target < e->s_lno + e->num_lines)
513
last_in_target = e->s_lno + e->num_lines;
@@ -513,7 +522,7 @@ static void blame_chunk(struct scoreboard *sb,
522
struct blame_entry *e;
523
524
for (e = sb->ent; e; e = e->next) {
516
- if (e->guilty || e->suspect != target)
525
+ if (e->guilty || cmp_suspect(e->suspect, target))
526
continue;
527
if (same <= e->s_lno)
528
continue;
@@ -634,7 +643,7 @@ static int find_move_in_parent(struct scoreboard *sb,
643
struct origin *parent)
644
{
645
int last_in_target;
637
- struct blame_entry *ent, split[3];
646
+ struct blame_entry *e, split[3];
647
mmfile_t file_p;
648
char type[10];
649
char *blob_p;
@@ -651,13 +660,13 @@ static int find_move_in_parent(struct scoreboard *sb,
660
return 0;
661
}
662
654
- for (ent = sb->ent; ent; ent = ent->next) {
655
- if (ent->suspect != target || ent->guilty)
663
+ for (e = sb->ent; e; e = e->next) {
664
+ if (e->guilty || cmp_suspect(e->suspect, target))
665
continue;
657
- find_copy_in_blob(sb, ent, parent, split, &file_p);
666
+ find_copy_in_blob(sb, e, parent, split, &file_p);
667
if (split[1].suspect &&
668
blame_move_score < ent_score(sb, &split[1]))
660
- split_blame(sb, split, ent);
669
+ split_blame(sb, split, e);
670
}
671
free(blob_p);
672
return 0;
@@ -671,7 +680,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
680
{
681
struct diff_options diff_opts;
682
const char *paths[1];
674
- struct blame_entry *ent;
683
+ struct blame_entry *e;
684
int i;
685
686
if (find_last_in_target(sb, target) < 0)
@@ -696,9 +705,9 @@ static int find_copy_in_parent(struct scoreboard *sb,
705
"", &diff_opts);
706
diffcore_std(&diff_opts);
707
699
- for (ent = sb->ent; ent; ent = ent->next) {
708
+ for (e = sb->ent; e; e = e->next) {
709
struct blame_entry split[3];
701
- if (ent->suspect != target || ent->guilty)
710
+ if (e->guilty || cmp_suspect(e->suspect, target))
711
continue;
712
713
memset(split, 0, sizeof(split));
@@ -724,12 +733,12 @@ static int find_copy_in_parent(struct scoreboard *sb,
733
free(blob);
734
continue;
735
}
727
- find_copy_in_blob(sb, ent, norigin, this, &file_p);
736
+ find_copy_in_blob(sb, e, norigin, this, &file_p);
737
copy_split_if_better(sb, split, this);
738
}
739
if (split[1].suspect &&
740
blame_copy_score < ent_score(sb, &split[1]))
732
- split_blame(sb, split, ent);
741
+ split_blame(sb, split, e);
742
}
743
diff_flush(&diff_opts);
744
@@ -763,12 +772,6 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
772
for (e = sb->ent; e; e = e->next)
773
if (e->suspect == origin)
774
e->suspect = porigin;
766
- /* now everything blamed for origin is blamed for
767
- * porigin, we do not need to keep it anymore.
768
- * Do not free porigin (or the ones we got from
769
- * earlier round); they may still be used elsewhere.
770
- */
771
- free_origin(origin);
775
return;
776
}
777
parent_origin[i] = porigin;
@@ -834,8 +837,10 @@ static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
837
838
/* Take responsibility for the remaining entries */
839
for (ent = sb->ent; ent; ent = ent->next)
837
- if (ent->suspect == suspect)
840
+ if (!cmp_suspect(ent->suspect, suspect))
841
ent->guilty = 1;
842
+
843
+ coalesce(sb);
844
}
845
}
846