[viewvc-dev] [PATCH] proposed viewvc changes to provide additional template information
Michael Brailsford <[email protected]>
| Newsgroups | gmane.comp.version-control.cvs.viewcvs.devel |
|---|---|
| Message-ID | <556277.94072.qm__36763.8711737984$1196706015$gmane$org@web37510.mail.mud.yahoo.com> |
This patch contains all the code to provide additional data to templates to provide additional functionality. The changes are as follows (all line numbers are line numbers of the patch file): * line 15: add the num_revs URL parameter to allow different numbers of revisions to show in the log view * line 23-27: add the path of the item to the row data provided to the directory template * line 35-54: add a method to retrieve svn properties * line 62-79: populate the num_revs option from the URL parameter, also no need in svn to sort on date v. revision. This is decidedly not CVS friendly, but the CVS stuff can be readded without adverse affect on SVN. * line 87, 95: add the path to the item to the template data, also format the date in a more compact format * line 103: convenience variable * line 111-122: add additional data to allow more functionality from the log view template, including any properties * line 130,138: pass along information to the log view as to whether we are viewing a file or a directory * line 146-150: removed the reordering of revision numbers prior to diffing, the revcmp() detects invalid revisions so I didn't just delete it I made these changes to provide the information I wanted while reworking the log view. So, I didn't perform a whole heck of a lot of investigation as to the "right way" to do things, I just wanted it done. Not to mention, my naivete of the whole arch of viewvc in general would likely make any investigation time consuming. So take a look at these and comment, and I'll make any changes to get these changes inline with the rest of viewvc. -Michael P.S. I should mention that I made these changes on the job. I have contacted my superiors and spoken with some folks from the legal dept. and they are supportive of donating contributions to the open source community, so long as the changes are credited to company and myself. I work for Cerner Corporation (http://www.cerner.com). Let me know what is needed to satisfy your requirements that my submissions are approved by Cerner. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
viewvc_py.diff
(text/x-patch, 5.3 KB)
--- viewvc_1_0_4/lib/viewvc.py 2007-11-29 16:46:30.000000000 -0600
+++ viewvc/lib/viewvc.py 2007-11-30 17:08:33.000000000 -0600
@@ -36,6 +36,7 @@
import struct
import types
import tempfile
+from svn import core, fs, repos
# these modules come from our library (the stub has set up the path)
import compat
@@ -679,6 +680,7 @@
'maxdate' : _re_validate_datetime,
'format' : _re_validate_alpha,
'limit' : _re_validate_number,
+ 'num_revs' : _re_validate_number,
# for redirect_pathrev
'orig_path' : None,
@@ -1570,9 +1572,10 @@
log_rev=None, state=None, size=None, mime_type=None,
date=None, ago=None, view_href=None, log_href=None,
revision_href=None, annotate_href=None, download_href=None,
- download_text_href=None, prefer_markup=ezt.boolean(0))
+ download_text_href=None, path=None, prefer_markup=ezt.boolean(0))
row.rev = file.rev
+ row.path = where + file.name
row.author = file.author
row.state = (request.roottype == 'cvs' and file.dead) and 'dead' or ''
if file.date is not None:
@@ -1864,6 +1867,26 @@
# sort highest revision first
return -cmp(rev1.number, rev2.number)
+# Retrieve the properties for the file being viewed.
+def get_props(request):
+ if request.roottype == 'svn':
+ path = core.svn_path_canonicalize(request.rootpath)
+ repo_ptr = repos.open(path)
+ fsob = repos.fs(repo_ptr)
+ rev = fs.youngest_rev(fsob)
+ root = fs.revision_root(fsob, rev)
+ raw_props = fs.node_proplist(root, request.where)
+ props = [ ]
+ for key, value in raw_props.items():
+ prop = _item()
+ prop.name = key
+ prop.value = str(value)
+ props.append(prop)
+ return props
+ else:
+ return []
+
+
def view_log(request):
cfg = request.cfg
diff_format = request.query_dict.get('diff_format', cfg.options.diff_format)
@@ -1877,16 +1900,15 @@
options = {}
options['svn_show_all_dir_logs'] = 1 ### someday make this optional?
options['svn_cross_copies'] = cfg.options.cross_copies
-
- show_revs = request.repos.itemlog(request.path_parts, request.pathrev,
- options)
- if logsort == 'date':
- show_revs.sort(logsort_date_cmp)
- elif logsort == 'rev':
- show_revs.sort(logsort_rev_cmp)
+ options['num_revs'] = int(request.query_dict.get("num_revs", 30))
+ if request.query_dict.has_key("revision"):
+ at_rev = int(request.query_dict.get("revision"))
else:
- # no sorting
- pass
+ at_rev = request.pathrev
+
+ show_revs = request.repos.itemlog(request.path_parts, at_rev, options)
+
+ show_revs.sort(logsort_rev_cmp)
# selected revision
selected_rev = request.query_dict.get('r1')
@@ -1897,13 +1919,14 @@
for rev in show_revs:
entry = _item()
entry.rev = rev.string
+ entry.path = request.where
entry.state = (cvs and rev.dead and 'dead')
entry.author = rev.author
entry.changed = rev.changed
entry.date = make_time_string(rev.date, cfg)
entry.ago = None
if rev.date is not None:
- entry.ago = html_time(request, rev.date, 1)
+ entry.ago = html_time(request, rev.date, 0)
entry.log = htmlify(rev.log or "")
entry.size = rev.size
entry.branch_point = None
@@ -2039,6 +2062,7 @@
entries.append(entry)
data = common_template_data(request)
+ tree_rev = vclib.svn.created_rev(request.repos, request.where, request.repos._getrev(request.pathrev))
data.update({
'default_branch' : None,
'mime_type' : request.mime_type,
@@ -2058,8 +2082,18 @@
'tag_download_href': None,
'tag_download_text_href': None,
'tag_annotate_href': None,
+ 'youngest_rev' : vclib.svn.get_youngest_revision(request.repos),
+ 'youngest_rev_href' : request.get_url(view_func=view_revision, params={}, escape=1),
+ 'tree_rev' : tree_rev,
+ 'tree_rev_href' : request.get_url(view_func=view_revision, params={'revision': tree_rev}, escape=1),
+ 'num_revs': int(request.query_dict.get("num_revs", 30)),
+ 'revision': at_rev,
})
+ #add props to the data
+ props = get_props(request)
+ data['props'] = props
+
lastrev = pathrev_form(request, data)
if cfg.options.use_pagesize:
@@ -2075,6 +2109,7 @@
request.get_form(params={'logsort': None})
if pathtype is vclib.FILE:
+ data['pathtype'] = 'file'
if not request.pathrev or lastrev is None:
view_href, download_href, download_text_href, \
annotate_href, revision_href, prefer_markup \
@@ -2100,6 +2135,7 @@
'tag_prefer_markup': prefer_markup,
})
else:
+ data['pathtype'] = 'dir'
data['view_href'] = request.get_url(view_func=view_directory,
params={}, escape=1)
@@ -2629,10 +2665,7 @@
p2 = _get_diff_path_parts(request, 'p2', rev2, request.pathrev)
try:
- if revcmp(rev1, rev2) > 0:
- rev1, rev2 = rev2, rev1
- sym1, sym2 = sym2, sym1
- p1, p2 = p2, p1
+ revcmp(rev1, rev2)
except ValueError:
raise debug.ViewVCException('Invalid revision(s) passed to diff',
'400 Bad Request')
@@ -3673,7 +3706,6 @@
debug.dump()
debug.DumpChildren(server)
-
class _item:
def __init__(self, **kw):
vars(self).update(kw)