summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2008-03-27 03:30:43 -0400
committerJunio C Hamano <gitster@pobox.com>2008-03-27 13:54:56 -0700
commitb717a627629e6886956af54274d507b9711d49e6 (patch)
tree8cf5348654fe216e1af3287984b91dd28f2bab8b /git-add--interactive.perl
parent1768905b51601d5d080168059acd24d13b888a2d (diff)
downloadgit-b717a627629e6886956af54274d507b9711d49e6.tar.gz
add--interactive: ignore mode change in 'p'atch command
When a path is examined in the patch subcommand, any mode changes in the file are given to use in the diff header by git-diff. If no hunks are staged, then we throw out that header and do not touch the path. But if _any_ hunks are staged, we use the header, and the mode is changed together with the contents. Since the 'p'atch command should just be dealing with hunks that are shown to the user, it makes sense to just ignore mode changes entirely. We do squirrel away the mode, though, since the next patch will allow users to select the mode update separately. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl16
1 files changed, 16 insertions, 0 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index a0a81f134a..5cdda29c54 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -550,6 +550,21 @@ sub parse_diff {
return @hunk;
}
+sub parse_diff_header {
+ my $src = shift;
+
+ my $head = { TEXT => [], DISPLAY => [] };
+ my $mode = { TEXT => [], DISPLAY => [] };
+
+ for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
+ my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
+ $mode : $head;
+ push @{$dest->{TEXT}}, $src->{TEXT}->[$i];
+ push @{$dest->{DISPLAY}}, $src->{DISPLAY}->[$i];
+ }
+ return ($head, $mode);
+}
+
sub hunk_splittable {
my ($text) = @_;
@@ -795,6 +810,7 @@ sub patch_update_file {
my ($ix, $num);
my $path = shift;
my ($head, @hunk) = parse_diff($path);
+ ($head, my $mode) = parse_diff_header($head);
for (@{$head->{DISPLAY}}) {
print;
}