diff: release blobs after generating textual diff.
This reduces the memory pressure when dealing with many paths. An unscientific test of running "diff-tree --stat --summary -M" between v2.6.19 and v2.6.20-rc1 in the linux kernel repository indicates that the number of minor faults are reduced by 2/3. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
May 3, 2007 at 13:05 UTC
fc3abdf5cb16914fb22747d7c3fb44258712a36d
1 file changed
+17
-5
diff.c
+17
-5
@@ -1236,6 +1236,8 @@ static void builtin_diff(const char *name_a,
1236
}
1237
1238
free_ab_and_return:
1239
+ diff_free_filespec_data(one);
1240
+ diff_free_filespec_data(two);
1241
free(a_one);
1242
free(b_two);
1243
return;
@@ -1262,7 +1264,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1264
diff_populate_filespec(two, 0);
1265
data->deleted = count_lines(one->data, one->size);
1266
data->added = count_lines(two->data, two->size);
1265
- return;
1267
+ goto free_and_return;
1268
}
1269
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1270
die("unable to read files to diff");
@@ -1284,6 +1286,10 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1286
ecb.priv = diffstat;
1287
xdl_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1288
}
1289
+
1290
+ free_and_return:
1291
+ diff_free_filespec_data(one);
1292
+ diff_free_filespec_data(two);
1293
}
1294
1295
static void builtin_checkdiff(const char *name_a, const char *name_b,
@@ -1306,7 +1312,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1312
die("unable to read files to diff");
1313
1314
if (file_is_binary(two))
1309
- return;
1315
+ goto free_and_return;
1316
else {
1317
/* Crazy xdl interfaces.. */
1318
xpparam_t xpp;
@@ -1320,6 +1326,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1326
ecb.priv = &data;
1327
xdl_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1328
}
1329
+ free_and_return:
1330
+ diff_free_filespec_data(one);
1331
+ diff_free_filespec_data(two);
1332
}
1333
1334
struct diff_filespec *alloc_filespec(const char *path)
@@ -1507,7 +1516,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1516
size_only = 0;
1517
1518
if (s->data)
1510
- return err;
1519
+ return 0;
1520
1521
if (S_ISDIRLNK(s->mode))
1522
return diff_populate_gitlink(s, size_only);
@@ -1597,8 +1606,11 @@ void diff_free_filespec_data(struct diff_filespec *s)
1606
free(s->data);
1607
else if (s->should_munmap)
1608
munmap(s->data, s->size);
1600
- s->should_free = s->should_munmap = 0;
1601
- s->data = NULL;
1609
+
1610
+ if (s->should_free || s->should_munmap) {
1611
+ s->should_free = s->should_munmap = 0;
1612
+ s->data = NULL;
1613
+ }
1614
free(s->cnt_data);
1615
s->cnt_data = NULL;
1616
}