@@ -47,31 +47,20 @@ static struct combine_diff_path *intersect_paths(
4747
4848 if (!n ) {
4949 for (i = 0 ; i < q -> nr ; i ++ ) {
50- int len ;
51- const char * path ;
5250 if (diff_unmodified_pair (q -> queue [i ]))
5351 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 );
6657 oidcpy (& p -> parent [n ].oid , & q -> queue [i ]-> one -> oid );
6758 p -> parent [n ].mode = q -> queue [i ]-> one -> mode ;
6859 p -> parent [n ].status = q -> queue [i ]-> status ;
6960
7061 if (combined_all_paths &&
7162 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 );
7564 }
7665 * tail = p ;
7766 tail = & p -> next ;
@@ -92,9 +81,7 @@ static struct combine_diff_path *intersect_paths(
9281 /* p->path not in q->queue[]; drop it */
9382 * tail = p -> next ;
9483 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 );
9885 free (p );
9986 continue ;
10087 }
@@ -110,8 +97,7 @@ static struct combine_diff_path *intersect_paths(
11097 p -> parent [n ].status = q -> queue [i ]-> status ;
11198 if (combined_all_paths &&
11299 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 );
115101
116102 tail = & p -> next ;
117103 i ++ ;
@@ -996,8 +982,9 @@ static void show_combined_header(struct combine_diff_path *elem,
996982
997983 if (rev -> combined_all_paths ) {
998984 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 ;
1001988 if (elem -> parent [i ].status == DIFF_STATUS_ADDED )
1002989 dump_quoted_path ("--- " , "" , "/dev/null" ,
1003990 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
12781265
12791266 for (i = 0 ; i < num_parent ; i ++ )
12801267 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 );
12871272 }
12881273 write_name_quoted (p -> path , stdout , line_termination );
12891274}
@@ -1443,22 +1428,19 @@ static struct combine_diff_path *find_paths_multitree(
14431428{
14441429 int i , nparent = parents -> nr ;
14451430 const struct object_id * * parents_oid ;
1446- struct combine_diff_path paths_head ;
1431+ struct combine_diff_path * paths ;
14471432 struct strbuf base ;
14481433
14491434 ALLOC_ARRAY (parents_oid , nparent );
14501435 for (i = 0 ; i < nparent ; i ++ )
14511436 parents_oid [i ] = & parents -> oid [i ];
14521437
1453- /* fake list head, so worker can assume it is non-NULL */
1454- paths_head .next = NULL ;
1455-
14561438 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 );
14581440
14591441 strbuf_release (& base );
14601442 free (parents_oid );
1461- return paths_head . next ;
1443+ return paths ;
14621444}
14631445
14641446static int match_objfind (struct combine_diff_path * path ,
@@ -1645,9 +1627,7 @@ void diff_tree_combined(const struct object_id *oid,
16451627 struct combine_diff_path * tmp = paths ;
16461628 paths = paths -> next ;
16471629 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 );
16511631 free (tmp );
16521632 }
16531633
@@ -1667,3 +1647,25 @@ void diff_tree_combined_merge(const struct commit *commit,
16671647 diff_tree_combined (& commit -> object .oid , & parents , rev );
16681648 oid_array_clear (& parents );
16691649}
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