diff options
Diffstat (limited to 'src')
| -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; +} |
