@@ -91,6 +91,7 @@ static struct expand_data {
91
91
struct object_id delta_base_oid ;
92
92
void * content ;
93
93
94
+ struct object * maybe_object ;
94
95
struct object_info info ;
95
96
} oi , oi_deref ;
96
97
@@ -1475,18 +1476,46 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
1475
1476
}
1476
1477
}
1477
1478
1479
+ static int get_or_parse_object (struct expand_data * data , const char * refname ,
1480
+ struct object * * object , struct strbuf * err , int * eaten )
1481
+ {
1482
+ if (!data -> maybe_object ) {
1483
+ data -> maybe_object = parse_object_buffer (the_repository , & data -> oid , data -> type ,
1484
+ data -> size , data -> content , eaten );
1485
+ if (!data -> maybe_object )
1486
+ return strbuf_addf_ret (err , -1 , _ ("parse_object_buffer failed on %s for %s" ),
1487
+ oid_to_hex (& data -> oid ), refname );
1488
+ }
1489
+
1490
+ * object = data -> maybe_object ;
1491
+ return 0 ;
1492
+ }
1493
+
1478
1494
/* See grab_values */
1479
- static void grab_tag_values (struct atom_value * val , int deref , struct object * obj )
1495
+ static int grab_tag_values (struct atom_value * val , int deref ,
1496
+ struct expand_data * data , const char * refname ,
1497
+ struct strbuf * err , int * eaten )
1480
1498
{
1481
- int i ;
1482
- struct tag * tag = ( struct tag * ) obj ;
1499
+ struct tag * tag = NULL ;
1500
+ int i , ret ;
1483
1501
1484
1502
for (i = 0 ; i < used_atom_cnt ; i ++ ) {
1485
1503
const char * name = used_atom [i ].name ;
1486
1504
enum atom_type atom_type = used_atom [i ].atom_type ;
1487
1505
struct atom_value * v = & val [i ];
1488
1506
if (!!deref != (* name == '*' ))
1489
1507
continue ;
1508
+
1509
+ if (!tag ) {
1510
+ struct object * object ;
1511
+
1512
+ ret = get_or_parse_object (data , refname , & object , err , eaten );
1513
+ if (ret < 0 )
1514
+ return ret ;
1515
+
1516
+ tag = (struct tag * ) object ;
1517
+ }
1518
+
1490
1519
if (deref )
1491
1520
name ++ ;
1492
1521
if (atom_type == ATOM_TAG )
@@ -1496,22 +1525,38 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
1496
1525
else if (atom_type == ATOM_OBJECT && tag -> tagged )
1497
1526
v -> s = xstrdup (oid_to_hex (& tag -> tagged -> oid ));
1498
1527
}
1528
+
1529
+ return 0 ;
1499
1530
}
1500
1531
1501
1532
/* See grab_values */
1502
- static void grab_commit_values (struct atom_value * val , int deref , struct object * obj )
1533
+ static int grab_commit_values (struct atom_value * val , int deref ,
1534
+ struct expand_data * data , const char * refname ,
1535
+ struct strbuf * err , int * eaten )
1503
1536
{
1504
- int i ;
1505
- struct commit * commit = ( struct commit * ) obj ;
1537
+ int i , ret ;
1538
+ struct commit * commit = NULL ;
1506
1539
1507
1540
for (i = 0 ; i < used_atom_cnt ; i ++ ) {
1508
1541
const char * name = used_atom [i ].name ;
1509
1542
enum atom_type atom_type = used_atom [i ].atom_type ;
1510
1543
struct atom_value * v = & val [i ];
1544
+
1511
1545
if (!!deref != (* name == '*' ))
1512
1546
continue ;
1513
1547
if (deref )
1514
1548
name ++ ;
1549
+
1550
+ if (!commit ) {
1551
+ struct object * object ;
1552
+
1553
+ ret = get_or_parse_object (data , refname , & object , err , eaten );
1554
+ if (ret < 0 )
1555
+ return ret ;
1556
+
1557
+ commit = (struct commit * ) object ;
1558
+ }
1559
+
1515
1560
if (atom_type == ATOM_TREE &&
1516
1561
grab_oid (name , "tree" , get_commit_tree_oid (commit ), v , & used_atom [i ]))
1517
1562
continue ;
@@ -1531,6 +1576,8 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
1531
1576
v -> s = strbuf_detach (& s , NULL );
1532
1577
}
1533
1578
}
1579
+
1580
+ return 0 ;
1534
1581
}
1535
1582
1536
1583
static const char * find_wholine (const char * who , int wholen , const char * buf )
@@ -1759,10 +1806,12 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1759
1806
}
1760
1807
}
1761
1808
1762
- static void grab_signature (struct atom_value * val , int deref , struct object * obj )
1809
+ static int grab_signature (struct atom_value * val , int deref ,
1810
+ struct expand_data * data , const char * refname ,
1811
+ struct strbuf * err , int * eaten )
1763
1812
{
1764
- int i ;
1765
- struct commit * commit = ( struct commit * ) obj ;
1813
+ int i , ret ;
1814
+ struct commit * commit = NULL ;
1766
1815
struct signature_check sigc = { 0 };
1767
1816
int signature_checked = 0 ;
1768
1817
@@ -1790,6 +1839,16 @@ static void grab_signature(struct atom_value *val, int deref, struct object *obj
1790
1839
continue ;
1791
1840
1792
1841
if (!signature_checked ) {
1842
+ if (!commit ) {
1843
+ struct object * object ;
1844
+
1845
+ ret = get_or_parse_object (data , refname , & object , err , eaten );
1846
+ if (ret < 0 )
1847
+ return ret ;
1848
+
1849
+ commit = (struct commit * ) object ;
1850
+ }
1851
+
1793
1852
check_commit_signature (commit , & sigc );
1794
1853
signature_checked = 1 ;
1795
1854
}
@@ -1843,6 +1902,8 @@ static void grab_signature(struct atom_value *val, int deref, struct object *obj
1843
1902
1844
1903
if (signature_checked )
1845
1904
signature_check_clear (& sigc );
1905
+
1906
+ return 0 ;
1846
1907
}
1847
1908
1848
1909
static void find_subpos (const char * buf ,
@@ -1920,9 +1981,8 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
1920
1981
}
1921
1982
1922
1983
static void grab_describe_values (struct atom_value * val , int deref ,
1923
- struct object * obj )
1984
+ struct expand_data * data )
1924
1985
{
1925
- struct commit * commit = (struct commit * )obj ;
1926
1986
int i ;
1927
1987
1928
1988
for (i = 0 ; i < used_atom_cnt ; i ++ ) {
@@ -1944,7 +2004,7 @@ static void grab_describe_values(struct atom_value *val, int deref,
1944
2004
cmd .git_cmd = 1 ;
1945
2005
strvec_push (& cmd .args , "describe" );
1946
2006
strvec_pushv (& cmd .args , atom -> u .describe_args .v );
1947
- strvec_push (& cmd .args , oid_to_hex (& commit -> object . oid ));
2007
+ strvec_push (& cmd .args , oid_to_hex (& data -> oid ));
1948
2008
if (pipe_command (& cmd , NULL , 0 , & out , 0 , & err , 0 ) < 0 ) {
1949
2009
error (_ ("failed to run 'describe'" ));
1950
2010
v -> s = xstrdup ("" );
@@ -2066,24 +2126,36 @@ static void fill_missing_values(struct atom_value *val)
2066
2126
* pointed at by the ref itself; otherwise it is the object the
2067
2127
* ref (which is a tag) refers to.
2068
2128
*/
2069
- static void grab_values (struct atom_value * val , int deref , struct object * obj , struct expand_data * data )
2129
+ static int grab_values (struct atom_value * val , int deref , struct expand_data * data ,
2130
+ const char * refname , struct strbuf * err , int * eaten )
2070
2131
{
2071
2132
void * buf = data -> content ;
2133
+ int ret ;
2072
2134
2073
- switch (obj -> type ) {
2135
+ switch (data -> type ) {
2074
2136
case OBJ_TAG :
2075
- grab_tag_values (val , deref , obj );
2137
+ ret = grab_tag_values (val , deref , data , refname , err , eaten );
2138
+ if (ret < 0 )
2139
+ goto out ;
2140
+
2076
2141
grab_sub_body_contents (val , deref , data );
2077
2142
grab_person ("tagger" , val , deref , buf );
2078
- grab_describe_values (val , deref , obj );
2143
+ grab_describe_values (val , deref , data );
2079
2144
break ;
2080
2145
case OBJ_COMMIT :
2081
- grab_commit_values (val , deref , obj );
2146
+ ret = grab_commit_values (val , deref , data , refname , err , eaten );
2147
+ if (ret < 0 )
2148
+ goto out ;
2149
+
2082
2150
grab_sub_body_contents (val , deref , data );
2083
2151
grab_person ("author" , val , deref , buf );
2084
2152
grab_person ("committer" , val , deref , buf );
2085
- grab_signature (val , deref , obj );
2086
- grab_describe_values (val , deref , obj );
2153
+
2154
+ ret = grab_signature (val , deref , data , refname , err , eaten );
2155
+ if (ret < 0 )
2156
+ goto out ;
2157
+
2158
+ grab_describe_values (val , deref , data );
2087
2159
break ;
2088
2160
case OBJ_TREE :
2089
2161
/* grab_tree_values(val, deref, obj, buf, sz); */
@@ -2094,8 +2166,12 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, s
2094
2166
grab_sub_body_contents (val , deref , data );
2095
2167
break ;
2096
2168
default :
2097
- die ("Eh? Object of type %d?" , obj -> type );
2169
+ die ("Eh? Object of type %d?" , data -> type );
2098
2170
}
2171
+
2172
+ ret = 0 ;
2173
+ out :
2174
+ return ret ;
2099
2175
}
2100
2176
2101
2177
static inline char * copy_advance (char * dst , const char * src )
@@ -2292,38 +2368,41 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re
2292
2368
return show_ref (& atom -> u .refname , ref -> refname );
2293
2369
}
2294
2370
2295
- static int get_object (struct ref_array_item * ref , int deref , struct object * * obj ,
2371
+ static int get_object (struct ref_array_item * ref , int deref ,
2296
2372
struct expand_data * oi , struct strbuf * err )
2297
2373
{
2298
- /* parse_object_buffer() will set eaten to 0 if free() will be needed */
2299
- int eaten = 1 ;
2374
+ /* parse_object_buffer() will set eaten to 1 if free() will be needed */
2375
+ int eaten = 0 ;
2376
+ int ret ;
2377
+
2300
2378
if (oi -> info .contentp ) {
2301
2379
/* We need to know that to use parse_object_buffer properly */
2302
2380
oi -> info .sizep = & oi -> size ;
2303
2381
oi -> info .typep = & oi -> type ;
2304
2382
}
2383
+
2305
2384
if (odb_read_object_info_extended (the_repository -> objects , & oi -> oid , & oi -> info ,
2306
- OBJECT_INFO_LOOKUP_REPLACE ))
2307
- return strbuf_addf_ret (err , -1 , _ ("missing object %s for %s" ),
2308
- oid_to_hex (& oi -> oid ), ref -> refname );
2385
+ OBJECT_INFO_LOOKUP_REPLACE )) {
2386
+ ret = strbuf_addf_ret (err , -1 , _ ("missing object %s for %s" ),
2387
+ oid_to_hex (& oi -> oid ), ref -> refname );
2388
+ goto out ;
2389
+ }
2309
2390
if (oi -> info .disk_sizep && oi -> disk_size < 0 )
2310
2391
BUG ("Object size is less than zero." );
2311
2392
2312
2393
if (oi -> info .contentp ) {
2313
- * obj = parse_object_buffer (the_repository , & oi -> oid , oi -> type , oi -> size , oi -> content , & eaten );
2314
- if (!* obj ) {
2315
- if (!eaten )
2316
- free (oi -> content );
2317
- return strbuf_addf_ret (err , -1 , _ ("parse_object_buffer failed on %s for %s" ),
2318
- oid_to_hex (& oi -> oid ), ref -> refname );
2319
- }
2320
- grab_values (ref -> value , deref , * obj , oi );
2394
+ ret = grab_values (ref -> value , deref , oi , ref -> refname , err , & eaten );
2395
+ if (ret < 0 )
2396
+ goto out ;
2321
2397
}
2322
2398
2323
2399
grab_common_values (ref -> value , deref , oi );
2400
+ ret = 0 ;
2401
+
2402
+ out :
2324
2403
if (!eaten )
2325
2404
free (oi -> content );
2326
- return 0 ;
2405
+ return ret ;
2327
2406
}
2328
2407
2329
2408
static void populate_worktree_map (struct hashmap * map , struct worktree * * worktrees )
@@ -2376,7 +2455,6 @@ static char *get_worktree_path(const struct ref_array_item *ref)
2376
2455
*/
2377
2456
static int populate_value (struct ref_array_item * ref , struct strbuf * err )
2378
2457
{
2379
- struct object * obj ;
2380
2458
int i ;
2381
2459
struct object_info empty = OBJECT_INFO_INIT ;
2382
2460
int ahead_behind_atoms = 0 ;
@@ -2564,14 +2642,14 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
2564
2642
2565
2643
2566
2644
oi .oid = ref -> objectname ;
2567
- if (get_object (ref , 0 , & obj , & oi , err ))
2645
+ if (get_object (ref , 0 , & oi , err ))
2568
2646
return -1 ;
2569
2647
2570
2648
/*
2571
2649
* If there is no atom that wants to know about tagged
2572
2650
* object, we are done.
2573
2651
*/
2574
- if (!need_tagged || (obj -> type != OBJ_TAG ))
2652
+ if (!need_tagged || (oi . type != OBJ_TAG ))
2575
2653
return 0 ;
2576
2654
2577
2655
/*
@@ -2589,7 +2667,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
2589
2667
}
2590
2668
}
2591
2669
2592
- return get_object (ref , 1 , & obj , & oi_deref , err );
2670
+ return get_object (ref , 1 , & oi_deref , err );
2593
2671
}
2594
2672
2595
2673
/*
0 commit comments