chiark / gitweb /
Move stat_exists to Dgit.pm
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Mar 2015 13:41:06 +0000 (13:41 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Mar 2015 15:19:51 +0000 (15:19 +0000)
Debian/Dgit.pm
dgit
infra/dgit-repos-server

index 211bae3a6626d503b6452864aa5815769ba1c6e9..8b29ba2746be30267b9cef7cf73ff60b3d95e25e 100644 (file)
@@ -12,6 +12,7 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(debiantag server_branch server_ref
+                      stat_exists
                       $package_re $branchprefix);
     %EXPORT_TAGS = ( policyflags => qw() );
     @EXPORT_OK   = qw();
@@ -43,4 +44,11 @@ sub debiantag ($) {
 sub server_branch ($) { return "$branchprefix/$_[0]"; }
 sub server_ref ($) { return "refs/".server_branch($_[0]); }
 
+sub stat_exists ($) {
+    my ($f) = @_;
+    return 1 if stat $f;
+    return 0 if $!==&ENOENT;
+    die "stat $f: $!";
+}
+
 1;
diff --git a/dgit b/dgit
index a0144bcde7901c8c702d5a77878f8f841aa29391..ad6289d53411a4ca155484dc48a1699e4ff6f056 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -185,13 +185,6 @@ sub changedir ($) {
     chdir $newdir or die "chdir: $newdir: $!";
 }
 
-sub stat_exists ($) {
-    my ($f) = @_;
-    return 1 if stat $f;
-    return 0 if $!==&ENOENT;
-    die "stat $f: $!";
-}
-
 sub deliberately ($) {
     return !!grep { $_[0] eq $_ } @deliberatelies;
 }
index 5599061de2a68cb8e997c66f2d81e48c489688a9..d2f94f1957e0bed922a0db052e2a81b921fa789a 100755 (executable)
@@ -124,10 +124,7 @@ sub acquirelock ($$) {
            debug " locking $lock failed";
            return undef;
        }
-       if (!stat $lock) {
-           next if $! == ENOENT;
-           die "stat $lock: $!";
-       }
+       next unless stat_exists $lock;
        my $want = (stat _)[1];
        stat $fh or die $!;
        my $got = (stat _)[1];
@@ -267,10 +264,7 @@ END
 
 sub dealwithfreshrepo () {
     my $freshrepo = "${workrepo}_fresh";
-    if (!stat $freshrepo) {
-       $!==ENOENT or die "$freshrepo $!";
-       return;
-    }
+    return unless stat_exists $freshrepo;
     $destrepo = $freshrepo;
 }
 
@@ -596,8 +590,7 @@ sub stunthook () {
 sub fixmissing__git_upload_pack () {
     $destrepo = "$dgitrepos/_empty";
     my $lfh = acquiretree($destrepo,1);
-    return if stat $destrepo;
-    die $! unless $!==ENOENT;
+    return if stat_exists $destrepo;
     rmtree "$destrepo.new";
     mkemptyrepo "$destrepo.new", "0644";
     rename "$destrepo.new", $destrepo or die $!;
@@ -686,10 +679,9 @@ sub parseargsdispatch () {
     }
     close $pollock or die $!;
 
-    if (stat $realdestrepo) {
+    if (stat_exists $realdestrepo) {
        $destrepo = $realdestrepo;
     } else {
-       $! == ENOENT or die "stat dest repo $destrepo: $!";
        debug " fixmissing $funcn";
        my $fixfunc = $main::{"fixmissing__$funcn"};
        &$fixfunc;