* [PATCH] ssoma-rm: do not commit changes on auto-removal miss
@ 2015-09-26 1:12 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-09-26 1:12 UTC (permalink / raw)
To: meta; +Cc: Eric Wong
No-op removals should be idempotent, as multiple reporters
may attempt to remove the same message at nearly the same
time.
---
lib/Ssoma/Git.pm | 2 +-
lib/Ssoma/Remover.pm | 4 +++-
t/remover.t | 18 ++++++++++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/lib/Ssoma/Git.pm b/lib/Ssoma/Git.pm
index 60058df..05fa5a3 100644
--- a/lib/Ssoma/Git.pm
+++ b/lib/Ssoma/Git.pm
@@ -215,7 +215,7 @@ sub cat_blob {
sub type {
my ($self, $obj) = @_;
my $cmd = "git cat-file -t $obj";
- my $str = `$cmd`;
+ my $str = `$cmd 2>/dev/null`;
die "$cmd failed: $?\n" if $?;
chomp $str;
$str;
diff --git a/lib/Ssoma/Remover.pm b/lib/Ssoma/Remover.pm
index 5e5872c..184db1a 100644
--- a/lib/Ssoma/Remover.pm
+++ b/lib/Ssoma/Remover.pm
@@ -30,7 +30,8 @@ sub _remove {
my $ref = $self->{ref};
my $tip = $git->qx_sha1("git rev-parse $ref^0");
my $obj = "$tip:$path";
- my $type = $git->type($obj);
+ my $type = eval { $git->type($obj) };
+ return unless defined $type;
my (@keep, @remove);
if ($type eq "tree") { # unlikely
$git->each_in_tree($obj, sub {
@@ -50,6 +51,7 @@ sub _remove {
} else {
die "unhandled type=$type for obj=$obj\n";
}
+ return unless @remove;
my $gii = Ssoma::GitIndexInfo->new;
foreach my $rm (@remove) { $gii->remove($rm) }
diff --git a/t/remover.t b/t/remover.t
index 1d74c02..f714aff 100644
--- a/t/remover.t
+++ b/t/remover.t
@@ -82,6 +82,24 @@ EOF
$expect--;
is(scalar @tree, $expect, "$expect messages left");
}
+
+ {
+ local $ENV{GIT_DIR} = $git_dir;
+ my $before = `git rev-parse HEAD^0`;
+ $rm->remove_simple($email);
+ my $after = `git rev-parse HEAD^0`;
+ is($before, $after, 'no commit on no-op removal');
+ }
+
+ {
+ local $ENV{GIT_DIR} = $git_dir;
+ $mda->deliver($email);
+ my $before = `git rev-parse HEAD^0`;
+ $email->body_set('changed');
+ $rm->remove_simple($email);
+ my $after = `git rev-parse HEAD^0`;
+ is($before, $after, 'no commit on no-op removal miss');
+ }
}
done_testing();
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-09-26 1:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-26 1:12 [PATCH] ssoma-rm: do not commit changes on auto-removal miss Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).