We have a function called get_stash_info that looks up this data based on a set of command-line arguments and produces diagnostics to the user on failure. While this is helpful in the existing use cases, we'd like to make use of this logic in a more programmatic way in the future. Split out much of the function into a function which can be used internally and which knows how to suppress these error messages with a quiet parameter. Wire up the rest of the function to call this internal function to preserve the existing behavior. Signed-off-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> --- builtin/stash.c | 50 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index 5897febfbe..2aa06cc91d 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -130,38 +130,21 @@ static void assert_stash_like(struct stash_info *info, const char *revision) die(_("'%s' is not a stash-like commit"), revision); } -static int get_stash_info(struct stash_info *info, int argc, const char **argv) +static int get_stash_info_1(struct stash_info *info, const char *commit, int quiet) { int ret; char *end_of_rev; char *expanded_ref; const char *revision; - const char *commit = NULL; struct object_id dummy; struct strbuf symbolic = STRBUF_INIT; - if (argc > 1) { - int i; - struct strbuf refs_msg = STRBUF_INIT; - - for (i = 0; i < argc; i++) - strbuf_addf(&refs_msg, " '%s'", argv[i]); - - fprintf_ln(stderr, _("Too many revisions specified:%s"), - refs_msg.buf); - strbuf_release(&refs_msg); - - return -1; - } - - if (argc == 1) - commit = argv[0]; - strbuf_init(&info->revision, 0); if (!commit) { if (!ref_exists(ref_stash)) { free_stash_info(info); - fprintf_ln(stderr, _("No stash entries found.")); + if (!quiet) + fprintf_ln(stderr, _("No stash entries found.")); return -1; } @@ -175,7 +158,8 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv) revision = info->revision.buf; if (get_oid(revision, &info->w_commit)) { - error(_("%s is not a valid reference"), revision); + if (!quiet) + error(_("%s is not a valid reference"), revision); free_stash_info(info); return -1; } @@ -204,6 +188,30 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv) return !(ret == 0 || ret == 1); } +static int get_stash_info(struct stash_info *info, int argc, const char **argv) +{ + const char *commit = NULL; + + if (argc > 1) { + int i; + struct strbuf refs_msg = STRBUF_INIT; + + for (i = 0; i < argc; i++) + strbuf_addf(&refs_msg, " '%s'", argv[i]); + + fprintf_ln(stderr, _("Too many revisions specified:%s"), + refs_msg.buf); + strbuf_release(&refs_msg); + + return -1; + } + + if (argc == 1) + commit = argv[0]; + + return get_stash_info_1(info, commit, 0); +} + static int do_clear_stash(void) { struct object_id obj;