Skip to content

Commit 16a7185

Browse files
flyingflogitster
authored andcommitted
Add a svnrdump-simulator replaying a dump file for testing
To ease testing without depending on a reachable svn server, this compact python script mimics parts of svnrdumps behaviour. It requires the remote url to start with sim://. Start and end revisions are evaluated. If the requested revision doesn't exist, as it is the case with incremental imports, if no new commit was added, it returns 1 (like svnrdump). To allow using the same dump file for simulating multiple incremental imports, the highest revision can be limited by setting the environment variable SVNRMAX to that value. This simulates the situation where higher revs don't exist yet. Signed-off-by: Florian Achleitner <[email protected]> Acked-by: David Michael Barr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8e43a1d commit 16a7185

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

contrib/svn-fe/svnrdump_sim.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python
2+
"""
3+
Simulates svnrdump by replaying an existing dump from a file, taking care
4+
of the specified revision range.
5+
To simulate incremental imports the environment variable SVNRMAX can be set
6+
to the highest revision that should be available.
7+
"""
8+
import sys, os
9+
10+
11+
def getrevlimit():
12+
var = 'SVNRMAX'
13+
if os.environ.has_key(var):
14+
return os.environ[var]
15+
return None
16+
17+
def writedump(url, lower, upper):
18+
if url.startswith('sim://'):
19+
filename = url[6:]
20+
if filename[-1] == '/': filename = filename[:-1] #remove terminating slash
21+
else:
22+
raise ValueError('sim:// url required')
23+
f = open(filename, 'r');
24+
state = 'header'
25+
wroterev = False
26+
while(True):
27+
l = f.readline()
28+
if l == '': break
29+
if state == 'header' and l.startswith('Revision-number: '):
30+
state = 'prefix'
31+
if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
32+
state = 'selection'
33+
if not upper == 'HEAD' and state == 'selection' and l == 'Revision-number: %s\n' % upper:
34+
break;
35+
36+
if state == 'header' or state == 'selection':
37+
if state == 'selection': wroterev = True
38+
sys.stdout.write(l)
39+
return wroterev
40+
41+
if __name__ == "__main__":
42+
if not (len(sys.argv) in (3, 4, 5)):
43+
print "usage: %s dump URL -rLOWER:UPPER"
44+
sys.exit(1)
45+
if not sys.argv[1] == 'dump': raise NotImplementedError('only "dump" is suppported.')
46+
url = sys.argv[2]
47+
r = ('0', 'HEAD')
48+
if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
49+
r = sys.argv[3][2:].lstrip().split(':')
50+
if not getrevlimit() is None: r[1] = getrevlimit()
51+
if writedump(url, r[0], r[1]): ret = 0
52+
else: ret = 1
53+
sys.exit(ret)

0 commit comments

Comments
 (0)