194
194
# Are we in 'revision mode' - has someone sent the 'r' query
195
195
# Work out the revisions from query
198
196
r_str = req.get_fieldstorage().getfirst("r")
199
197
revision = common.svn.revision_from_string(r_str)
199
# Now we need to get a directory listing (ls). We also need a function (fn)
200
# that will give us a (filename, attributes) pair for each type.
201
201
# Start by trying to do an SVN status, so we can report file version
206
ls_list = svnclient.list(path, revision=revision, recurse=False)
208
filename, attrs = PysvnList_tofileinfo(path, ls)
209
listing[filename.decode('utf-8')] = attrs
205
ls = svnclient.list(path, revision=revision, recurse=False)
206
fn = PysvnList_tofileinfo
211
status_list = svnclient.status(path, recurse=False, get_all=True,
208
ls = svnclient.status(path, recurse=False, get_all=True,
213
for status in status_list:
214
filename, attrs = PysvnStatus_to_fileinfo(path, status)
215
listing[filename.decode('utf-8')] = attrs
210
fn = PysvnStatus_to_fileinfo
216
211
except pysvn.ClientError:
217
212
# Presumably the directory is not under version control.
218
213
# Fallback to just an OS file listing.
215
fn = file_to_fileinfo
220
for filename in os.listdir(path):
221
listing[filename.decode('utf-8')] = file_to_fileinfo(path, filename)
217
ls = os.listdir(path)
223
219
# Non-directories will error - that's OK, we just want the "."
225
221
# The subversion one includes "." while the OS one does not.
226
222
# Add "." to the output, so the caller can see we are
228
mtime = os.path.getmtime(path)
229
listing["."] = file_to_fileinfo(path, "")
228
filename, attrs = fn(path, bit)
229
listing[filename.decode('utf-8')] = attrs
231
231
if ignore_dot_files:
232
232
for fn in listing.keys():
273
273
def file_to_fileinfo(path, filename):
274
274
"""Given a filename (relative to a given path), gets all the info "ls"
275
needs to display about the filename. Returns a dict containing a number
276
of fields related to the file (excluding the filename itself)."""
277
fullpath = path if len(filename) == 0 else os.path.join(path, filename)
278
return _fullpath_stat_fileinfo(fullpath)
275
needs to display about the filename. Returns pair mapping filename to
276
a dict containing a number of other fields."""
277
fullpath = path if filename in ('', '.') else os.path.join(path, filename)
278
return filename, _fullpath_stat_fileinfo(fullpath)
280
280
def PysvnStatus_to_fileinfo(path, status):
281
281
"""Given a PysvnStatus object, gets all the info "ls"