From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] ssoma-rm: do not commit changes on auto-removal miss
Date: Sat, 26 Sep 2015 01:12:57 +0000 [thread overview]
Message-ID: <20150926011257.15583-1-e@80x24.org> (raw)
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
reply other threads:[~2015-09-26 1:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150926011257.15583-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).