my $color_author = 'magenta';
+# Aliases in Git with "! ..." are always run in the top-level-directory.
+# GIT_PREFIX contains the relative path to the current subdirectory. Thanks to
+# dr_lepper in #git on Freenode (2013-04-03 23:17) for telling me about
+# GIT_PREFIX.
+if (defined $ENV{GIT_PREFIX} and $ENV{GIT_PREFIX} ne '') {
+ chdir $ENV{GIT_PREFIX} or die $!;
+}
+
my $format = '%x00' # separator from --graph
. '%h' . '%x00' # abbreviated commit hash
. '%at' . '%x00' # author date
. '%an' . '%x00' # author name
. '%s' . '%x00' # subject
. '%d'; # ref names
-my @cmd = ('git', 'log', '--all', '--graph', "--format=$format");
+my @cmd = ('git', 'log', '--graph', "--format=$format",
+ # use either given arguments or --all to list all commits
+ (scalar @ARGV) ? @ARGV : '--all');
open my $fh, '-|', @cmd or die $!;
my $pager = $ENV{PAGER};
}
# Commit line.
- $line =~ /^([ *|.-]+)\x00(.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/
+ $line =~ /^([ *|.\\-]+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)\x00(.*)$/
or die $line;
my $prefix = $1;
my $hash = colored($2, $color_hash);