diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-10-04 17:13:43 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-10-27 00:11:09 +0400 |
commit | 233884131d123432d2e1ad7236ad3c6ef7b2b518 (patch) | |
tree | 7badf8a263468f8cba00a1568b4fc06cf25b17c1 /src/stash.c | |
parent | 590fb68be087ed8a60323026dc2501c456ede945 (diff) |
stash: add git_stash_foreach()
Diffstat (limited to 'src/stash.c')
-rw-r--r-- | src/stash.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/stash.c b/src/stash.c index e63ee99e3..ed0b20f93 100644 --- a/src/stash.c +++ b/src/stash.c @@ -575,3 +575,45 @@ cleanup: git_index_free(index); return error; } + +int git_stash_foreach( + git_repository *repo, + stash_cb callback, + void *payload) +{ + git_reference *stash; + git_reflog *reflog = NULL; + int error; + size_t i, max; + const git_reflog_entry *entry; + + error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE); + if (error == GIT_ENOTFOUND) + return 0; + + if (error < 0) + goto cleanup; + + if ((error = git_reflog_read(&reflog, stash)) < 0) + goto cleanup; + + max = git_reflog_entrycount(reflog); + for (i = 0; i < max; i++) { + entry = git_reflog_entry_byindex(reflog, max - i - 1); + + if (callback(i, + git_reflog_entry_msg(entry), + git_reflog_entry_oidnew(entry), + payload)) { + error = GIT_EUSER; + goto cleanup; + } + } + + error = 0; + +cleanup: + git_reference_free(stash); + git_reflog_free(reflog); + return error; +} |