git-pickaxe: re-scan the blob after making progress with -C
The reason to do this is the same as in the previous change for line copy detection within the same file (-M). Also this fixes -C and -C -C (aka find-copies-harder) logic; in this application we are not interested in the similarity matching diffcore-rename makes, because we are only interested in scanning files that were modified, or in the case of -C -C, scanning all files in the parent and we want to do that ourselves. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 4, 2006 at 16:39 UTC
334947843cbd50895f1dc58d8bd2f217e1f1ef77
1 file changed
+103
-62
builtin-pickaxe.c
+103
-62
@@ -803,6 +803,36 @@ static int find_move_in_parent(struct scoreboard *sb,
803
return 0;
804
}
805
806
+
807
+struct blame_list {
808
+ struct blame_entry *ent;
809
+ struct blame_entry split[3];
810
+};
811
+
812
+static struct blame_list *setup_blame_list(struct scoreboard *sb,
813
+ struct origin *target,
814
+ int *num_ents_p)
815
+{
816
+ struct blame_entry *e;
817
+ int num_ents, i;
818
+ struct blame_list *blame_list = NULL;
819
+
820
+ /* Count the number of entries the target is suspected for,
821
+ * and prepare a list of entry and the best split.
822
+ */
823
+ for (e = sb->ent, num_ents = 0; e; e = e->next)
824
+ if (!e->guilty && !cmp_suspect(e->suspect, target))
825
+ num_ents++;
826
+ if (num_ents) {
827
+ blame_list = xcalloc(num_ents, sizeof(struct blame_list));
828
+ for (e = sb->ent, i = 0; e; e = e->next)
829
+ if (!e->guilty && !cmp_suspect(e->suspect, target))
830
+ blame_list[i++].ent = e;
831
+ }
832
+ *num_ents_p = num_ents;
833
+ return blame_list;
834
+}
835
+
836
static int find_copy_in_parent(struct scoreboard *sb,
837
struct origin *target,
838
struct commit *parent,
@@ -811,91 +841,101 @@ static int find_copy_in_parent(struct scoreboard *sb,
841
{
842
struct diff_options diff_opts;
843
const char *paths[1];
814
- struct blame_entry *e;
844
int i, j;
816
- struct blame_list {
817
- struct blame_entry *ent;
818
- struct blame_entry split[3];
819
- } *blame_list;
845
+ int retval;
846
+ struct blame_list *blame_list;
847
int num_ents;
848
822
- /* Count the number of entries the target is suspected for,
823
- * and prepare a list of entry and the best split.
824
- */
825
- for (e = sb->ent, num_ents = 0; e; e = e->next)
826
- if (!e->guilty && !cmp_suspect(e->suspect, target))
827
- num_ents++;
828
- if (!num_ents)
849
+ blame_list = setup_blame_list(sb, target, &num_ents);
850
+ if (!blame_list)
851
return 1; /* nothing remains for this target */
852
831
- blame_list = xcalloc(num_ents, sizeof(struct blame_list));
832
- for (e = sb->ent, i = 0; e; e = e->next)
833
- if (!e->guilty && !cmp_suspect(e->suspect, target))
834
- blame_list[i++].ent = e;
835
-
853
diff_setup(&diff_opts);
854
diff_opts.recursive = 1;
855
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
856
840
- /* Try "find copies harder" on new path */
841
- if ((opt & PICKAXE_BLAME_COPY_HARDER) &&
842
- (!porigin || strcmp(target->path, porigin->path))) {
843
- diff_opts.detect_rename = DIFF_DETECT_COPY;
844
- diff_opts.find_copies_harder = 1;
845
- }
857
paths[0] = NULL;
858
diff_tree_setup_paths(paths, &diff_opts);
859
if (diff_setup_done(&diff_opts) < 0)
860
die("diff-setup");
861
+
862
+ /* Try "find copies harder" on new path if requested;
863
+ * we do not want to use diffcore_rename() actually to
864
+ * match things up; find_copies_harder is set only to
865
+ * force diff_tree_sha1() to feed all filepairs to diff_queue,
866
+ * and this code needs to be after diff_setup_done(), which
867
+ * usually makes find-copies-harder imply copy detection.
868
+ */
869
+ if ((opt & PICKAXE_BLAME_COPY_HARDER) &&
870
+ (!porigin || strcmp(target->path, porigin->path)))
871
+ diff_opts.find_copies_harder = 1;
872
+
873
diff_tree_sha1(parent->tree->object.sha1,
874
target->commit->tree->object.sha1,
875
"", &diff_opts);
853
- diffcore_std(&diff_opts);
876
855
- for (i = 0; i < diff_queued_diff.nr; i++) {
856
- struct diff_filepair *p = diff_queued_diff.queue[i];
857
- struct origin *norigin;
858
- mmfile_t file_p;
859
- char type[10];
860
- char *blob;
861
- struct blame_entry this[3];
862
-
863
- if (!DIFF_FILE_VALID(p->one))
864
- continue; /* does not exist in parent */
865
- if (porigin && !strcmp(p->one->path, porigin->path))
866
- /* find_move already dealt with this path */
867
- continue;
877
+ if (!diff_opts.find_copies_harder)
878
+ diffcore_std(&diff_opts);
879
869
- norigin = get_origin(sb, parent, p->one->path);
870
- hashcpy(norigin->blob_sha1, p->one->sha1);
871
- blob = read_sha1_file(norigin->blob_sha1, type,
872
- (unsigned long *) &file_p.size);
873
- file_p.ptr = blob;
874
- if (!file_p.ptr)
875
- continue;
880
+ retval = 0;
881
+ while (1) {
882
+ int made_progress = 0;
883
+
884
+ for (i = 0; i < diff_queued_diff.nr; i++) {
885
+ struct diff_filepair *p = diff_queued_diff.queue[i];
886
+ struct origin *norigin;
887
+ mmfile_t file_p;
888
+ char type[10];
889
+ char *blob;
890
+ struct blame_entry this[3];
891
+
892
+ if (!DIFF_FILE_VALID(p->one))
893
+ continue; /* does not exist in parent */
894
+ if (porigin && !strcmp(p->one->path, porigin->path))
895
+ /* find_move already dealt with this path */
896
+ continue;
897
+
898
+ norigin = get_origin(sb, parent, p->one->path);
899
+ hashcpy(norigin->blob_sha1, p->one->sha1);
900
+ blob = read_sha1_file(norigin->blob_sha1, type,
901
+ (unsigned long *) &file_p.size);
902
+ file_p.ptr = blob;
903
+ if (!file_p.ptr)
904
+ continue;
905
+
906
+ for (j = 0; j < num_ents; j++) {
907
+ find_copy_in_blob(sb, blame_list[j].ent,
908
+ norigin, this, &file_p);
909
+ copy_split_if_better(sb, blame_list[j].split,
910
+ this);
911
+ decref_split(this);
912
+ }
913
+ free(blob);
914
+ origin_decref(norigin);
915
+ }
916
917
for (j = 0; j < num_ents; j++) {
878
- find_copy_in_blob(sb, blame_list[j].ent, norigin,
879
- this, &file_p);
880
- copy_split_if_better(sb, blame_list[j].split,
881
- this);
882
- decref_split(this);
918
+ struct blame_entry *split = blame_list[j].split;
919
+ if (split[1].suspect &&
920
+ blame_copy_score < ent_score(sb, &split[1])) {
921
+ split_blame(sb, split, blame_list[j].ent);
922
+ made_progress = 1;
923
+ }
924
+ decref_split(split);
925
}
884
- free(blob);
885
- origin_decref(norigin);
886
- }
887
- diff_flush(&diff_opts);
926
+ free(blame_list);
927
889
- for (j = 0; j < num_ents; j++) {
890
- struct blame_entry *split = blame_list[j].split;
891
- if (split[1].suspect &&
892
- blame_copy_score < ent_score(sb, &split[1]))
893
- split_blame(sb, split, blame_list[j].ent);
894
- decref_split(split);
928
+ if (!made_progress)
929
+ break;
930
+ blame_list = setup_blame_list(sb, target, &num_ents);
931
+ if (!blame_list) {
932
+ retval = 1;
933
+ break;
934
+ }
935
}
896
- free(blame_list);
936
+ diff_flush(&diff_opts);
937
898
- return 0;
938
+ return retval;
939
}
940
941
#define MAXPARENT 16
@@ -942,7 +982,8 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
982
goto finish;
983
}
984
for (j = same = 0; j < i; j++)
945
- if (!hashcmp(parent_origin[j]->blob_sha1,
985
+ if (parent_origin[j] &&
986
+ !hashcmp(parent_origin[j]->blob_sha1,
987
porigin->blob_sha1)) {
988
same = 1;
989
break;