Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 14 years ago

#2556 closed enhancement (fixed)

Easy switching between revisions while previewing a file in browser

Reported by: pete@… Owned by: Jonas Borgström
Priority: normal Milestone: 0.10
Component: version control/browser Version: 0.9.2
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

While previewing a file in the browser it is helpful to be able to quickly jump back and forth between revisions. Attatched is a patch to the current /trunk/versioncontrol/web/browser.py to add links to the oldest, previous, next, and most recent revisions to a file being previewed. I'm not familiar with hacking the templates, so the links simply appear in the 'alternate' file downloads area.

--- browser.py	2006-01-04 10:16:03.000000000 -0500
+++ browser.py	2006-01-04 10:19:30.000000000 -0500
@@ -25,6 +25,7 @@
 from trac.web.chrome import add_link, add_stylesheet, INavigationContributor
 from trac.wiki import wiki_to_html, wiki_to_oneliner, IWikiSyntaxProvider
 from trac.versioncontrol.web_ui.util import *
+from trac.versioncontrol.svn_authz import SubversionAuthorizer
 
 
 IMG_RE = re.compile(r"\.(gif|jpg|jpeg|png)(\?.*)?$", re.IGNORECASE)
@@ -211,6 +212,34 @@
             mime_type = get_mime_type(content)
             use_rev = rev and node.rev
             
+            newestchgset = repos.get_youngest_rev()
+            nodehistory = repos.get_path_history(node.path, newestchgset)
+            allrevs = list(nodehistory)
+            oldest_rev_num = len(allrevs) - 1
+            oldest_rev = allrevs[oldest_rev_num]
+            oldest_path = '%s' % oldest_rev[0]
+            youngest_rev = allrevs[0]
+            youngest_path = '%s' % youngest_rev[0]
+            temprev = 0
+       ##find the current rev     
+            for revision in allrevs:
+            	if revision[1] == int(node.rev):
+            		break
+            	else:
+            		temprev += 1
+            		continue
+           		
+            current_rev = allrevs[temprev]
+            
+            if current_rev != oldest_rev:
+            	previous_rev = allrevs[temprev + 1]
+            	prev_path = '%s' % previous_rev[0]
+            	if previous_rev != oldest_rev:
+	             	add_link(req, 'alternate', self.env.href.browser(oldest_path, rev=oldest_rev[1]), 'Oldest Revision')
+	             	add_link(req, 'alternate', self.env.href.browser(prev_path, rev=previous_rev[1]), 'Previous Revision')
+                else:
+	             	add_link(req, 'alternate', self.env.href.browser(oldest_path, rev=oldest_rev[1]), 'Previous (Oldest) Revision')
+            
             if not is_binary(content):
                 if mime_type != 'text/plain':
                     plain_href = self.env.href.browser(node.path, rev=use_rev,
@@ -230,6 +259,16 @@
             add_link(req, 'alternate', raw_href, 'Original Format', mime_type)
             req.hdf['file.raw_href'] = raw_href
 
+            if current_rev != youngest_rev:
+            	next_rev = allrevs[temprev - 1]
+            	next_path = '%s' % next_rev[0]
+                if temprev - 1 > 0 and next_rev != youngest_rev:
+	             	add_link(req, 'alternate', self.env.href.browser(next_path, rev=next_rev[1]), 'Next Revision')
+	             	add_link(req, 'alternate', self.env.href.browser(youngest_path, rev=youngest_rev[1]), 'Most Recent Revision')
+                else:
+	             	add_link(req, 'alternate', self.env.href.browser(youngest_path, rev=youngest_rev[1]), 'Next (Most Recent) Revision')
+
+
             add_stylesheet(req, 'common/css/code.css')
 
     # IWikiSyntaxProvider methods

Attachments (0)

Change History (3)

comment:1 by Christopher Lenz, 18 years ago

Milestone: 0.9.3

Using diff to compare versions sounds like a better idea to me. Anyway, no enhancements on the maintenance branch.

comment:2 by Christian Boos, 18 years ago

Milestone: 0.10
Resolution: fixed
Status: newclosed

The trunk has now this feature, since the merging of the TracDiff branch.

See TracChangeset#CheckingtheLastChange.

comment:3 by Christian Boos, 18 years ago

PS: also, in the patch, the usage of repos.get_path_history() seems to be quite inappropriate here. That method has a very specific usage and should be used only in some situations (it's actually used to implement the Show only add, removes mode of TracRevisionLog, and for the search link shown in the TracBrowser when a path is not found). You should have used simply Repository.get_node() then Node.get_history().

I also realize that the documentation for this method is misleading… I'll fix that.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.