diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-19 16:30:37 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-19 16:52:20 +0100 |
| commit | 6aaae94a7060834a68f3fd24d8006dbfe769e04a (patch) | |
| tree | d0a9531c535c7fdbacfc77206c558222d5ae2731 /src | |
| parent | afc57eb48fc69d3e4808648c090aa6f91f9b29aa (diff) | |
| download | libgit2-6aaae94a7060834a68f3fd24d8006dbfe769e04a.tar.gz | |
reflog: handle the birth of a branch
The reflog append function was overzealous in its checking. When passed
an old and new ids, it should not do any checking, but just serialize
the data to a reflog entry.
Diffstat (limited to 'src')
| -rw-r--r-- | src/refdb_fs.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index f2edf0c56..905113226 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -992,18 +992,24 @@ out: static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message) { int error; - git_oid old_id; + git_oid old_id = {{0}}; git_reference *head; - error = git_reference_name_to_id(&old_id, backend->repo, ref->name); - if (!git_branch_is_head(ref)) - return 0; + /* if we can't resolve, we use {0}*40 as old id */ + git_reference_name_to_id(&old_id, backend->repo, ref->name); if ((error = git_reference_lookup(&head, backend->repo, "HEAD")) < 0) return error; + if (git_reference_type(head) == GIT_REF_OID) + goto cleanup; + + if (strcmp(git_reference_symbolic_target(head), ref->name)) + goto cleanup; + error = reflog_append(backend, head, &old_id, git_reference_target(ref), who, message); +cleanup: git_reference_free(head); return error; } @@ -1595,23 +1601,23 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co return error; } - if (is_symbolic) { - error = git_reference_name_to_id(&new_id, repo, git_reference_symbolic_target(ref)); - if (error < 0 && error != GIT_ENOTFOUND) - return error; - /* detaching HEAD does not create an entry */ - if (error == GIT_ENOTFOUND) - return 0; + if (new) { + git_oid_cpy(&new_id, new); + } else { + if (!is_symbolic) { + git_oid_cpy(&new_id, git_reference_target(ref)); + } else { + error = git_reference_name_to_id(&new_id, repo, git_reference_symbolic_target(ref)); + if (error < 0 && error != GIT_ENOTFOUND) + return error; + /* detaching HEAD does not create an entry */ + if (error == GIT_ENOTFOUND) + return 0; - giterr_clear(); + giterr_clear(); + } } - - if (new) - git_oid_cpy(&new_id, new); - else if (!is_symbolic) - git_oid_cpy(&new_id, git_reference_target(ref)); - if ((error = serialize_reflog_entry(&buf, &old_id, &new_id, who, message)) < 0) goto cleanup; |
