@@ -1353,7 +1353,8 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
1353
1353
}
1354
1354
1355
1355
static int write_ref_to_lockfile (struct ref_lock * lock ,
1356
- const struct object_id * oid , struct strbuf * err );
1356
+ const struct object_id * oid ,
1357
+ int skip_oid_verification , struct strbuf * err );
1357
1358
static int commit_ref_update (struct files_ref_store * refs ,
1358
1359
struct ref_lock * lock ,
1359
1360
const struct object_id * oid , const char * logmsg ,
@@ -1500,7 +1501,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1500
1501
}
1501
1502
oidcpy (& lock -> old_oid , & orig_oid );
1502
1503
1503
- if (write_ref_to_lockfile (lock , & orig_oid , & err ) ||
1504
+ if (write_ref_to_lockfile (lock , & orig_oid , 0 , & err ) ||
1504
1505
commit_ref_update (refs , lock , & orig_oid , logmsg , & err )) {
1505
1506
error ("unable to write current sha1 into %s: %s" , newrefname , err .buf );
1506
1507
strbuf_release (& err );
@@ -1520,7 +1521,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1520
1521
1521
1522
flag = log_all_ref_updates ;
1522
1523
log_all_ref_updates = LOG_REFS_NONE ;
1523
- if (write_ref_to_lockfile (lock , & orig_oid , & err ) ||
1524
+ if (write_ref_to_lockfile (lock , & orig_oid , 0 , & err ) ||
1524
1525
commit_ref_update (refs , lock , & orig_oid , NULL , & err )) {
1525
1526
error ("unable to write current sha1 into %s: %s" , oldrefname , err .buf );
1526
1527
strbuf_release (& err );
@@ -1756,26 +1757,31 @@ static int files_log_ref_write(struct files_ref_store *refs,
1756
1757
* errors, rollback the lockfile, fill in *err and return -1.
1757
1758
*/
1758
1759
static int write_ref_to_lockfile (struct ref_lock * lock ,
1759
- const struct object_id * oid , struct strbuf * err )
1760
+ const struct object_id * oid ,
1761
+ int skip_oid_verification , struct strbuf * err )
1760
1762
{
1761
1763
static char term = '\n' ;
1762
1764
struct object * o ;
1763
1765
int fd ;
1764
1766
1765
- o = parse_object (the_repository , oid );
1766
- if (!o ) {
1767
- strbuf_addf (err ,
1768
- "trying to write ref '%s' with nonexistent object %s" ,
1769
- lock -> ref_name , oid_to_hex (oid ));
1770
- unlock_ref (lock );
1771
- return -1 ;
1772
- }
1773
- if (o -> type != OBJ_COMMIT && is_branch (lock -> ref_name )) {
1774
- strbuf_addf (err ,
1775
- "trying to write non-commit object %s to branch '%s'" ,
1776
- oid_to_hex (oid ), lock -> ref_name );
1777
- unlock_ref (lock );
1778
- return -1 ;
1767
+ if (!skip_oid_verification ) {
1768
+ o = parse_object (the_repository , oid );
1769
+ if (!o ) {
1770
+ strbuf_addf (
1771
+ err ,
1772
+ "trying to write ref '%s' with nonexistent object %s" ,
1773
+ lock -> ref_name , oid_to_hex (oid ));
1774
+ unlock_ref (lock );
1775
+ return -1 ;
1776
+ }
1777
+ if (o -> type != OBJ_COMMIT && is_branch (lock -> ref_name )) {
1778
+ strbuf_addf (
1779
+ err ,
1780
+ "trying to write non-commit object %s to branch '%s'" ,
1781
+ oid_to_hex (oid ), lock -> ref_name );
1782
+ unlock_ref (lock );
1783
+ return -1 ;
1784
+ }
1779
1785
}
1780
1786
fd = get_lock_file_fd (& lock -> lk );
1781
1787
if (write_in_full (fd , oid_to_hex (oid ), the_hash_algo -> hexsz ) < 0 ||
@@ -2189,7 +2195,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
2189
2195
}
2190
2196
2191
2197
static int files_reflog_iterator_peel (struct ref_iterator * ref_iterator ,
2192
- struct object_id * peeled )
2198
+ struct object_id * peeled )
2193
2199
{
2194
2200
BUG ("ref_iterator_peel() called for reflog_iterator" );
2195
2201
}
@@ -2575,8 +2581,10 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2575
2581
* The reference already has the desired
2576
2582
* value, so we don't need to write it.
2577
2583
*/
2578
- } else if (write_ref_to_lockfile (lock , & update -> new_oid ,
2579
- err )) {
2584
+ } else if (write_ref_to_lockfile (
2585
+ lock , & update -> new_oid ,
2586
+ update -> flags & REF_SKIP_OID_VERIFICATION ,
2587
+ err )) {
2580
2588
char * write_err = strbuf_detach (err , NULL );
2581
2589
2582
2590
/*
0 commit comments