Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_file option to read events from other sources #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions git-cal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Data::Dumper;

binmode(STDOUT, ":utf8");
#command line options
my ( $help, $period, $use_ascii, $use_ansi, $use_unicode, $format, $author, $filepath, $all_branches );
my ( $help, $period, $use_ascii, $use_ansi, $use_unicode, $format, $author, $filepath, $event_file, $all_branches );

GetOptions(
'help|?' => \$help,
Expand All @@ -20,6 +20,7 @@ GetOptions(
'ansi' => \$use_ansi,
'unicode' => \$use_unicode,
'author=s' => \$author,
'from_file=s' => \$event_file,
'all' => \$all_branches
) or pod2usage(2);

Expand Down Expand Up @@ -61,7 +62,11 @@ sub process {
: 'ansi';
}
init_cal_stuff();
process_current_repo();
if ($event_file) {
process_from_file($event_file);
} else {
process_current_repo();
}
my %stats = compute_stats();
print_grid(%stats);
}
Expand All @@ -86,6 +91,28 @@ sub process_current_repo {
}
}

sub process_from_file {
my $fh;
my @epochs;
my $file = shift(@_);
if ($file ne '-') {
open ($fh, '<', $file) or die "Error: Could not open file '$file'";
@epochs = <$fh>;
} else {
@epochs = <STDIN>;
}

if ( !@epochs ) {
print "git-cal: got empty log, nothing to do\n";
exit(1);
}
my $status;
foreach (@epochs) {
$status = add_epoch($_);
last if !$status;
}
}

sub git_command {
my $command = qq{git log --no-merges --pretty=format:"%at" --since="13 months"};
$command .= qq{ --author="$author"} if $author;
Expand Down Expand Up @@ -439,6 +466,8 @@ Activity can be displayed using ascii, ansi or unicode characters, default is ch

git-cal --ansi

git-cal --from_file=<timestamp_file>

git-cal --unicode

git-cal <options> <filepath>
Expand Down Expand Up @@ -479,6 +508,11 @@ Display activity using ASCII characters instead of ANSI colors.

Display activity using ANSI colors

=item --from_file

Display activity from a (non-git) file of newline separated timestamps.
Alternatively read timestamps from stdin if the filename '-' is given.

=item --unicode

Display activity using unicode characters
Expand Down