From: William Pursell <bill.pursell@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/2] Add / command in add --patch (feature request)
Date: Wed, 26 Nov 2008 20:51:20 +0000 [thread overview]
Message-ID: <492DB6C8.7010205@gmail.com> (raw)
This sequence of 2 patches adds a '/' command to
add --patch that allows the user to search for
a hunk that matches a regex, and deals with j,k slightly
more gracefully. (Rather than printing the
help menu if k is invalid, it will print
a relevant error message.)
This is naive, and it is easy for an invalid
search string to cause a perl error.
I think it could be useful functionality to make
robust.
(Please CC me in any response)
---
git-add--interactive.perl | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b0223c3..7ad4ee0 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -876,12 +876,14 @@ sub patch_update_file {
$num = scalar @hunk;
$ix = 0;
+ my $search_s; # User entered string to match a hunk.
while (1) {
my ($prev, $next, $other, $undecided, $i);
$other = '';
if ($num <= $ix) {
+ $search_s = 0;
$ix = 0;
}
for ($i = 0; $i < $ix; $i++) {
@@ -916,11 +918,24 @@ sub patch_update_file {
$other .= '/s';
}
$other .= '/e';
- for (@{$hunk[$ix]{DISPLAY}}) {
- print;
+
+ my $line;
+ if( $search_s ) {
+ my $text = join( "", @{$hunk[$ix]{DISPLAY}} );
+ if( $text !~ $search_s ) {
+ $line = "n\n";
+ } else {
+ print $text;
+ }
+ } else {
+ for (@{$hunk[$ix]{DISPLAY}}) {
+ print;
+ }
+ }
+ if (!$line) {
+ print colored $prompt_color, "Stage this hunk [y/n/a/d///$other/?]? ";
+ $line = <STDIN>;
}
- print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? ";
- my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {
$hunk[$ix]{USE} = 1;
@@ -946,6 +961,9 @@ sub patch_update_file {
}
next;
}
+ elsif ($line =~ m|^/(.*)|) {
+ $search_s = $1;
+ }
elsif ($other =~ /K/ && $line =~ /^K/) {
$ix--;
next;
--
1.6.0.4.781.gf2070.dirty
--
William Pursell
next reply other threads:[~2008-11-26 20:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 20:51 William Pursell [this message]
2008-11-26 21:55 ` [PATCH 1/2] Add / command in add --patch (feature request) Junio C Hamano
2008-11-26 22:38 ` Jeff King
2008-11-26 22:54 ` Junio C Hamano
2008-11-27 6:02 ` William Pursell
2008-11-27 6:41 ` Junio C Hamano
2008-11-27 1:46 ` Johannes Schindelin
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=492DB6C8.7010205@gmail.com \
--to=bill.pursell@gmail.com \
--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