forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvnfind
More file actions
executable file
·159 lines (127 loc) · 4.68 KB
/
svnfind
File metadata and controls
executable file
·159 lines (127 loc) · 4.68 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
# -*- python -*-
"""
NAME
%(program)s - find a filename close to a given a SVN repository commit
SYNOPSIS
%(program)s [OPTIONS] REPO REV NAME
DESCRIPTION
Supposing we have a subversion repository containing a trunk and
various branches. Given the repository url and the revision number of
a commit, what is the top of the branch? $(program)s attempts to
answer this by letting you search for a specific file name which is
assumed to be unique within the branch and be situated at the top of
the branch subtree.
%(options)s
AUTHOR
Written by Henrik Levkowetz, <henrik@zinfandel.tools.ietf.org>
COPYRIGHT
Copyright 2015 Henrik Levkowetz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version. There is NO WARRANTY; not even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
"""
import sys, os.path, getopt, re
version = "0.13"
program = os.path.basename(sys.argv[0])
progdir = os.path.dirname(sys.argv[0])
# ----------------------------------------------------------------------
# Parse options
options = ""
for line in re.findall("\n +(if|elif) +opt in \[(.+)\]:\s+#(.+)\n", open(sys.argv[0]).read()):
if not options:
options += "OPTIONS\n"
options += " %-16s %s\n" % (line[1].replace('"', ''), line[2])
options = options.strip()
# with ' < 1:' on the next line, this is a no-op:
if len(sys.argv) <= 1:
help()
try:
opts, files = getopt.gnu_getopt(sys.argv[1:], "dfDhv", ["dirchange", "filechange", "dirpath", "help", "version",])
except Exception, e:
print "%s: %s" % (program, e)
sys.exit(1)
# ----------------------------------------------------------------------
# Handle options
# set default values, if any
opt_dirpath = False
opt_dirchange = False
opt_filechange = False
opt_verbose = False
# ----------------------------------------------------------------------
def help(msg=None, err=0):
if msg:
print(msg+'\n')
print(__doc__ % globals())
sys.exit(err)
# handle individual options
for opt, value in opts:
if opt in ["-h", "--help"]: # Output this help, then exit
help()
elif opt in ["-v", "--version"]: # Output version information, then exit
print program, version
sys.exit(0)
elif opt in ["-d", "--dirchange"]: # Look only for directory changes
opt_dirchange = True
elif opt in ["-f", "--filechange"]: #Look only for file changes
opt_filechange = True
elif opt in ["-D", "--dirpath"]: # Output the directory path, not the file path
opt_dirpath = True
# if neither filechange nor dirchange have been specified, look for both
if not opt_filechange and not opt_dirchange:
opt_filechange = True
opt_dirchange = True
# ----------------------------------------------------------------------
def help(msg=None, err=0):
if msg:
print(msg+'\n')
print(__doc__ % globals())
sys.exit(err)
# ----------------------------------------------------------------------
def say(s):
sys.stderr.write("%s\n" % (s))
# ----------------------------------------------------------------------
def note(s):
if opt_verbose:
sys.stderr.write("%s\n" % (s))
# ----------------------------------------------------------------------
def die(s, error=1):
sys.stderr.write("\n%s: Error: %s\n\n" % (program, s))
sys.exit(error)
# ----------------------------------------------------------------------
# Bad args
if len(files) < 3:
help("Not enogh arguments\n\nExpected %s REPO REV NAME" %program, 1)
# ----------------------------------------------------------------------
# The program itself
import pysvn
#import debug
repo, rev, name = files
changeset = pysvn.Transaction(repo, rev, True)
changed = changeset.changed()
# Each dictionary entry is a tuple, with elements as follows:
CHG_ACTION, CHG_KIND, CHG_TEXTMOD, CHG_PROPMOD = range(4)
node = None
for key in changed:
if opt_dirchange and changed[key][CHG_KIND] == pysvn.node_kind.dir:
node = key
break
if opt_filechange and changed[key][CHG_KIND] == pysvn.node_kind.file:
node = '/'.join(key.split('/')[:-1])
break
while node:
#debug.show('node')
list = changeset.list(node)
if name in list:
if opt_dirpath:
print node
else:
sys.stdout.write(node)
sys.stdout.write('/')
sys.stdout.write(name)
sys.stdout.write('\n')
break
node = '/'.join(node.split('/')[:-1])