From: Junio C Hamano Date: Fri, 13 Aug 2010 00:49:37 GMT Subject: Re: [PATCH v4 3/9] stash: introduce is_stash_ref and assert_stash_ref functions. Message-ID: <7v39ujnxpa.fsf@alter.siamese.dyndns.org> In-Reply-To: <1281398688-21008-4-git-send-email-jon.seymour@gmail.com> Jon Seymour writes: > Introduce a function, is_stash_ref, which checks whether an > argument is valid stash reference (e.g. is of the form ['refs/']stash['@{'something'}]) > > Introduce a function, assert_stash_ref, which can be used to ensure > that certain commands are only called with stash references as > arguments. > > Signed-off-by: Jon Seymour > --- > git-stash.sh | 9 +++++++++ > 1 files changed, 9 insertions(+), 0 deletions(-) > > diff --git a/git-stash.sh b/git-stash.sh > index dbb7944..41a9359 100755 > --- a/git-stash.sh > +++ b/git-stash.sh > @@ -223,6 +223,15 @@ show_stash () { > git diff $flags $b_commit $w_commit > } > > +is_stash_ref() { > + revs="$(git rev-parse --revs-only --symbolic --verify --default ${ref_stash} "$@")" && > + test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${revs%@*}")" > +} > + > +assert_stash_ref() { > + is_stash_ref "$@" || die "$* is not a stash reference" > +} I have to wonder what these functions would do when given more than one args, but I cannot (yet) see the users of this function, which may be doing their own sanity checking to avoid that situation, so...