summaryrefslogtreecommitdiff
path: root/src/stash.c
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2013-12-18 09:33:45 -0800
committerVicent Marti <vicent@github.com>2013-12-18 09:33:45 -0800
commit4e1f517c61fef323b9cb3acedd19ce7859a8e546 (patch)
tree87823d6c36e00b3098069142ba9e630e2570f1b7 /src/stash.c
parenta7ecd1a9e36df5d6843c1863542c02d777e9e8b5 (diff)
parentf21051297cc698644ea0dc9c7122ec944dba2863 (diff)
downloadlibgit2-4e1f517c61fef323b9cb3acedd19ce7859a8e546.tar.gz
Merge pull request #1920 from libgit2/cmn/ref-with-log
Reference operations with log
Diffstat (limited to 'src/stash.c')
-rw-r--r--src/stash.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/stash.c b/src/stash.c
index eae56966c..3019816ff 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -412,25 +412,15 @@ 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;
-
- git_reference_free(stash);
-
- if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE) < 0))
- goto cleanup;
+ if ((error = git_reference_ensure_log(repo, GIT_REFS_STASH_FILE)) < 0)
+ return error;
- if ((error = git_reflog_append(reflog, w_commit_oid, stasher, message)) < 0)
- goto cleanup;
+ error = git_reference_create_with_log(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message);
- if ((error = git_reflog_write(reflog)) < 0)
- goto cleanup;
+ git_reference_free(stash);
-cleanup:
- git_reflog_free(reflog);
return error;
}
@@ -638,7 +628,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: