diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-10-08 20:07:55 +0200 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-10-26 22:11:15 +0200 |
commit | e4c64cf2aa77a97824db4d2700ca507278ef857d (patch) | |
tree | a6d3a4dfc7cf11099129da13de34c8af27ace49e /src/stash.c | |
parent | 233884131d123432d2e1ad7236ad3c6ef7b2b518 (diff) | |
download | libgit2-e4c64cf2aa77a97824db4d2700ca507278ef857d.tar.gz |
stash: add git_stash_drop()
Diffstat (limited to 'src/stash.c')
-rw-r--r-- | src/stash.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/stash.c b/src/stash.c index ed0b20f93..3011f00f0 100644 --- a/src/stash.c +++ b/src/stash.c @@ -617,3 +617,43 @@ cleanup: git_reflog_free(reflog); return error; } + +int git_stash_drop( + git_repository *repo, + size_t index) +{ + git_reference *stash; + git_reflog *reflog = NULL; + size_t max; + int error; + + if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0) + return error; + + if ((error = git_reflog_read(&reflog, stash)) < 0) + goto cleanup; + + max = git_reflog_entrycount(reflog); + + if (index > max - 1) { + error = GIT_ENOTFOUND; + giterr_set(GITERR_STASH, "No stashed state at position %" PRIuZ, index); + goto cleanup; + } + + if ((error = git_reflog_drop(reflog, max - index - 1, true)) < 0) + goto cleanup; + + if ((error = git_reflog_write(reflog)) < 0) + goto cleanup; + + if (max == 1) { + error = git_reference_delete(stash); + stash = NULL; + } + +cleanup: + git_reference_free(stash); + git_reflog_free(reflog); + return error; +} |