#!/usr/bin/perl -w
use strict;
use Git;
binmode(STDOUT, ":raw");
my $repo = Git->repository();
my $menu_use_color = $repo->get_colorbool('color.interactive');
my ($prompt_color, $header_color, $help_color) =
$menu_use_color ? (
$repo->get_color('color.interactive.prompt', 'bold blue'),
$repo->get_color('color.interactive.header', 'bold'),
$repo->get_color('color.interactive.help', 'red bold'),
) : ();
my $error_color = ();
if ($menu_use_color) {
my $help_color_spec = ($repo->config('color.interactive.help') or
'red bold');
$error_color = $repo->get_color('color.interactive.error',
$help_color_spec);
}
my $diff_use_color = $repo->get_colorbool('color.diff');
my ($fraginfo_color) =
$diff_use_color ? (
$repo->get_color('color.diff.frag', 'cyan'),
) : ();
my ($diff_plain_color) =
$diff_use_color ? (
$repo->get_color('color.diff.plain', ''),
) : ();
my ($diff_old_color) =
$diff_use_color ? (
$repo->get_color('color.diff.old', 'red'),
) : ();
my ($diff_new_color) =
$diff_use_color ? (
$repo->get_color('color.diff.new', 'green'),
) : ();
my $normal_color = $repo->get_color("", "reset");
my $use_readkey = 0;
sub ReadMode;
sub ReadKey;
if ($repo->config_bool("interactive.singlekey")) {
eval {
require Term::ReadKey;
Term::ReadKey->import;
$use_readkey = 1;
};
}
sub colored {
my $color = shift;
my $string = join("", @_);
if (defined $color) {
# Put a color code at the beginning of each line, a reset at the end
# color after newlines that are not at the end of the string
$string =~ s/(\n+)(.)/$1$color$2/g;
# reset before newlines
$string =~ s/(\n+)/$normal_color$1/g;
# codes at beginning and end (if necessary):
$string =~ s/^/$color/;
$string =~ s/$/$normal_color/ unless $string =~ /\n$/;
}
return $string;
}
# command line options
my $patch_mode;
my $patch_mode_revision;
sub apply_patch;
sub apply_patch_for_checkout_commit;
sub apply_patch_for_stash;
my %patch_modes = (
'stage' => {
DIFF => 'diff-files -p',
APPLY => sub { apply_patch 'apply --cached', @_; },
APPLY_CHECK => 'apply --cached',
VERB => 'Stage',
TARGET => '',
PARTICIPLE => 'staging',
FILTER => 'file-only',
},
'stash' => {
DIFF => 'diff-index -p HEAD',
APPLY => sub { apply_patch 'apply --cached', @_; },
APPLY_CHECK => 'apply --cached',
VERB => 'Stash',
TARGET => '',
PARTICIPLE =&g
|