git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make git-add -i accept ranges like 7-
@ 2008-07-14 18:06 Ciaran McCreesh
  2008-07-14 18:15 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Ciaran McCreesh @ 2008-07-14 18:06 UTC (permalink / raw)
  To: git; +Cc: Ciaran McCreesh

git-add -i ranges expect number-number. But for the supremely lazy, typing in
that second number when selecting "from patch 7 to the end" is wasted effort.
So treat an empty second number in a range as "until the last item".

Signed-off-by: Ciaran McCreesh <ciaran.mccreesh@googlemail.com>
---
 Documentation/git-add.txt |    5 +++--
 git-add--interactive.perl |    6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 46dd56c..3558905 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -187,8 +187,9 @@ update::
    "Update>>".  When the prompt ends with double '>>', you can
    make more than one selection, concatenated with whitespace or
    comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
-   2,3,4,5,7,9 from the list.  You can say '*' to choose
-   everything.
+   2,3,4,5,7,9 from the list.  If the second number in a range is
+   omitted, all remaining patches are taken.  E.g. "7-" to choose
+   7,8,9 from the list.  You can say '*' to choose everything.
 +
 What you chose are then highlighted with '*',
 like this:
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 801d7c0..72a8858 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -406,9 +406,9 @@ sub list_and_choose {
 			if ($choice =~ s/^-//) {
 				$choose = 0;
 			}
-			# A range can be specified like 5-7
-			if ($choice =~ /^(\d+)-(\d+)$/) {
-				($bottom, $top) = ($1, $2);
+			# A range can be specified like 5-7 or 5-.
+			if ($choice =~ /^(\d*)-(\d*)$/) {
+				($bottom, $top) = ($1, length($2) ? $2 : 1 + @stuff);
 			}
 			elsif ($choice =~ /^\d+$/) {
 				$bottom = $top = $choice;
-- 
1.5.6.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Make git-add -i accept ranges like 7-
  2008-07-14 18:06 [PATCH] Make git-add -i accept ranges like 7- Ciaran McCreesh
@ 2008-07-14 18:15 ` Junio C Hamano
  2008-07-14 18:29   ` [PATCH,v2] " Ciaran McCreesh
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-07-14 18:15 UTC (permalink / raw)
  To: Ciaran McCreesh; +Cc: git

Ciaran McCreesh <ciaran.mccreesh@googlemail.com> writes:

> git-add -i ranges expect number-number. But for the supremely lazy, typing in
> that second number when selecting "from patch 7 to the end" is wasted effort.
> So treat an empty second number in a range as "until the last item".

You didn't describe why you changed the first regexp from \d+ to \d*,
which would allow "-9" as a valid input as well.

But in that case $bottom will become an empty string.  Don't you need to
adjust the users of this data in the codepaths that follow this part?  I
didn't check.

> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 801d7c0..72a8858 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -406,9 +406,9 @@ sub list_and_choose {
>  			if ($choice =~ s/^-//) {
>  				$choose = 0;
>  			}
> -			# A range can be specified like 5-7
> -			if ($choice =~ /^(\d+)-(\d+)$/) {
> -				($bottom, $top) = ($1, $2);
> +			# A range can be specified like 5-7 or 5-.
> +			if ($choice =~ /^(\d*)-(\d*)$/) {
> +				($bottom, $top) = ($1, length($2) ? $2 : 1 + @stuff);
>  			}
>  			elsif ($choice =~ /^\d+$/) {
>  				$bottom = $top = $choice;
> -- 
> 1.5.6.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH,v2] Make git-add -i accept ranges like 7-
  2008-07-14 18:15 ` Junio C Hamano
@ 2008-07-14 18:29   ` Ciaran McCreesh
  0 siblings, 0 replies; 3+ messages in thread
From: Ciaran McCreesh @ 2008-07-14 18:29 UTC (permalink / raw)
  To: gitster; +Cc: git, Ciaran McCreesh

git-add -i ranges expect number-number. But for the supremely lazy, typing in
that second number when selecting "from patch 7 to the end" is wasted effort.
So treat an empty second number in a range as "until the last item".

Signed-off-by: Ciaran McCreesh <ciaran.mccreesh@googlemail.com>
---
Oops, my bad.

Attempt 2 changes the regex to require a number in the first half of the range.
I was planning to allow for -7, meaning 'up to 7', but this collides with - at
the start being used to unchoose things. There's not much point adding a
special thing for 'from the start' though, since '1' is only one character to
type.

 Documentation/git-add.txt |    5 +++--
 git-add--interactive.perl |    6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 46dd56c..3558905 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -187,8 +187,9 @@ update::
    "Update>>".  When the prompt ends with double '>>', you can
    make more than one selection, concatenated with whitespace or
    comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
-   2,3,4,5,7,9 from the list.  You can say '*' to choose
-   everything.
+   2,3,4,5,7,9 from the list.  If the second number in a range is
+   omitted, all remaining patches are taken.  E.g. "7-" to choose
+   7,8,9 from the list.  You can say '*' to choose everything.
 +
 What you chose are then highlighted with '*',
 like this:
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 801d7c0..a6a5c52 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -406,9 +406,9 @@ sub list_and_choose {
 			if ($choice =~ s/^-//) {
 				$choose = 0;
 			}
-			# A range can be specified like 5-7
-			if ($choice =~ /^(\d+)-(\d+)$/) {
-				($bottom, $top) = ($1, $2);
+			# A range can be specified like 5-7 or 5-.
+			if ($choice =~ /^(\d+)-(\d*)$/) {
+				($bottom, $top) = ($1, length($2) ? $2 : 1 + @stuff);
 			}
 			elsif ($choice =~ /^\d+$/) {
 				$bottom = $top = $choice;
-- 
1.5.6.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-14 18:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 18:06 [PATCH] Make git-add -i accept ranges like 7- Ciaran McCreesh
2008-07-14 18:15 ` Junio C Hamano
2008-07-14 18:29   ` [PATCH,v2] " Ciaran McCreesh

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).