annotate tests/fixtures/rsvn.py @ 910:312f36a425f0

Ignore invalid utf8 in commit messages Old svn allowed users to include invalid utf8 in their commits. Since there are real repos with said invalid utf8, we need to be able to import them, even if svn won't.
author David Schleimer <dschleimer@fb.com>
date Thu, 17 May 2012 14:15:14 -0700
parents e9af7eba88db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python2
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
2
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
3 # LICENSE
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
4 #
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
5 # Copyright (c) 2004, Francois Beausoleil
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
6 # All rights reserved.
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
7 #
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
8 # Redistribution and use in source and binary forms, with or without
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
9 # modification, are permitted provided that the following conditions
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
10 # are met:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
11 #
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
12 # * Redistributions of source code must retain the above copyright
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
13 # notice, this list of conditions and the following disclaimer.
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
14 # * Redistributions in binary form must reproduce the above copyright
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
15 # notice, this list of conditions and the following disclaimer in
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
16 # the documentation and/or other materials provided with the
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
17 # distribution.
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
18 # * Neither the name of the Francois Beausoleil nor the names of its
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
19 # contributors may be used to endorse or promote products derived
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
20 # from this software without specific prior written permission.
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
21 #
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
33
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
34 import getopt
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
35 import sys
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
36 import os
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
37 import re
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
38 import traceback
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
39 from svn import core, repos, fs
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
40
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
41 VERSION='$Id: rsvn.py 20 2005-09-23 15:08:08Z fbos $'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
42 RCOPY_RE = re.compile('^\s*rcopy\s+(.+)\s+(.+)$')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
43 RMOVE_RE = re.compile('^\s*rmove\s+(.+)\s+(.+)$')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
44 RMKDIR_RE = re.compile('^\s*rmkdir\s+(.+)$')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
45 RDELETE_RE = re.compile('^\s*rdelete\s+(.+)$')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
46 COMMENT_RE = re.compile('(?:^\s*#)|(?:^\s*$)')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
47
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
48 def usage(error=None):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
49 if error:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
50 print 'Error: %s\n' % error
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
51 print 'USAGE: %s --message=MESSAGE repos_path [--username=USERNAME]' % (
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
52 os.path.basename(sys.argv[0]))
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
53 print ''
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
54 print ' --help, -h print this usage message and exit with success'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
55 print ' --version print the version number'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
56 print ' --username=USERNAME Username to execute the commands under'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
57 print ' --message=LOG_MSG Log message to execute the commit with'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
58 print ''
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
59 print 'Reads STDIN and parses the following commands, to execute them on the server, '
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
60 print 'all within the same transaction:'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
61 print ''
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
62 print ' rcopy SRC DEST Copy the HEAD revision of a file or folder'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
63 print ' rmove SRC DEST Copy + delete the HEAD revision of a file or folder'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
64 print ' rdelete TARGET Deletes something from the repository'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
65 print ' rmkdir TARGET Creates a new folder (must create parents first)'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
66 print ' # Initiates a comment'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
67 print ''
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
68 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
69
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
70
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
71 class Transaction:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
72 """Represents a transaction in a Subversion repository
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
73
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
74 Transactions are long-lived objects which exist in the repository,
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
75 and are used to build an intermediate representation of a new
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
76 revision. Once the transaction is committed, the repository
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
77 bumps the revision number, and links the new transaction in the
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
78 Subversion filesystem."""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
79
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
80 def __init__(self, repository, rev, username, message, pool, logger=None):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
81 if logger:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
82 self.logger = logger
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
83 else:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
84 self.logger = sys.stdout
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
85 self.pool = pool
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
86 self.rev = rev
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
87
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
88 self.fsptr = repos.svn_repos_fs(repository)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
89 self.rev_root = fs.revision_root(self.fsptr, self.rev,
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
90 self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
91 self.txnp = repos.svn_repos_fs_begin_txn_for_commit(
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
92 repository, self.rev, username, message, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
93 self.txn_root = fs.txn_root(self.txnp, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
94 self.log('Base revision %d\n' % rev)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
95
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
96 def commit(self):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
97 values = fs.commit_txn(self.txnp, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
98 return values[1]
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
99
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
100 def rollback(self):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
101 fs.abort_txn(self.txnp, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
102
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
103 def copy(self, src, dest, subpool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
104 self.log('A + %s\n' % dest)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
105 fs.copy(self.rev_root, src, self.txn_root, dest, subpool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
106
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
107 def delete(self, entry, subpool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
108 self.log('D %s\n' % entry)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
109 fs.delete(self.txn_root, entry, subpool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
110
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
111 def mkdir(self, entry, subpool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
112 self.log('A %s\n' % entry)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
113 fs.make_dir(self.txn_root, entry, subpool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
114
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
115 def move(self, src, dest, subpool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
116 self.copy(src, dest, subpool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
117 self.delete(src, subpool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
118
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
119 def log(self, msg):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
120 self.logger.write(msg)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
121
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
122
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
123 class Repository:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
124 """Represents a Subversion repository, and allows common operations
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
125 on it."""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
126
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
127 def __init__(self, repos_path, pool, logger=None):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
128 if logger:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
129 self.logger = logger
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
130 else:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
131 self.logger = sys.stdout
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
132 self.pool = pool
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
133 assert self.pool
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
134
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
135 self.repo = repos.svn_repos_open(repos_path, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
136 self.fsptr = repos.svn_repos_fs(self.repo)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
137
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
138 def get_youngest(self):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
139 """Returns the youngest revision in the repository."""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
140 return fs.youngest_rev(self.fsptr, self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
141
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
142 def begin(self, username, log_msg):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
143 """Initiate a new Transaction"""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
144 return Transaction(self.repo, self.get_youngest(), username,
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
145 log_msg, self.pool, self.logger)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
146
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
147 def close(self):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
148 """Close the repository, aborting any uncommitted transactions"""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
149 core.svn_pool_destroy(self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
150 core.apr_terminate()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
151
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
152 def subpool(self):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
153 """Instantiates a new pool from the master pool"""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
154 return core.svn_pool_create(self.pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
155
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
156 def delete_pool(self, pool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
157 """Deletes the passed-in pool. Returns None, to assign to pool in
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
158 caller."""
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
159 core.svn_pool_destroy(pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
160 return None
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
161
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
162 def rsvn(pool):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
163 log_msg = None
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
164
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
165 try:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
166 opts, args = getopt.getopt(sys.argv[1:], 'vh',
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
167 ["help", "username=", "message=", "version"])
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
168 except getopt.GetoptError, e:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
169 sys.stderr.write(str(e) + '\n\n')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
170 usage()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
171 sys.exit(1)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
172
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
173 for opt, value in opts:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
174 if opt == '--version':
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
175 print '%s version %s' % (os.path.basename(sys.argv[0]), VERSION)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
176 sys.exit(0)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
177 elif opt == '--help' or opt == '-h':
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
178 usage()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
179 sys.exit(0)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
180 elif opt == '--username':
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
181 username = value
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
182 elif opt == '--message':
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
183 log_msg = value
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
184
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
185 if log_msg == None:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
186 usage('Missing --message argument')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
187 sys.exit(1)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
188
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
189 if len(args) != 1:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
190 usage('Missing repository path argument')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
191 sys.exit(1)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
192
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
193 repos_path = args[0]
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
194 print 'Accessing repository at [%s]' % repos_path
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
195
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
196 repository = Repository(repos_path, pool)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
197 sub = repository.subpool()
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
198
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
199 try:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
200 txn = repository.begin(username, log_msg)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
201
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
202 # Read commands from STDIN
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
203 lineno = 0
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
204 for line in sys.stdin:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
205 lineno += 1
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
206
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
207 core.svn_pool_clear(sub)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
208 try:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
209 if COMMENT_RE.search(line):
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
210 continue
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
211
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
212 match = RCOPY_RE.search(line)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
213 if match:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
214 src = match.group(1)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
215 dest = match.group(2)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
216 txn.copy(src, dest, sub)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
217 continue
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
218
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
219 match = RMOVE_RE.search(line)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
220 if match:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
221 src = match.group(1)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
222 dest = match.group(2)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
223 txn.move(src, dest, sub)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
224 continue
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
225
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
226 match = RMKDIR_RE.search(line)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
227 if match:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
228 entry = match.group(1)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
229 txn.mkdir(entry, sub)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
230 continue
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
231
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
232 match = RDELETE_RE.search(line)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
233 if match:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
234 entry = match.group(1)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
235 txn.delete(entry, sub)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
236 continue
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
237
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
238 raise NameError, ('Unknown command [%s] on line %d' %
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
239 (line, lineno))
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
240
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
241 except:
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
242 sys.stderr.write(('Exception occured while processing line %d:\n' %
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
243 lineno))
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
244 etype, value, tb = sys.exc_info()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
245 traceback.print_exception(etype, value, tb, None, sys.stderr)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
246 sys.stderr.write('\n')
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
247 txn.rollback()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
248 sys.exit(1)
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
249
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
250 new_rev = txn.commit()
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
251 print '\nCommitted revision %d.' % new_rev
832
e9af7eba88db globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents: 581
diff changeset
252
581
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
253 finally:
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
254 print '\nRepository closed.'
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
255
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
256 def main():
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
257 core.run_app(rsvn)
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
258
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
259 if __name__ == '__main__':
90efea2c19df Add rsvn.py to test tools
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
260 main()