@@ -1427,28 +1427,30 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re
1427
1427
return show_ref (& atom -> u .refname , ref -> refname );
1428
1428
}
1429
1429
1430
- static void get_object (struct ref_array_item * ref , const struct object_id * oid ,
1431
- int deref , struct object * * obj )
1430
+ static int get_object (struct ref_array_item * ref , const struct object_id * oid ,
1431
+ int deref , struct object * * obj , struct strbuf * err )
1432
1432
{
1433
1433
int eaten ;
1434
+ int ret = 0 ;
1434
1435
unsigned long size ;
1435
1436
void * buf = get_obj (oid , obj , & size , & eaten );
1436
1437
if (!buf )
1437
- die ( _ ("missing object %s for %s" ),
1438
- oid_to_hex (oid ), ref -> refname );
1439
- if (!* obj )
1440
- die ( _ ("parse_object_buffer failed on %s for %s" ),
1441
- oid_to_hex (oid ), ref -> refname );
1442
-
1443
- grab_values (ref -> value , deref , * obj , buf , size );
1438
+ ret = strbuf_addf_ret ( err , -1 , _ ("missing object %s for %s" ),
1439
+ oid_to_hex (oid ), ref -> refname );
1440
+ else if (!* obj )
1441
+ ret = strbuf_addf_ret ( err , -1 , _ ("parse_object_buffer failed on %s for %s" ),
1442
+ oid_to_hex (oid ), ref -> refname );
1443
+ else
1444
+ grab_values (ref -> value , deref , * obj , buf , size );
1444
1445
if (!eaten )
1445
1446
free (buf );
1447
+ return ret ;
1446
1448
}
1447
1449
1448
1450
/*
1449
1451
* Parse the object referred by ref, and grab needed value.
1450
1452
*/
1451
- static void populate_value (struct ref_array_item * ref )
1453
+ static int populate_value (struct ref_array_item * ref , struct strbuf * err )
1452
1454
{
1453
1455
struct object * obj ;
1454
1456
int i ;
@@ -1570,16 +1572,17 @@ static void populate_value(struct ref_array_item *ref)
1570
1572
break ;
1571
1573
}
1572
1574
if (used_atom_cnt <= i )
1573
- return ;
1575
+ return 0 ;
1574
1576
1575
- get_object (ref , & ref -> objectname , 0 , & obj );
1577
+ if (get_object (ref , & ref -> objectname , 0 , & obj , err ))
1578
+ return -1 ;
1576
1579
1577
1580
/*
1578
1581
* If there is no atom that wants to know about tagged
1579
1582
* object, we are done.
1580
1583
*/
1581
1584
if (!need_tagged || (obj -> type != OBJ_TAG ))
1582
- return ;
1585
+ return 0 ;
1583
1586
1584
1587
/*
1585
1588
* If it is a tag object, see if we use a value that derefs
@@ -1593,20 +1596,23 @@ static void populate_value(struct ref_array_item *ref)
1593
1596
* is not consistent with what deref_tag() does
1594
1597
* which peels the onion to the core.
1595
1598
*/
1596
- get_object (ref , tagged , 1 , & obj );
1599
+ return get_object (ref , tagged , 1 , & obj , err );
1597
1600
}
1598
1601
1599
1602
/*
1600
1603
* Given a ref, return the value for the atom. This lazily gets value
1601
1604
* out of the object by calling populate value.
1602
1605
*/
1603
- static void get_ref_atom_value (struct ref_array_item * ref , int atom , struct atom_value * * v )
1606
+ static int get_ref_atom_value (struct ref_array_item * ref , int atom ,
1607
+ struct atom_value * * v , struct strbuf * err )
1604
1608
{
1605
1609
if (!ref -> value ) {
1606
- populate_value (ref );
1610
+ if (populate_value (ref , err ))
1611
+ return -1 ;
1607
1612
fill_missing_values (ref -> value );
1608
1613
}
1609
1614
* v = & ref -> value [atom ];
1615
+ return 0 ;
1610
1616
}
1611
1617
1612
1618
/*
@@ -2130,9 +2136,13 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
2130
2136
int cmp ;
2131
2137
cmp_type cmp_type = used_atom [s -> atom ].type ;
2132
2138
int (* cmp_fn )(const char * , const char * );
2139
+ struct strbuf err = STRBUF_INIT ;
2133
2140
2134
- get_ref_atom_value (a , s -> atom , & va );
2135
- get_ref_atom_value (b , s -> atom , & vb );
2141
+ if (get_ref_atom_value (a , s -> atom , & va , & err ))
2142
+ die ("%s" , err .buf );
2143
+ if (get_ref_atom_value (b , s -> atom , & vb , & err ))
2144
+ die ("%s" , err .buf );
2145
+ strbuf_release (& err );
2136
2146
cmp_fn = s -> ignore_case ? strcasecmp : strcmp ;
2137
2147
if (s -> version )
2138
2148
cmp = versioncmp (va -> s , vb -> s );
@@ -2210,12 +2220,8 @@ int format_ref_array_item(struct ref_array_item *info,
2210
2220
if (cp < sp )
2211
2221
append_literal (cp , sp , & state );
2212
2222
pos = parse_ref_filter_atom (format , sp + 2 , ep , error_buf );
2213
- if (pos < 0 ) {
2214
- pop_stack_element (& state .stack );
2215
- return -1 ;
2216
- }
2217
- get_ref_atom_value (info , pos , & atomv );
2218
- if (atomv -> handler (atomv , & state , error_buf )) {
2223
+ if (pos < 0 || get_ref_atom_value (info , pos , & atomv , error_buf ) ||
2224
+ atomv -> handler (atomv , & state , error_buf )) {
2219
2225
pop_stack_element (& state .stack );
2220
2226
return -1 ;
2221
2227
}
0 commit comments