-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmart_rev.py
57 lines (41 loc) · 1.58 KB
/
smart_rev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""This is a helper program for using git as a front end to SVN.
The SubWCRev program is used to embed the revision number into a
source code file. This is called by the build process in some
environments. If you are using git as an svn front end execuiting this
command gives an error and stops the build.
This program wraps the SubWCRev program to work for both svn and git
repos. When called it detects if the file is in a git or svn
repository and does the appropriate thing. In svn it calls the
SubWCRev command, in git it just substitutes a dummy value for the
revision number.
in
C:\Program Files\TortoiseSVN\bin rename SubWCRev.exe to SubWCRev_old.exe
create the file C:\Program Files\TortoiseSVN\bin\SubWCRev.bat
with the single line:
python "c:\Program Files\TortoiseSVN\bin\smart_rev.py" %*
copy this file (smart_rev.py) to C:\Program Files\TortoiseSVN\bin
"""
import sys
import os
GIT, SVN = 0, 1
mode = 0
print "smart_rev.py got {}".format(sys.argv)
test_path = sys.argv[1]
source_file = sys.argv[2]
destination_file = sys.argv[3]
assert os.path.isdir(test_path), "specified path is not a directory."
test_path = os.path.join(test_path, ".svn")
if os.path.isdir(test_path):
mode = SVN
else:
mode = GIT
if mode == SVN:
print "SVN mode"
elif mode == GIT:
print "GIT mode"
with open(source_file, "r") as infile:
with open(destination_file, "w") as outfile:
for line in infile.readlines():
line = line.replace("$WCMODS?true:false$", "true")
line = line.replace("$WCREV$", "123456")
print >> outfile, line