diff options
author | Jonathan Nieder <jrnieder@gmail.com> | 2014-09-11 03:22:48 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-10-15 19:47:25 +0200 |
commit | 62a2d52514aed2b684409cb48e40e0cd14335d1b (patch) | |
tree | 609d4997c69205497bbd6103c0d76f49e22b91e8 /refs.c | |
parent | reflog test: test interaction with detached HEAD (diff) | |
download | git-62a2d52514aed2b684409cb48e40e0cd14335d1b.tar.xz git-62a2d52514aed2b684409cb48e40e0cd14335d1b.zip |
branch -d: avoid repeated symref resolution
If a repository gets in a broken state with too much symref nesting,
it cannot be repaired with "git branch -d":
$ git symbolic-ref refs/heads/nonsense refs/heads/nonsense
$ git branch -d nonsense
error: branch 'nonsense' not found.
Worse, "git update-ref --no-deref -d" doesn't work for such repairs
either:
$ git update-ref -d refs/heads/nonsense
error: unable to resolve reference refs/heads/nonsense: Too many levels of symbolic links
Fix both by teaching resolve_ref_unsafe a new RESOLVE_REF_NO_RECURSE
flag and passing it when appropriate.
Callers can still read the value of a symref (for example to print a
message about it) with that flag set --- resolve_ref_unsafe will
resolve one level of symrefs and stop there.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1467,6 +1467,10 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned refname = refname_buffer; if (flags) *flags |= REF_ISSYMREF; + if (resolve_flags & RESOLVE_REF_NO_RECURSE) { + hashclr(sha1); + return refname; + } continue; } } @@ -1523,13 +1527,17 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned buf = buffer + 4; while (isspace(*buf)) buf++; + refname = strcpy(refname_buffer, buf); + if (resolve_flags & RESOLVE_REF_NO_RECURSE) { + hashclr(sha1); + return refname; + } if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) { if (flags) *flags |= REF_ISBROKEN; errno = EINVAL; return NULL; } - refname = strcpy(refname_buffer, buf); } } @@ -2170,6 +2178,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, if (mustexist) resolve_flags |= RESOLVE_REF_READING; + if (flags & REF_NODEREF && flags & REF_DELETING) + resolve_flags |= RESOLVE_REF_NO_RECURSE; refname = resolve_ref_unsafe(refname, resolve_flags, lock->old_sha1, &type); @@ -3664,13 +3674,16 @@ int ref_transaction_commit(struct ref_transaction *transaction, /* Acquire all locks while verifying old values */ for (i = 0; i < n; i++) { struct ref_update *update = updates[i]; + int flags = update->flags; + if (is_null_sha1(update->new_sha1)) + flags |= REF_DELETING; update->lock = lock_ref_sha1_basic(update->refname, (update->have_old ? update->old_sha1 : NULL), NULL, - update->flags, + flags, &update->type); if (!update->lock) { ret = (errno == ENOTDIR) |