]> granicus.if.org Git - git/commitdiff
Merge branch 'mh/expire-updateref-fixes'
authorJunio C Hamano <gitster@pobox.com>
Tue, 10 Mar 2015 20:52:39 +0000 (13:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Mar 2015 20:52:40 +0000 (13:52 -0700)
Various issues around "reflog expire", e.g. using --updateref when
expiring a reflog for a symbolic reference, have been corrected
and/or made saner.

* mh/expire-updateref-fixes:
  reflog_expire(): never update a reference to null_sha1
  reflog_expire(): ignore --updateref for symbolic references
  reflog: improve and update documentation
  struct ref_lock: delete the force_write member
  lock_ref_sha1_basic(): do not set force_write for missing references
  write_ref_sha1(): move write elision test to callers
  write_ref_sha1(): remove check for lock == NULL

1  2 
refs.c

diff --cc refs.c
index 8d46b08055ef9cb151c1868a0354fd906b0bcddf,05a4be0c0628098dec80d9bd8a564cfc019c2427..e23542b3869b38e47f59f102d28648d30d506574
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -3848,11 -3783,21 +3832,22 @@@ int ref_transaction_commit(struct ref_t
        /* Perform updates first so live commits remain referenced */
        for (i = 0; i < n; i++) {
                struct ref_update *update = updates[i];
 +              int flags = update->flags;
  
 -              if (!is_null_sha1(update->new_sha1)) {
 +              if ((flags & REF_HAVE_NEW) && !is_null_sha1(update->new_sha1)) {
-                       if (write_ref_sha1(update->lock, update->new_sha1,
-                                          update->msg)) {
+                       int overwriting_symref = ((update->type & REF_ISSYMREF) &&
+                                                 (update->flags & REF_NODEREF));
+                       if (!overwriting_symref
+                           && !hashcmp(update->lock->old_sha1, update->new_sha1)) {
+                               /*
+                                * The reference already has the desired
+                                * value, so we don't need to write it.
+                                */
+                               unlock_ref(update->lock);
+                               update->lock = NULL;
+                       } else if (write_ref_sha1(update->lock, update->new_sha1,
+                                                 update->msg)) {
                                update->lock = NULL; /* freed by write_ref_sha1 */
                                strbuf_addf(err, "Cannot update the ref '%s'.",
                                            update->refname);