mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-10139 fix for diff links on branches
X-SVN-Rev: 34535
This commit is contained in:
parent
72523b3ae8
commit
6161ae065e
2 changed files with 85 additions and 27 deletions
|
@ -72,6 +72,7 @@ class ReviewModule(Component):
|
|||
return (template, data, content_type)
|
||||
|
||||
def render_reviewlink(self, req):
|
||||
"""Render the "143 commits." box that shows in the topnav."""
|
||||
#add_stylesheet(req, 'icucodetools/css/icuxtn.css')
|
||||
|
||||
els = []
|
||||
|
@ -103,18 +104,21 @@ class ReviewModule(Component):
|
|||
|
||||
|
||||
def match_request(self, req):
|
||||
"""Is this a review URL?"""
|
||||
match = re.match('/review(?:/([^/]+))?(?:/([^/]+))?(?:/(.*)$)?', req.path_info)
|
||||
if match:
|
||||
req.args['ticket'] = match.group(1)
|
||||
return True
|
||||
|
||||
def match_ticketpage(self, req):
|
||||
"""Is this the ticket URL?"""
|
||||
match = re.match('/ticket(?:/([^/]+))?(?:/([^/]+))?(?:/(.*)$)?', req.path_info)
|
||||
if match:
|
||||
req.args['ticket'] = match.group(1)
|
||||
return True
|
||||
|
||||
def pathToBranchName(self, path):
|
||||
"""convert a full path name to the 'branch' it applies to."""
|
||||
#return '/'.join(path.split('/')[0:2])
|
||||
windex = None
|
||||
win = None
|
||||
|
@ -134,25 +138,54 @@ class ReviewModule(Component):
|
|||
segments = path[windex:].split('/')
|
||||
return path[:windex] + ('/'.join(segments[0:win[1]+1])) # use specified # of following segments
|
||||
|
||||
def changeToRange(self, c_new, change):
|
||||
def changeToRange(self, c_new, change, repos):
|
||||
"""preprocess a chgset.get_changes[n] entry. Returns (srcrev,dstrev,type) + change. The specially processed srcrev and dstrev are -1 for none, and the type gets munged a bit."""
|
||||
# q: (u'trunk/Locale.java', 'file', 'add', None, u'-1') from r3
|
||||
# q: (u'trunk/util.c', 'file', 'edit', u'trunk/util.c', u'2') from r4
|
||||
# c_path = change[0]
|
||||
# c_itemtype = change[1]
|
||||
c_path = change[0] # new path
|
||||
# c_itemtype = change[1] # 'file' or ?
|
||||
c_type = change[2]
|
||||
c_oldpath = change[3]
|
||||
c_old = int(change[4] or -1)
|
||||
c_dstrev = c_new
|
||||
c_srcrev = c_old = int(change[4] or -1)
|
||||
if(c_type in (Changeset.COPY,Changeset.MOVE)):
|
||||
return (-1, c_new, c_type, c_old, c_oldpath) # ignore OLD rev for these
|
||||
c_srcrev = -1
|
||||
elif(c_type in (Changeset.DELETE)):
|
||||
return (c_old, -1, c_type)
|
||||
c_dstrev = -1
|
||||
elif(c_type in (Changeset.EDIT, Changeset.ADD)):
|
||||
if c_path != c_oldpath and c_oldpath != None and c_path != None: # did the path change? (copy or move)
|
||||
if(c_old != -1): # if we have an old rev, track it
|
||||
## SHOULD call repos.get_path_history(c_path, c_new, c_old)
|
||||
## and then look for 'copy' or 'move' here.
|
||||
## Code below will only return the EDIT (etc) operation *before* the copy/move.
|
||||
# oldchange = repos.get_changeset(c_old) # old rev
|
||||
# found = None
|
||||
# for oldchg in oldchange.get_changes():
|
||||
# if oldchg[0] == c_path or oldchg[3] == c_oldpath:
|
||||
# found = oldchg
|
||||
# if found:
|
||||
# # "found" is the source location (pre copy)
|
||||
# # however, change[] will have the correct from/to
|
||||
# #
|
||||
# c_type = "["+str(c_old)+":"+str(c_new)+"]"+found[2] + "+" +c_type
|
||||
# else:
|
||||
# c_type = "???+" + c_type
|
||||
c_type = "(copy/move)+" + c_type
|
||||
else:
|
||||
c_type = "(???)+" + c_type
|
||||
else:
|
||||
return (c_old, c_new, c_type)
|
||||
c_type = c_type +" ???"
|
||||
return (c_srcrev, c_dstrev, c_type) + change + (1,) # preprocessed + (change) + (mergecount)
|
||||
|
||||
def describeChange(self, file, change, req, db):
|
||||
"""HTMLize a changeset (the 'details' column)"""
|
||||
what = change[2] or 'change'
|
||||
where = 'r%d:%d' % (change[0],change[1])
|
||||
if(change[0] == -1):
|
||||
if(change[2] == 'move'):
|
||||
url = req.href.changeset(change[1])
|
||||
where = 'r%d' % change[1]
|
||||
what = change[2]
|
||||
elif(change[0] == -1):
|
||||
if(change[1] == -1):
|
||||
url = None
|
||||
what = "noop"
|
||||
|
@ -167,18 +200,27 @@ class ReviewModule(Component):
|
|||
what = "deleted"
|
||||
where = None
|
||||
else:
|
||||
url = req.href.changeset(old_path=file, old=change[0], new_path=file, new=change[1])
|
||||
url = req.href.changeset(old_path=change[6] or file, old=change[0], new_path=change[3] or file, new=change[1])
|
||||
|
||||
# multi change
|
||||
if(change[8]>1):
|
||||
what = u"%s\u00d7%d" % (what, change[8])
|
||||
|
||||
# urlize
|
||||
if url:
|
||||
what = Markup('<a href="%s">%s</a>' % (url,what))
|
||||
|
||||
if where:
|
||||
# search query?
|
||||
return (what, tag.a(where, href=req.href.search(q=where)))
|
||||
#return (what, where)
|
||||
else:
|
||||
# specific url
|
||||
return (what, '')
|
||||
|
||||
|
||||
def process_request(self, req):
|
||||
#ok, what are we about.
|
||||
"""This is the 'main' of this module."""
|
||||
#db = self.env.get_db_cnx()
|
||||
#ticketlist = {} # dict of ticket->???
|
||||
#revlist = {} # dict of revision->
|
||||
|
@ -214,6 +256,7 @@ class ReviewModule(Component):
|
|||
|
||||
data['overall_y'] = 0
|
||||
data['ticket_id'] = req.args['ticket']
|
||||
data['ticket_summary'] = ''
|
||||
data['ticket_href'] = req.href.ticket(req.args['ticket'])
|
||||
|
||||
ticket_mgr = TicketManager(self.compmgr)
|
||||
|
@ -231,10 +274,10 @@ class ReviewModule(Component):
|
|||
return req.redirect(req.href.changeset(revs[0]))
|
||||
|
||||
revcount = 0
|
||||
branches = {}
|
||||
files = {}
|
||||
branches = {} # track each branch separately.
|
||||
files = {} # track all of the files which are affected
|
||||
# may be 0 revs.
|
||||
revisions = []
|
||||
revisions = [] # array of munged revisions
|
||||
|
||||
for rev in revs:
|
||||
chgset = repos.get_changeset(rev)
|
||||
|
@ -252,20 +295,20 @@ class ReviewModule(Component):
|
|||
except Exception, e:
|
||||
self.env.log.warn(e)
|
||||
revision['comment_wiki'] = "%s (could not format - %s)" % (message, str(e))
|
||||
#return system_message(_('HTML parsing error: %(message)s',
|
||||
# message=escape(e.msg)), line)
|
||||
|
||||
rbranches = revision['branches'] = []
|
||||
# walk through all changes in this Changeset and apply them to the files[] array
|
||||
for chg in chgset.get_changes():
|
||||
path = chg[0]
|
||||
path = chg[0] # new path
|
||||
if path in files:
|
||||
item = files[path]
|
||||
item = files[path] # known file
|
||||
else:
|
||||
item = []
|
||||
files[path] = item;
|
||||
item.append(self.changeToRange(rev,chg))
|
||||
files[path] = item; # new file
|
||||
item.append(self.changeToRange(rev,chg,repos))
|
||||
branch_name = self.pathToBranchName(path)
|
||||
if branch_name not in rbranches:
|
||||
# first time we have seen this branch
|
||||
rbranches.append(branch_name)
|
||||
revisions.append(revision)
|
||||
data['revisions'] = revisions
|
||||
|
@ -278,17 +321,25 @@ class ReviewModule(Component):
|
|||
filelist = files.keys()
|
||||
filelist.sort()
|
||||
# print 'bar to %d len of %s' % (len(filelist),str(filelist))
|
||||
# see changeToRange() for definition of the elements here.
|
||||
# (oldrev, newrev, type, (change...) )
|
||||
for file in filelist:
|
||||
changes = files[file]
|
||||
i = 0
|
||||
# print " looping from %d to %d over %d " % (i,len(changes)-1,len(changes))
|
||||
while len(changes)>1 and i<(len(changes)-1):
|
||||
if changes[i][1] == changes[i+1][0]:
|
||||
merge = None
|
||||
if changes[i][1] == changes[i+1][0]: # if this change is exactly subsequent to the previous
|
||||
if changes[i][0] == -1:
|
||||
changes[i+1] = (changes[i][0],changes[i+1][1],'add+commits') # retain 'first' rev
|
||||
else:
|
||||
changes[i+1] = (changes[i][0],changes[i+1][1],'multiple commits') # retain 'first' rev
|
||||
|
||||
if changes[i][2] == Changeset.ADD and changes[i+1][2] == Changeset.EDIT:
|
||||
merge = (changes[i][0],changes[i+1][1],'add+commits') # merge, retain 'first' rev
|
||||
elif changes[i][2] == '(copy/move)+edit' and changes[i+1][2] == Changeset.EDIT:
|
||||
merge = (changes[i][0],changes[i+1][1],'(copy/move)+edit') # retain 'first' rev
|
||||
elif changes[i][2] == Changeset.EDIT and changes[i+1][2] == Changeset.EDIT:
|
||||
merge = (changes[i][0],changes[i+1][1],'edit') # retain 'first' rev
|
||||
if merge:
|
||||
# preserve paths
|
||||
changes[i+1] = merge + (changes[i+1][3], changes[i+1][4], changes[i][5]+"+"+changes[i+1][5], changes[i][6], changes[i+1][7], changes[i][8]+1)
|
||||
changes = changes[:i] + changes[i+1:] # and shift down
|
||||
# print "merged: %s" % str(changes)
|
||||
files[file] = changes
|
||||
|
@ -316,7 +367,7 @@ class ReviewModule(Component):
|
|||
changes_data.append(self.describeChange(file, change, req, db))
|
||||
file_data['changes'] = changes_data
|
||||
if(len(changes)>1):
|
||||
whathtml = self.describeChange(file, (changes[0][0], changes[len(changes)-1][1], 'overall'), req, db)
|
||||
whathtml = self.describeChange(file, (int(changes[0][7] or -1), int(changes[len(changes)-1][1] or -1), 'overall', changes[len(changes)-1][3], None, None, changes[0][6], None, len(changes)), req, db)
|
||||
file_data['overall'] = whathtml
|
||||
file_data['overall_y'] = 1
|
||||
data['overall_y'] = 1
|
||||
|
@ -331,7 +382,9 @@ class ReviewModule(Component):
|
|||
|
||||
# .. convert dict to array.
|
||||
branch_list = []
|
||||
for branch in branches:
|
||||
branch_keys = branches.keys()
|
||||
branch_keys.sort()
|
||||
for branch in branch_keys:
|
||||
branch_list.append(branches[branch])
|
||||
data['branches'] = branch_list
|
||||
data['lastbranch'] = branch
|
||||
|
|
|
@ -18,8 +18,13 @@
|
|||
<div id="content" class="icucodereview">
|
||||
|
||||
|
||||
<h1>Ticket <a href='${href.ticket(ticket_id)}'>#${ticket_id}</a></h1>
|
||||
<h1>NOTE, SRL IS DOING SOME WORK ON THIS PAGE, PLEASE PARDON THE DUST.</h1>
|
||||
|
||||
|
||||
<h1>Ticket <a href='${href.ticket(ticket_id)}'>#${ticket_id}</a></h1>
|
||||
<p>
|
||||
<span class="icureview_summary">${ticket_summary}</span>
|
||||
</p>
|
||||
<py:if test="revcount">
|
||||
|
||||
<h2>${revcount} Changesets</h2>
|
||||
|
|
Loading…
Add table
Reference in a new issue