X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=git-add--interactive.perl;h=ee3d812695fa232f30682b0e546105ca0eea5d49;hb=826fb177068a0b0a2dec0d3e05e64521c4d0160e;hp=d948aa88dba11d1d7d87f6a523c698cf4f4848f1;hpb=189627cd588c2937de7b655595b8ed777f445c85;p=platform%2Fupstream%2Fgit.git diff --git a/git-add--interactive.perl b/git-add--interactive.perl index d948aa8..ee3d812 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -44,6 +44,11 @@ my ($diff_new_color) = my $normal_color = $repo->get_color("", "reset"); +my $diff_algorithm = $repo->config('diff.algorithm'); +my $diff_indent_heuristic = $repo->config_bool('diff.indentheuristic'); +my $diff_compaction_heuristic = $repo->config_bool('diff.compactionheuristic'); +my $diff_filter = $repo->config('interactive.difffilter'); + my $use_readkey = 0; my $use_termcap = 0; my %term_escapes; @@ -56,6 +61,9 @@ if ($repo->config_bool("interactive.singlekey")) { Term::ReadKey->import; $use_readkey = 1; }; + if (!$use_readkey) { + print STDERR "missing Term::ReadKey, disabling interactive.singlekey\n"; + } eval { require Term::Cap; my $termcap = Term::Cap->Tgetent; @@ -167,7 +175,7 @@ my %patch_modes = ( my %patch_mode_flavour = %{$patch_modes{stage}}; sub run_cmd_pipe { - if ($^O eq 'MSWin32' || $^O eq 'msys') { + if ($^O eq 'MSWin32') { my @invalid = grep {m/[":*]/} @_; die "$^O does not support: @invalid\n" if @invalid; my @args = map { m/ /o ? "\"$_\"": $_ } @_; @@ -261,6 +269,17 @@ sub get_empty_tree { return '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; } +sub get_diff_reference { + my $ref = shift; + if (defined $ref and $ref ne 'HEAD') { + return $ref; + } elsif (is_initial_commit()) { + return get_empty_tree(); + } else { + return 'HEAD'; + } +} + # Returns list of hashes, contents of each of which are: # VALUE: pathname # BINARY: is a binary path @@ -284,14 +303,7 @@ sub list_modified { return if (!@tracked); } - my $reference; - if (defined $patch_mode_revision and $patch_mode_revision ne 'HEAD') { - $reference = $patch_mode_revision; - } elsif (is_initial_commit()) { - $reference = get_empty_tree(); - } else { - $reference = 'HEAD'; - } + my $reference = get_diff_reference($patch_mode_revision); for (run_cmd_pipe(qw(git diff-index --cached --numstat --summary), $reference, '--', @tracked)) { @@ -506,6 +518,9 @@ sub error_msg { sub list_and_choose { my ($opts, @stuff) = @_; my (@chosen, @return); + if (!@stuff) { + return @return; + } my $i; my @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY}; @@ -716,6 +731,8 @@ sub add_untracked_cmd { if (@add) { system(qw(git update-index --add --), @add); say_n_paths('added', @add); + } else { + print "No untracked files.\n"; } print "\n"; } @@ -731,13 +748,28 @@ sub run_git_apply { sub parse_diff { my ($path) = @_; my @diff_cmd = split(" ", $patch_mode_flavour{DIFF}); + if (defined $diff_algorithm) { + splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}"; + } + if ($diff_indent_heuristic) { + splice @diff_cmd, 1, 0, "--indent-heuristic"; + } elsif ($diff_compaction_heuristic) { + splice @diff_cmd, 1, 0, "--compaction-heuristic"; + } if (defined $patch_mode_revision) { - push @diff_cmd, $patch_mode_revision; + push @diff_cmd, get_diff_reference($patch_mode_revision); } my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path); my @colored = (); if ($diff_use_color) { - @colored = run_cmd_pipe("git", @diff_cmd, qw(--color --), $path); + my @display_cmd = ("git", @diff_cmd, qw(--color --), $path); + if (defined $diff_filter) { + # quotemeta is overkill, but sufficient for shell-quoting + my $diff = join(' ', map { quotemeta } @display_cmd); + @display_cmd = ("$diff | $diff_filter"); + } + + @colored = run_cmd_pipe(@display_cmd); } my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' }; @@ -748,7 +780,7 @@ sub parse_diff { } push @{$hunk[-1]{TEXT}}, $diff[$i]; push @{$hunk[-1]{DISPLAY}}, - ($diff_use_color ? $colored[$i] : $diff[$i]); + (@colored ? $colored[$i] : $diff[$i]); } return @hunk; } @@ -1067,7 +1099,6 @@ EOF } sub diff_applies { - my $fh; return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check', map { @{$_->{TEXT}} } @_); } @@ -1148,9 +1179,9 @@ sub help_patch_cmd { print colored $help_color, <{TEXT}, @result); my $apply_routine = $patch_mode_flavour{APPLY}; &$apply_routine(@patch);