git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Brandon Casey <casey@nrlssc.navy.mil>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] git-stash: add new 'drop' subcommand
Date: Fri, 04 Jan 2008 17:47:43 -0800	[thread overview]
Message-ID: <7vtzltf3gg.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <477EDDD4.5060509@nrlssc.navy.mil> (Brandon Casey's message of "Fri, 04 Jan 2008 19:31:00 -0600")

Brandon Casey <casey@nrlssc.navy.mil> writes:

> I'm not sure if there is a proper way to get 'stash@{0}' from
> 'refs/stash' so I kept my usage of that former string outside
> of the drop_stash() function.

Doesn't "$refs_stash@{0}" (which would give refs/stash@{0} not
stash@{0}) work for you?

> diff --git a/git-stash.sh b/git-stash.sh
> index 06cb177..a789a53 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -1,7 +1,7 @@
>  #!/bin/sh
>  # Copyright (c) 2007, Nanako Shiraishi
>  
> -USAGE='[  | save | list | show | apply | clear | create ]'
> +USAGE='[  | save | list | show | apply | clear | create | drop ]'

Might want to put drop next to clear, but that is minor.

> +drop_stash () {
> +	if ! have_stash
> +	then
> +		echo >&2 'No stash entries to drop'
> +		exit 0
> +	fi
> +
> +	# Verify supplied argument looks like a stash entry
> +	s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@") &&
> +	git rev-parse --verify "$s:"   > /dev/null 2>&1 &&
> +	git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
> +	git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
> +		die "$*: not a valid stashed state"
> +
> +	git reflog delete "$@" && echo "Dropped $@ ($s)" ||

The second $@ is inconsistent with the next line's use of $*; intentional?

> +		die "$*: Could not drop stash entry"
> +}

> +drop)
> +	shift
> +	if test $# = 0
> +	then
> +		set -- "stash@{0}"
> +	fi
> +	drop_stash "$@" &&
> +	(git rev-parse --verify "stash@{0}" > /dev/null 2>&1 || clear_stash)

Curious.

 (1) Why not do the clearing inside drop_stash?

 (2) Why is clearning necessary in the first place (iow,
     shouldn't "reflog delete" take care of that)?

Other than that, nicely done.

  reply	other threads:[~2008-01-05  1:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1199495198-26270-1-git-send-email-casey@nrlssc.navy.mil>
2008-01-05  1:31 ` [PATCH] git-stash: add new 'drop' subcommand Brandon Casey
2008-01-05  1:47   ` Junio C Hamano [this message]
2008-01-05  5:46     ` Brandon Casey
2008-01-05  3:51   ` Jeff King
2008-01-05  9:26     ` JM Ibanez
2008-01-05  9:35       ` [PATCH] git-stash clear: refuse to work with extra parameter for now Junio C Hamano
2008-01-05 10:00         ` Jeff King
2008-01-05 12:36   ` [PATCH] git-stash: add new 'drop' subcommand Marco Costalba
2008-01-07 17:12 Brandon Casey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vtzltf3gg.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=casey@nrlssc.navy.mil \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).