[Bps-public-commit] r14308 - in Pushmi/branches/lock: . lib/Pushmi lib/Pushmi/Command

clkao at bestpractical.com clkao at bestpractical.com
Fri Jul 18 22:29:43 EDT 2008


Author: clkao
Date: Fri Jul 18 22:29:42 2008
New Revision: 14308

Added:
   Pushmi/branches/lock/lib/Pushmi/Command/Runlock.pm
   Pushmi/branches/lock/t/lock.t
Modified:
   Pushmi/branches/lock/MANIFEST
   Pushmi/branches/lock/lib/Pushmi/Mirror.pm
   Pushmi/branches/lock/lib/Pushmi/Test.pm

Log:
pre-lock hook that locks the master first.


Modified: Pushmi/branches/lock/MANIFEST
==============================================================================
--- Pushmi/branches/lock/MANIFEST	(original)
+++ Pushmi/branches/lock/MANIFEST	Fri Jul 18 22:29:42 2008
@@ -21,6 +21,7 @@
 lib/Pushmi/Command/Help.pm
 lib/Pushmi/Command/Mirror.pm
 lib/Pushmi/Command/Runhook.pm
+lib/Pushmi/Command/Runlock.pm
 lib/Pushmi/Command/Sync.pm
 lib/Pushmi/Command/Tryauth.pm
 lib/Pushmi/Command/Unlock.pm

Added: Pushmi/branches/lock/lib/Pushmi/Command/Runlock.pm
==============================================================================
--- (empty file)
+++ Pushmi/branches/lock/lib/Pushmi/Command/Runlock.pm	Fri Jul 18 22:29:42 2008
@@ -0,0 +1,53 @@
+package Pushmi::Command::Runlock;
+use strict;
+use warnings;
+use base 'Pushmi::Command';
+my $logger = Pushmi::Config->logger('pushmi.runlock');
+
+sub options {
+    ( 'path=s'    => 'path',
+      'user=s'    => 'user',
+      'comment=s' => 'comment',
+      'steal'     => 'steal' );
+}
+
+sub run {
+    my ($self, $repospath) = @_;
+    die "repospath required" unless $repospath;
+
+    my $pushmi = Pushmi::Mirror->new( path => $repospath );
+    $pushmi->ensure_consistency;
+
+    my $t = $pushmi->root_svkpath;
+
+    my ($mirror) = $t->is_mirrored;
+    my $ra = $mirror->_backend->_new_ra;
+    my $lock_path = substr($self->{path}, 1);
+    $ra->lock({ $lock_path => -1 }, $self->{comment}, $self->{steal},
+          sub { my ($path, $locked, $lock, $err, $pool) = @_;
+                print $lock->token if $lock;
+            });
+    exit 0;
+}
+
+=head1 NAME
+
+Pushmi::Command::Runlock - svn lock preprocessing
+
+=head1 SYNOPSIS
+
+ runlock
+
+=head1 OPTIONS
+
+
+=head1 DESCRIPTION
+
+The command tries to lock the master and output the token on success
+to be used by the replica.
+
+This is not intended to be invoked manually.
+
+=cut
+
+1;

Modified: Pushmi/branches/lock/lib/Pushmi/Mirror.pm
==============================================================================
--- Pushmi/branches/lock/lib/Pushmi/Mirror.pm	(original)
+++ Pushmi/branches/lock/lib/Pushmi/Mirror.pm	Fri Jul 18 22:29:42 2008
@@ -118,6 +118,17 @@
 
 END
 
+    _install_hook( $self->path, 'pre-lock', << "END");
+#!/bin/sh
+export SVKNOSVNCONFIG=1
+export PUSHMI_CONFIG=$ENV{PUSHMI_CONFIG}
+export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}
+export DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}
+export PATH=$ENV{PATH}
+$perl $pushmi runlock "\$1" --path "\$2" --user "\$3" --comment "\$4" --steal "\$5"
+
+END
+
 }
 
 sub _install_hook {

Modified: Pushmi/branches/lock/lib/Pushmi/Test.pm
==============================================================================
--- Pushmi/branches/lock/lib/Pushmi/Test.pm	(original)
+++ Pushmi/branches/lock/lib/Pushmi/Test.pm	Fri Jul 18 22:29:42 2008
@@ -57,6 +57,12 @@
                     @$arg], undef,
 	_mk_cmp_closure($exp_stdout, $stdout_err), # stdout
 	_mk_cmp_closure($exp_stderr, $stdout_err); # stderr
+
+    unless ($ret) {
+        diag("Exit value: $?");
+        @_ = (0, join(' ', 'svn', @$arg));
+    }
+
     if (@$stdout_err) {
 	@_ = (0, join(' ', 'svn', @$arg));
 	diag("Different in line: ".join(',', @$stdout_err));

Added: Pushmi/branches/lock/t/lock.t
==============================================================================
--- (empty file)
+++ Pushmi/branches/lock/t/lock.t	Fri Jul 18 22:29:42 2008
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More;
+use SVK::Test;
+use Pushmi::Test;
+use Pushmi::Mirror;
+use FindBin;
+
+plan skip_all => 'requires 1.6.0 for lock'
+    if $SVN::Core::VERSION lt '1.6.0';
+
+plan tests => 10;
+
+my ($svk,
+    $uri, $srepos, undef, undef, $scorpath,
+    $muri, $repos, undef, $copath, undef ) = build_basic_test_ok();
+
+is_svn_output(['co', $muri, $copath],
+	      ['A    t/checkout/basic-svn/A',
+	       'Checked out revision 1.']);
+chdir($copath);
+overwrite_file("fromsvn.txt", "orz\n");
+is_svn_output(['add', 'fromsvn.txt'],
+	      ['A         fromsvn.txt']);
+is_svn_output(['ci', -m => 'add fromsvn'],
+	      ['Adding         fromsvn.txt',
+	       'Transmitting file data .',
+	       'Committed revision 2.']);
+is($srepos->fs->youngest_rev, 2, 'committed via hook');
+
+is_svn_output(['lock', -m => 'lock from slave', 'fromsvn.txt'],
+              ["'fromsvn.txt' locked by user 'clkao'."]);
+my $lock = $repos->fs->get_lock('/fromsvn.txt');
+$lock = $lock->token if $lock;
+ok($lock, 'has lock on slave');
+my $lock2 = $srepos->fs->get_lock('/fromsvn.txt');
+$lock2 = $lock2->token if $lock;
+ok($lock2, 'has lock on master');
+
+is($lock, $lock2, 'lock token are identical');



More information about the Bps-public-commit mailing list