diff-files -c/--cc: combine only when both ours and theirs exist.
The previous round forgot to make sure there actually are two versions to compare against the working tree version. Otherwise using -c/--cc would not make much sense. Also plug a small memory leak. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 28, 2006 at 02:09 UTC
939aabbf7d108b5d6830bf5cd89abc910cc9ff27
1 file changed
+7
-2
diff-files.c
+7
-2
@@ -121,6 +121,7 @@ int main(int argc, const char **argv)
121
struct combine_diff_path p;
122
unsigned char fill[4][20];
123
} combine;
124
+ int num_compare_stages = 0;
125
126
combine.p.next = NULL;
127
combine.p.len = ce_namelen(ce);
@@ -140,9 +141,11 @@ int main(int argc, const char **argv)
141
* stage #3 (theirs) is the second.
142
*/
143
stage = ce_stage(nce);
143
- if (2 <= stage)
144
+ if (2 <= stage) {
145
+ num_compare_stages++;
146
memcpy(combine.p.parent_sha1[stage-2],
147
nce->sha1, 20);
148
+ }
149
150
/* diff against the proper unmerged stage */
151
if (stage == diff_unmerged_stage)
@@ -154,12 +157,14 @@ int main(int argc, const char **argv)
157
*/
158
i--;
159
157
- if (combine_merges) {
160
+ if (combine_merges && num_compare_stages == 2) {
161
show_combined_diff(&combine.p, 2,
162
dense_combined_merges,
163
NULL, 0);
164
+ free(combine.p.path);
165
continue;
166
}
167
+ free(combine.p.path);
168
169
/*
170
* Show the diff for the 'ce' if we found the one