summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-16 16:36:38 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-16 16:44:16 +0200
commitd4490cb5e98ffb0fb073165f26cf5cffbdf0e1ff (patch)
tree7e38fd45094f6f39dc7ccb6004043d38bcb2b191
parent2376fcab86e719c8838ba4011c74d08444461405 (diff)
downloadlibgit2-cmn/reference-lock.tar.gz
start of stashcmn/reference-lock
-rw-r--r--src/stash.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/stash.c b/src/stash.c
index 5bd948815..5c8e4f3ec 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -599,9 +599,9 @@ int git_stash_drop(
git_repository *repo,
size_t index)
{
- git_reference *stash;
+ git_reference *stash = NULL;
git_reflog *reflog = NULL;
- git_reference_transaction *txn;
+ git_reference_transaction *txn = NULL;
size_t max;
int error;
@@ -609,7 +609,7 @@ int git_stash_drop(
return error;
if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0)
- return error;
+ goto cleanup;
if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE)) < 0)
goto cleanup;
@@ -622,17 +622,18 @@ int git_stash_drop(
goto cleanup;
}
+ if (max == 1) {
+ error = git_reference_delete(stash);
+ goto cleanup;
+ }
+
if ((error = git_reflog_drop(reflog, index, true)) < 0)
goto cleanup;
- if ((error = git_reflog_write(reflog)) < 0)
+ if ((error = git_reference_commit(txn, reflog)) < 0)
goto cleanup;
- if (max == 1) {
- error = git_reference_delete(stash);
- git_reference_free(stash);
- stash = NULL;
- } else if (index == 0) {
+ if (index == 0) {
const git_reflog_entry *entry;
entry = git_reflog_entry_byindex(reflog, 0);
@@ -646,6 +647,7 @@ int git_stash_drop(
}
cleanup:
+ git_reference_transaction_free(txn);
git_reference_free(stash);
git_reflog_free(reflog);
return error;