16
16
#define FAST_WORKING_DIRECTORY 1
17
17
#endif
18
18
19
- static int use_size_cache ;
20
-
21
19
static int diff_detect_rename_default ;
22
20
static int diff_rename_limit_default = -1 ;
23
21
static int diff_use_color_default ;
@@ -1236,6 +1234,8 @@ static void builtin_diff(const char *name_a,
1236
1234
}
1237
1235
1238
1236
free_ab_and_return :
1237
+ diff_free_filespec_data (one );
1238
+ diff_free_filespec_data (two );
1239
1239
free (a_one );
1240
1240
free (b_two );
1241
1241
return ;
@@ -1262,7 +1262,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1262
1262
diff_populate_filespec (two , 0 );
1263
1263
data -> deleted = count_lines (one -> data , one -> size );
1264
1264
data -> added = count_lines (two -> data , two -> size );
1265
- return ;
1265
+ goto free_and_return ;
1266
1266
}
1267
1267
if (fill_mmfile (& mf1 , one ) < 0 || fill_mmfile (& mf2 , two ) < 0 )
1268
1268
die ("unable to read files to diff" );
@@ -1284,6 +1284,10 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1284
1284
ecb .priv = diffstat ;
1285
1285
xdl_diff (& mf1 , & mf2 , & xpp , & xecfg , & ecb );
1286
1286
}
1287
+
1288
+ free_and_return :
1289
+ diff_free_filespec_data (one );
1290
+ diff_free_filespec_data (two );
1287
1291
}
1288
1292
1289
1293
static void builtin_checkdiff (const char * name_a , const char * name_b ,
@@ -1306,7 +1310,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1306
1310
die ("unable to read files to diff" );
1307
1311
1308
1312
if (file_is_binary (two ))
1309
- return ;
1313
+ goto free_and_return ;
1310
1314
else {
1311
1315
/* Crazy xdl interfaces.. */
1312
1316
xpparam_t xpp ;
@@ -1320,6 +1324,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1320
1324
ecb .priv = & data ;
1321
1325
xdl_diff (& mf1 , & mf2 , & xpp , & xecfg , & ecb );
1322
1326
}
1327
+ free_and_return :
1328
+ diff_free_filespec_data (one );
1329
+ diff_free_filespec_data (two );
1323
1330
}
1324
1331
1325
1332
struct diff_filespec * alloc_filespec (const char * path )
@@ -1399,55 +1406,6 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
1399
1406
return 1 ;
1400
1407
}
1401
1408
1402
- static struct sha1_size_cache {
1403
- unsigned char sha1 [20 ];
1404
- unsigned long size ;
1405
- } * * sha1_size_cache ;
1406
- static int sha1_size_cache_nr , sha1_size_cache_alloc ;
1407
-
1408
- static struct sha1_size_cache * locate_size_cache (unsigned char * sha1 ,
1409
- int find_only ,
1410
- unsigned long size )
1411
- {
1412
- int first , last ;
1413
- struct sha1_size_cache * e ;
1414
-
1415
- first = 0 ;
1416
- last = sha1_size_cache_nr ;
1417
- while (last > first ) {
1418
- int cmp , next = (last + first ) >> 1 ;
1419
- e = sha1_size_cache [next ];
1420
- cmp = hashcmp (e -> sha1 , sha1 );
1421
- if (!cmp )
1422
- return e ;
1423
- if (cmp < 0 ) {
1424
- last = next ;
1425
- continue ;
1426
- }
1427
- first = next + 1 ;
1428
- }
1429
- /* not found */
1430
- if (find_only )
1431
- return NULL ;
1432
- /* insert to make it at "first" */
1433
- if (sha1_size_cache_alloc <= sha1_size_cache_nr ) {
1434
- sha1_size_cache_alloc = alloc_nr (sha1_size_cache_alloc );
1435
- sha1_size_cache = xrealloc (sha1_size_cache ,
1436
- sha1_size_cache_alloc *
1437
- sizeof (* sha1_size_cache ));
1438
- }
1439
- sha1_size_cache_nr ++ ;
1440
- if (first < sha1_size_cache_nr )
1441
- memmove (sha1_size_cache + first + 1 , sha1_size_cache + first ,
1442
- (sha1_size_cache_nr - first - 1 ) *
1443
- sizeof (* sha1_size_cache ));
1444
- e = xmalloc (sizeof (struct sha1_size_cache ));
1445
- sha1_size_cache [first ] = e ;
1446
- hashcpy (e -> sha1 , sha1 );
1447
- e -> size = size ;
1448
- return e ;
1449
- }
1450
-
1451
1409
static int populate_from_stdin (struct diff_filespec * s )
1452
1410
{
1453
1411
#define INCREMENT 1024
@@ -1503,11 +1461,11 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1503
1461
if (S_ISDIR (s -> mode ))
1504
1462
return -1 ;
1505
1463
1506
- if (!use_size_cache )
1507
- size_only = 0 ;
1508
-
1509
1464
if (s -> data )
1510
- return err ;
1465
+ return 0 ;
1466
+
1467
+ if (size_only && 0 < s -> size )
1468
+ return 0 ;
1511
1469
1512
1470
if (S_ISDIRLNK (s -> mode ))
1513
1471
return diff_populate_gitlink (s , size_only );
@@ -1570,19 +1528,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1570
1528
}
1571
1529
else {
1572
1530
enum object_type type ;
1573
- struct sha1_size_cache * e ;
1574
-
1575
- if (size_only && use_size_cache &&
1576
- (e = locate_size_cache (s -> sha1 , 1 , 0 )) != NULL ) {
1577
- s -> size = e -> size ;
1578
- return 0 ;
1579
- }
1580
-
1581
- if (size_only ) {
1531
+ if (size_only )
1582
1532
type = sha1_object_info (s -> sha1 , & s -> size );
1583
- if (use_size_cache && 0 < type )
1584
- locate_size_cache (s -> sha1 , 0 , s -> size );
1585
- }
1586
1533
else {
1587
1534
s -> data = read_sha1_file (s -> sha1 , & type , & s -> size );
1588
1535
s -> should_free = 1 ;
@@ -1597,8 +1544,11 @@ void diff_free_filespec_data(struct diff_filespec *s)
1597
1544
free (s -> data );
1598
1545
else if (s -> should_munmap )
1599
1546
munmap (s -> data , s -> size );
1600
- s -> should_free = s -> should_munmap = 0 ;
1601
- s -> data = NULL ;
1547
+
1548
+ if (s -> should_free || s -> should_munmap ) {
1549
+ s -> should_free = s -> should_munmap = 0 ;
1550
+ s -> data = NULL ;
1551
+ }
1602
1552
free (s -> cnt_data );
1603
1553
s -> cnt_data = NULL ;
1604
1554
}
@@ -2090,8 +2040,6 @@ int diff_setup_done(struct diff_options *options)
2090
2040
*/
2091
2041
read_cache ();
2092
2042
}
2093
- if (options -> setup & DIFF_SETUP_USE_SIZE_CACHE )
2094
- use_size_cache = 1 ;
2095
2043
if (options -> abbrev <= 0 || 40 < options -> abbrev )
2096
2044
options -> abbrev = 40 ; /* full */
2097
2045
0 commit comments