diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-11-13 18:15:20 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-11-23 14:55:02 +0100 |
commit | a57dd3b7a46c9a2f87f203f1ab372fa28e10e571 (patch) | |
tree | ce76f383edaa14bee45a687453223613c1c1ee9c /src/stash.c | |
parent | 110df89317b56267b956574216d6611637860446 (diff) | |
download | libgit2-a57dd3b7a46c9a2f87f203f1ab372fa28e10e571.tar.gz |
reflog: integrate into the ref writing
Whenever a reference is created or updated, we need to write to the
reflog regardless of whether the user gave us a message, so we shouldn't
leave that to the ref frontend, but integrate it into the backend.
This also eliminates the race between ref update and writing to the
reflog, as we protect the reflog with the ref lock.
As an additional benefit, this reflog append on the backend happens by
appending to the file instead of parsing and rewriting it.
Diffstat (limited to 'src/stash.c')
-rw-r--r-- | src/stash.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/stash.c b/src/stash.c index 083c2a4cd..66b1cd7c5 100644 --- a/src/stash.c +++ b/src/stash.c @@ -412,25 +412,12 @@ static int update_reflog( const char *message) { git_reference *stash; - git_reflog *reflog = NULL; int error; - if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0) - goto cleanup; + error = git_reference_create_with_log(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message); git_reference_free(stash); - if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE) < 0)) - goto cleanup; - - if ((error = git_reflog_append(reflog, w_commit_oid, stasher, message)) < 0) - goto cleanup; - - if ((error = git_reflog_write(reflog)) < 0) - goto cleanup; - -cleanup: - git_reflog_free(reflog); return error; } @@ -636,7 +623,11 @@ int git_stash_drop( entry = git_reflog_entry_byindex(reflog, 0); git_reference_free(stash); - error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1); + if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1) < 0)) + goto cleanup; + + /* We need to undo the writing that we just did */ + error = git_reflog_write(reflog); } cleanup: |