Compare commits
No commits in common. "wip/rebasable-branch-for-bean-query-goofy" and "master" have entirely different histories.
wip/rebasa
...
master
1 changed files with 29 additions and 48 deletions
|
|
@ -28,12 +28,10 @@ $ENV{PAGER} = "/usr/bin/cat";
|
||||||
|
|
||||||
my $BEANCOUNT_QUERY_CMD = "/usr/bin/bean-query";
|
my $BEANCOUNT_QUERY_CMD = "/usr/bin/bean-query";
|
||||||
|
|
||||||
my($VERBOSE, $BEANCOUNT_DIR, $LOAD_FILE, $BRANCH_NAME, $REBASE_BRANCH, $FIFO_DIR, $CLEAR_FILES, $GLUE) = (0, undef, undef, undef, undef, undef, 1, 'BeAn');
|
my($VERBOSE, $BEANCOUNT_DIR, $LOAD_FILE, $BRANCH_NAME, $FIFO_DIR, $CLEAR_FILES, $GLUE) = (0, undef, undef, undef, undef, 1, 'BeAn');
|
||||||
|
|
||||||
GetOptions("verbose=i" => \$VERBOSE, "beancountDir=s" => \$BEANCOUNT_DIR, 'glue=s' => \$GLUE, 'clearFiles!', \$CLEAR_FILES,
|
GetOptions("verbose=i" => \$VERBOSE, "beancountDir=s" => \$BEANCOUNT_DIR, 'glue=s' => \$GLUE, 'clearFiles!', \$CLEAR_FILES,
|
||||||
"loadFile=s" => \$LOAD_FILE, "branchName=s" => \$BRANCH_NAME,
|
"loadFile=s" => \$LOAD_FILE, "branchName=s" => \$BRANCH_NAME, 'fifoDir=s' => \$FIFO_DIR);
|
||||||
'rebaseBranch=s' => \$REBASE_BRANCH,
|
|
||||||
'fifoDir=s' => \$FIFO_DIR);
|
|
||||||
|
|
||||||
sub UsageAndExit($) {
|
sub UsageAndExit($) {
|
||||||
print STDERR "usage: $0 --loadFile=/path/to/file.beancount --beancountDir=/path/to/beancountdir --fifoDir=/path/to/directory/for/fifos [ --glue=FOUR_CHAR_STRING --branchName=BRANCH_NAME --verbose=N ]\n";
|
print STDERR "usage: $0 --loadFile=/path/to/file.beancount --beancountDir=/path/to/beancountdir --fifoDir=/path/to/directory/for/fifos [ --glue=FOUR_CHAR_STRING --branchName=BRANCH_NAME --verbose=N ]\n";
|
||||||
|
|
@ -56,18 +54,15 @@ UsageAndExit("glue must be at exactly four characters")
|
||||||
my($tempRepository, $tempRepositoryDirectory);
|
my($tempRepository, $tempRepositoryDirectory);
|
||||||
|
|
||||||
sub CleanupEvertything {
|
sub CleanupEvertything {
|
||||||
# $tempRepository = undef if (defined $tempRepository);
|
$tempRepository = undef if (defined $tempRepository);
|
||||||
# $tempRepositoryDirectory = undef if (defined $tempRepositoryDirectory);
|
$tempRepositoryDirectory = undef if (defined $tempRepositoryDirectory);
|
||||||
StopRunningBeanQuery();
|
StopRunningBeanQuery();
|
||||||
croak @_;
|
croak @_;
|
||||||
}
|
}
|
||||||
UsageAndExit("--rebaseBranch can only be used in conjunction with --branchName")
|
|
||||||
if (defined $REBASE_BRANCH) and (not defined $BRANCH_NAME);
|
|
||||||
|
|
||||||
if (defined $BRANCH_NAME) {
|
if (defined $BRANCH_NAME) {
|
||||||
my $absGitRepositoryDirectory = File::Spec->rel2abs( $BEANCOUNT_DIR );
|
my $absGitRepositoryDirectory = File::Spec->rel2abs( $BEANCOUNT_DIR );
|
||||||
$tempRepositoryDirectory = tempdir('beancountquerygoofydaemongit_' . $$ . '_XXXXXXXXXXX',
|
$tempRepositoryDirectory = tempdir('beancountquerygoofydaemongit_' . $$ . '_XXXXXXXXXXX',
|
||||||
TMPDIR => 1); #, CLEANUP => 1);
|
TMPDIR => 1, CLEANUP => 1);
|
||||||
print STDERR "Copy Git repository to $tempRepositoryDirectory...." if $VERBOSE > 2;
|
print STDERR "Copy Git repository to $tempRepositoryDirectory...." if $VERBOSE > 2;
|
||||||
system($RSYNC_CMD, '-Ha', "$absGitRepositoryDirectory/", "$tempRepositoryDirectory/");
|
system($RSYNC_CMD, '-Ha', "$absGitRepositoryDirectory/", "$tempRepositoryDirectory/");
|
||||||
print STDERR "copy completed.\n" if $VERBOSE > 2;
|
print STDERR "copy completed.\n" if $VERBOSE > 2;
|
||||||
|
|
@ -77,54 +72,40 @@ if (defined $BRANCH_NAME) {
|
||||||
$tempRepository->run(clean => '-fx', { quiet => 1 });
|
$tempRepository->run(clean => '-fx', { quiet => 1 });
|
||||||
$tempRepository->run(reset => '--hard', { quiet => 1 });
|
$tempRepository->run(reset => '--hard', { quiet => 1 });
|
||||||
$tempRepository->run(clean => '-fx', { quiet => 1 });
|
$tempRepository->run(clean => '-fx', { quiet => 1 });
|
||||||
$tempRepository->run(checkout => $BRANCH_NAME, { quiet => 1 });
|
$tempRepository->run(checkout => '$BRANCH_NAME', { quiet => 1 });
|
||||||
if (defined $REBASE_BRANCH) {
|
|
||||||
$tempRepository->run(rebase => $REBASE_BRANCH, { quiet => 1 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
######################################################################
|
|
||||||
sub CheckUpstreamAndPull {
|
sub CheckUpstreamAndPull {
|
||||||
# Returns true iff. a pull was required and the files have changed.
|
# Returns true iff. a pull was required and the files have changed.
|
||||||
return 0 unless (defined $tempRepository);
|
return 0 unless (defined $tempRepository);
|
||||||
my($retVal, $pullOutput) = (0, "");
|
|
||||||
my $options = { quiet => 1 };
|
my $options = { quiet => 1 };
|
||||||
if ($VERBOSE > 5) {
|
if ($VERBOSE > 5) {
|
||||||
print STDERR "...clean & git pull...";
|
print STDERR "...clean & git pull...";
|
||||||
$options = {};
|
$options = {};
|
||||||
}
|
}
|
||||||
print STDERR "...for check if upstream Git changed..." if $VERBOSE > 5;
|
print STDERR "...check if upstream Git changed..." if $VERBOSE > 5;
|
||||||
foreach my $branch ($REBASE_BRANCH, $BRANCH_NAME) {
|
my $updateOutput = $tempRepository->run(remote => 'update', $options);
|
||||||
next unless defined $branch;
|
print "$updateOutput" if defined $updateOutput and $updateOutput !~ /^\s*$/ and $VERBOSE > 5;
|
||||||
print STDERR "...checking $branch now..." if $VERBOSE > 5;
|
my $curRev = $tempRepository->run('rev-parse' => '@');
|
||||||
$tempRepository->run(checkout => $branch, $options);
|
my $remoteRev = $tempRepository->run('rev-parse' => '@{u}');
|
||||||
my $updateOutput = $tempRepository->run(remote => 'update', $options);
|
my $baseRev = $tempRepository->run('merge-base' => '@', '@{u}');
|
||||||
print "$updateOutput" if defined $updateOutput and $updateOutput !~ /^\s*$/ and $VERBOSE > 5;
|
print STDERR "...$curRev is current, $remoteRev is remote Rev $baseRev is base...\n" if $VERBOSE > 6;
|
||||||
my $curRev = $tempRepository->run('rev-parse' => '@');
|
if ($curRev eq $remoteRev) {
|
||||||
my $remoteRev = $tempRepository->run('rev-parse' => '@{u}');
|
print STDERR "no change..." if $VERBOSE > 5;
|
||||||
my $baseRev = $tempRepository->run('merge-base' => '@', '@{u}');
|
return 0;
|
||||||
print STDERR "...on $branch, $curRev is current, $remoteRev is remote Rev $baseRev is base...\n" if $VERBOSE > 6;
|
} elsif ($curRev eq $baseRev) {
|
||||||
if ($curRev eq $remoteRev) {
|
$tempRepository->run(clean => '-fx', $options);
|
||||||
print STDERR "$branch: no change..." if $VERBOSE > 5;
|
$tempRepository->run(reset => '--hard', $options);
|
||||||
next;
|
$tempRepository->run(clean => '-fx', $options);
|
||||||
} elsif ($curRev eq $baseRev) {
|
my $pullOutput = $tempRepository->run('pull');
|
||||||
$tempRepository->run(clean => '-fx', $options);
|
print STDERR "\nPerformed pull since remote updated:\n $pullOutput\n" if ($VERBOSE > 0);
|
||||||
$tempRepository->run(reset => '--hard', $options);
|
return 1;
|
||||||
$tempRepository->run(clean => '-fx', $options);
|
} else {
|
||||||
my $pullOutput = "";
|
CleanupEvertything();
|
||||||
$pullOutput .= $tempRepository->run('pull');
|
die("our local Git has $curRev, upstream is at $remoteRev, and the base is $baseRev " .
|
||||||
$retVal = 1;
|
"so give up entirely on trying to make this work.");
|
||||||
} else {
|
|
||||||
CleanupEvertything("our local Git has $curRev, upstream is at $remoteRev, and the base is $baseRev " .
|
|
||||||
"so give up entirely on trying to make this work.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (defined $REBASE_BRANCH) {
|
|
||||||
$tempRepository->run(checkout => $BRANCH_NAME, $options);
|
|
||||||
$tempRepository->run(rebase => $REBASE_BRANCH, $options) if $retVal > 0;
|
|
||||||
}
|
|
||||||
return $retVal;
|
|
||||||
}
|
}
|
||||||
######################################################################
|
|
||||||
my %options = (
|
my %options = (
|
||||||
create => 'yes',
|
create => 'yes',
|
||||||
exclusive => 0,
|
exclusive => 0,
|
||||||
|
|
@ -168,7 +149,7 @@ sub StartRunningBeanQuery {
|
||||||
push(@cmd, $LOAD_FILE);
|
push(@cmd, $LOAD_FILE);
|
||||||
print STDERR "Starting beancount..." if $VERBOSE > 4;
|
print STDERR "Starting beancount..." if $VERBOSE > 4;
|
||||||
$runningBeanQuery = Expect->spawn(@cmd);
|
$runningBeanQuery = Expect->spawn(@cmd);
|
||||||
print STDERR "...spawned & loading data..." if $VERBOSE > 4;
|
print STDERR "...spawned & loading data..." if $VERBOSE > 4;
|
||||||
$runningBeanQuery->log_stdout(0);
|
$runningBeanQuery->log_stdout(0);
|
||||||
$runningBeanQuery->expect(undef, -re => '^\s*beancount\s*\>\s*')
|
$runningBeanQuery->expect(undef, -re => '^\s*beancount\s*\>\s*')
|
||||||
or die("Unable to find beancount prompt, output was instead: ".
|
or die("Unable to find beancount prompt, output was instead: ".
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue