@@ -47,31 +47,20 @@ static struct combine_diff_path *intersect_paths(
47
47
48
48
if (!n ) {
49
49
for (i = 0 ; i < q -> nr ; i ++ ) {
50
- int len ;
51
- const char * path ;
52
50
if (diff_unmodified_pair (q -> queue [i ]))
53
51
continue ;
54
- path = q -> queue [i ]-> two -> path ;
55
- len = strlen (path );
56
- p = xmalloc (combine_diff_path_size (num_parent , len ));
57
- p -> path = (char * ) & (p -> parent [num_parent ]);
58
- memcpy (p -> path , path , len );
59
- p -> path [len ] = 0 ;
60
- p -> next = NULL ;
61
- memset (p -> parent , 0 ,
62
- sizeof (p -> parent [0 ]) * num_parent );
63
-
64
- oidcpy (& p -> oid , & q -> queue [i ]-> two -> oid );
65
- p -> mode = q -> queue [i ]-> two -> mode ;
52
+ p = combine_diff_path_new (q -> queue [i ]-> two -> path ,
53
+ strlen (q -> queue [i ]-> two -> path ),
54
+ q -> queue [i ]-> two -> mode ,
55
+ & q -> queue [i ]-> two -> oid ,
56
+ num_parent );
66
57
oidcpy (& p -> parent [n ].oid , & q -> queue [i ]-> one -> oid );
67
58
p -> parent [n ].mode = q -> queue [i ]-> one -> mode ;
68
59
p -> parent [n ].status = q -> queue [i ]-> status ;
69
60
70
61
if (combined_all_paths &&
71
62
filename_changed (p -> parent [n ].status )) {
72
- strbuf_init (& p -> parent [n ].path , 0 );
73
- strbuf_addstr (& p -> parent [n ].path ,
74
- q -> queue [i ]-> one -> path );
63
+ p -> parent [n ].path = xstrdup (q -> queue [i ]-> one -> path );
75
64
}
76
65
* tail = p ;
77
66
tail = & p -> next ;
@@ -92,9 +81,7 @@ static struct combine_diff_path *intersect_paths(
92
81
/* p->path not in q->queue[]; drop it */
93
82
* tail = p -> next ;
94
83
for (j = 0 ; j < num_parent ; j ++ )
95
- if (combined_all_paths &&
96
- filename_changed (p -> parent [j ].status ))
97
- strbuf_release (& p -> parent [j ].path );
84
+ free (p -> parent [j ].path );
98
85
free (p );
99
86
continue ;
100
87
}
@@ -110,8 +97,7 @@ static struct combine_diff_path *intersect_paths(
110
97
p -> parent [n ].status = q -> queue [i ]-> status ;
111
98
if (combined_all_paths &&
112
99
filename_changed (p -> parent [n ].status ))
113
- strbuf_addstr (& p -> parent [n ].path ,
114
- q -> queue [i ]-> one -> path );
100
+ p -> parent [n ].path = xstrdup (q -> queue [i ]-> one -> path );
115
101
116
102
tail = & p -> next ;
117
103
i ++ ;
@@ -996,8 +982,9 @@ static void show_combined_header(struct combine_diff_path *elem,
996
982
997
983
if (rev -> combined_all_paths ) {
998
984
for (i = 0 ; i < num_parent ; i ++ ) {
999
- char * path = filename_changed (elem -> parent [i ].status )
1000
- ? elem -> parent [i ].path .buf : elem -> path ;
985
+ const char * path = elem -> parent [i ].path ?
986
+ elem -> parent [i ].path :
987
+ elem -> path ;
1001
988
if (elem -> parent [i ].status == DIFF_STATUS_ADDED )
1002
989
dump_quoted_path ("--- " , "" , "/dev/null" ,
1003
990
line_prefix , c_meta , c_reset );
@@ -1278,12 +1265,10 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
1278
1265
1279
1266
for (i = 0 ; i < num_parent ; i ++ )
1280
1267
if (rev -> combined_all_paths ) {
1281
- if (filename_changed (p -> parent [i ].status ))
1282
- write_name_quoted (p -> parent [i ].path .buf , stdout ,
1283
- inter_name_termination );
1284
- else
1285
- write_name_quoted (p -> path , stdout ,
1286
- inter_name_termination );
1268
+ const char * path = p -> parent [i ].path ?
1269
+ p -> parent [i ].path :
1270
+ p -> path ;
1271
+ write_name_quoted (path , stdout , inter_name_termination );
1287
1272
}
1288
1273
write_name_quoted (p -> path , stdout , line_termination );
1289
1274
}
@@ -1443,22 +1428,19 @@ static struct combine_diff_path *find_paths_multitree(
1443
1428
{
1444
1429
int i , nparent = parents -> nr ;
1445
1430
const struct object_id * * parents_oid ;
1446
- struct combine_diff_path paths_head ;
1431
+ struct combine_diff_path * paths ;
1447
1432
struct strbuf base ;
1448
1433
1449
1434
ALLOC_ARRAY (parents_oid , nparent );
1450
1435
for (i = 0 ; i < nparent ; i ++ )
1451
1436
parents_oid [i ] = & parents -> oid [i ];
1452
1437
1453
- /* fake list head, so worker can assume it is non-NULL */
1454
- paths_head .next = NULL ;
1455
-
1456
1438
strbuf_init (& base , PATH_MAX );
1457
- diff_tree_paths (& paths_head , oid , parents_oid , nparent , & base , opt );
1439
+ paths = diff_tree_paths (oid , parents_oid , nparent , & base , opt );
1458
1440
1459
1441
strbuf_release (& base );
1460
1442
free (parents_oid );
1461
- return paths_head . next ;
1443
+ return paths ;
1462
1444
}
1463
1445
1464
1446
static int match_objfind (struct combine_diff_path * path ,
@@ -1645,9 +1627,7 @@ void diff_tree_combined(const struct object_id *oid,
1645
1627
struct combine_diff_path * tmp = paths ;
1646
1628
paths = paths -> next ;
1647
1629
for (i = 0 ; i < num_parent ; i ++ )
1648
- if (rev -> combined_all_paths &&
1649
- filename_changed (tmp -> parent [i ].status ))
1650
- strbuf_release (& tmp -> parent [i ].path );
1630
+ free (tmp -> parent [i ].path );
1651
1631
free (tmp );
1652
1632
}
1653
1633
@@ -1667,3 +1647,25 @@ void diff_tree_combined_merge(const struct commit *commit,
1667
1647
diff_tree_combined (& commit -> object .oid , & parents , rev );
1668
1648
oid_array_clear (& parents );
1669
1649
}
1650
+
1651
+ struct combine_diff_path * combine_diff_path_new (const char * path ,
1652
+ size_t path_len ,
1653
+ unsigned int mode ,
1654
+ const struct object_id * oid ,
1655
+ size_t num_parents )
1656
+ {
1657
+ struct combine_diff_path * p ;
1658
+ size_t parent_len = st_mult (sizeof (p -> parent [0 ]), num_parents );
1659
+
1660
+ p = xmalloc (st_add4 (sizeof (* p ), path_len , 1 , parent_len ));
1661
+ p -> path = (char * )& (p -> parent [num_parents ]);
1662
+ memcpy (p -> path , path , path_len );
1663
+ p -> path [path_len ] = 0 ;
1664
+ p -> next = NULL ;
1665
+ p -> mode = mode ;
1666
+ oidcpy (& p -> oid , oid );
1667
+
1668
+ memset (p -> parent , 0 , parent_len );
1669
+
1670
+ return p ;
1671
+ }
0 commit comments