Re: [PATCH v4 3/9] stash: introduce is_stash_ref and assert_stash_ref functions.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 13, 2010, 00:49 UTC
- Message-ID
- <7v39ujnxpa.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1281398688-21008-4-git-send-email-jon.seymour@gmail.com>
Jon Seymour <jon.seymour@gmail.com> writes:
Show 28 quoted lines
> 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 <jon.seymour@gmail.com>
> ---
> 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...