Christian Boos wrote:
Hi,
I'd like to resume my work on the version control refactoring.
The items I want to address this time are:
* fixing #1830 (Repository subsets have to be fully self contained)
TODO
* reintroduce the support for additional changeset properties
Done
* reintroduce the support for tags and branches
TODO
* make the changeset link syntax more tolerant (at least allow
hexadecimal changeset numbers)
Done
When this is done (should not take long),
this could eventually be merged back.
In addition to the above, I added the trac.versioncontrol namespace,
which ease the integration of vc backend plugins.
As I'd like to proceed using small incremental merges,
I'm asking for a review of those changes for their merge in trunk.
Diff attached.
-- Christian
diff -r 503470fdd894 htdocs/css/changeset.css
--- a/htdocs/css/changeset.css Wed Mar 1 16:49:07 2006 +0100
+++ b/htdocs/css/changeset.css Wed Mar 1 16:53:55 2006 +0100
@@ -17,6 +17,11 @@
width: .35em;
}
+#overview .changeset { padding: 0 0 1px }
+#overview dd.changeset p {
+ margin-bottom: 1em;
+ margin-top: 0;
+}
#overview .message { padding: 1em 0 1px }
#overview dd.message p, #overview dd.message ul, #overview dd.message ol {
margin-bottom: 1em;
diff -r 503470fdd894 setup.py
--- a/setup.py Wed Mar 1 16:49:07 2006 +0100
+++ b/setup.py Wed Mar 1 16:53:55 2006 +0100
@@ -5,7 +5,12 @@ import sys
import sys
import string
from glob import glob
-from distutils.core import setup
+try:
+ from setuptools import setup
+except ImportError:
+ print>>sys.stderr, ("Warning: Trac should use setuptools in order to "
+ "support pluggable versioncontrol backends.")
+ from distutils.core import setup
from distutils.command.install import install
from distutils.command.install_data import install_data
from distutils.command.install_scripts import install_scripts
@@ -221,6 +226,7 @@ facilities.
'trac.ticket', 'trac.upgrades', 'trac.web',
'trac.versioncontrol', 'trac.versioncontrol.web_ui',
'trac.wiki'],
+ namespace_packages = ['trac', 'trac.versioncontrol'],
data_files=[(_p('share/trac/templates'), glob('templates/*')),
(_p('share/trac/htdocs'), glob(_p('htdocs/*.*')) + [_p('htdocs/README')]),
(_p('share/trac/htdocs/css'), glob(_p('htdocs/css/*'))),
diff -r 503470fdd894 templates/changeset.cs
--- a/templates/changeset.cs Wed Mar 1 16:49:07 2006 +0100
+++ b/templates/changeset.cs Wed Mar 1 16:53:55 2006 +0100
@@ -156,6 +156,10 @@
(<?cs alt:changeset.age ?>less than one hour<?cs /alt ?> ago)</dd>
<dt class="author">Author:</dt>
<dd class="author"><?cs var:changeset.author ?></dd>
+ <?cs each:prop = changeset.properties ?>
+ <dt class="<?cs var:prop.htmlclass ?>"><?cs var:prop.name ?>:</dt>
+ <dd class="<?cs var:prop.htmlclass ?>"><?cs var:prop.value ?></dd>
+ <?cs /each ?>
<dt class="message">Message:</dt>
<dd class="message" id="searchable"><?cs
alt:changeset.message ?> <?cs /alt ?></dd><?cs
@@ -243,10 +247,10 @@
<thead><tr>
<th title="Revision <?cs var:item.rev.old ?>"><a href="<?cs
var:item.browser_href.old ?>" title="Show old version of <?cs
- var:item.path.old ?>">r<?cs var:item.rev.old ?></a></th>
+ var:item.path.old ?>">r<?cs var:item.shortrev.old ?></a></th>
<th title="Revision <?cs var:item.rev.new ?>"><a href="<?cs
var:item.browser_href.new ?>" title="Show new version of <?cs
- var:item.path.new ?>">r<?cs var:item.rev.new ?></a></th>
+ var:item.path.new ?>">r<?cs var:item.shortrev.new ?></a></th>
<th> </th></tr>
</thead><?cs
each:change = item.diff ?><?cs
diff -r 503470fdd894 trac/__init__.py
--- a/trac/__init__.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/__init__.py Wed Mar 1 16:53:55 2006 +0100
@@ -1,4 +1,10 @@
# -*- coding: iso-8859-1 -*-
+
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ pass
+
"""
Trac
Edgewall Software
@@ -43,3 +49,4 @@ __license_long__ = """
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."""
+
diff -r 503470fdd894 trac/scripts/admin.py
--- a/trac/scripts/admin.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/scripts/admin.py Wed Mar 1 16:53:55 2006 +0100
@@ -577,7 +577,9 @@ class TracAdmin(cmd.Cmd):
('trac', 'repository_type', repository_type),
('trac', 'repository_dir', repository_dir),
('trac', 'templates_dir', templates_dir),
- ('project', 'name', project_name)
+ ('project', 'name', project_name),
+ ('components',
+ 'trac.versioncontrol.%s' % repository_type, 'enabled')
]
try:
self.__env = Environment(self.envname, create=True,
diff -r 503470fdd894 trac/ticket/api.py
--- a/trac/ticket/api.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/ticket/api.py Wed Mar 1 16:53:55 2006 +0100
@@ -153,7 +153,7 @@ class TicketSystem(Component):
# matches #... but not &#... (HTML entity)
r"!?(?<!&)#"
# optional intertrac shorthand #T... + digits
- r"(?P<it_ticket>%s)?\d+" % Formatter.INTERTRAC_SCHEME,
+ r"(?P<it_ticket>%s)\d+" % Formatter.INTERTRAC_SCHEME,
lambda x, y, z: self._format_link(x, 'ticket', y[1:], y, z))
def _format_link(self, formatter, ns, target, label, fullmatch=None):
diff -r 503470fdd894 trac/ticket/report.py
--- a/trac/ticket/report.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/ticket/report.py Wed Mar 1 16:53:55 2006 +0100
@@ -512,7 +512,7 @@ class ReportModule(Component):
yield ('report', self._format_link)
def get_wiki_syntax(self):
- yield (r"!?\{(?P<it_report>%s\s*)?\d+\}" % Formatter.INTERTRAC_SCHEME,
+ yield (r"!?\{(?P<it_report>%s\s*)\d+\}" % Formatter.INTERTRAC_SCHEME,
lambda x, y, z: self._format_link(x, 'report', y[1:-1], y, z))
def _format_link(self, formatter, ns, target, label, fullmatch=None):
diff -r 503470fdd894 trac/versioncontrol/__init__.py
--- a/trac/versioncontrol/__init__.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/versioncontrol/__init__.py Wed Mar 1 16:53:55 2006 +0100
@@ -1,1 +1,6 @@ from trac.versioncontrol.api import *
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ pass
+
from trac.versioncontrol.api import *
diff -r 503470fdd894 trac/versioncontrol/api.py
--- a/trac/versioncontrol/api.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/versioncontrol/api.py Wed Mar 1 16:53:55 2006 +0100
@@ -297,6 +297,18 @@ class Changeset(object):
self.author = author
self.date = date
+ def properties(self):
+ """Generator that provide additional metadata for this changeset.
+
+ Each additional property is a 4 element tuple:
+ * `name` is the name of the property,
+ * `text` its value
+ * `wikiflag` indicates whether the `text` should be interpreted as
+ wiki text or not
+ * `htmlclass` enables to attach special formatting to the displayed
+ property, e.g. `'author'`, `'time'`, `'message'` or `'changeset'`.
+ """
+
def get_changes(self):
"""
Generator that produces a (path, kind, change, base_rev, base_path)
diff -r 503470fdd894 trac/versioncontrol/web_ui/changeset.py
--- a/trac/versioncontrol/web_ui/changeset.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/versioncontrol/web_ui/changeset.py Wed Mar 1 16:53:55 2006 +0100
@@ -270,13 +270,21 @@ class ChangesetModule(Component):
return 'Changeset %s' % rev
title = _changeset_title(rev)
+ properties = []
+ for name, value, wikiflag, htmlclass in chgset.properties():
+ if wikiflag:
+ value = wiki_to_html(value or '', self.env, req)
+ properties.append({'name': name, 'value': value,
+ 'htmlclass': htmlclass})
+
req.hdf['changeset'] = {
'revision': chgset.rev,
'time': util.format_datetime(chgset.date),
'age': util.pretty_timedelta(chgset.date, None, 3600),
'author': chgset.author or 'anonymous',
'message': wiki_to_html(chgset.message or '--', self.env, req,
- escape_newlines=True)
+ escape_newlines=True),
+ 'properties': properties
}
oldest_rev = repos.oldest_rev
if chgset.rev != oldest_rev:
@@ -333,6 +341,7 @@ class ChangesetModule(Component):
if old_node:
info['path.old'] = old_node.path
info['rev.old'] = old_node.rev
+ info['shortrev.old'] = repos.short_rev(old_node.rev)
old_href = self.env.href.browser(old_node.created_path,
rev=old_node.created_rev)
# Reminder: old_node.path may not exist at old_node.rev
@@ -343,6 +352,7 @@ class ChangesetModule(Component):
if new_node:
info['path.new'] = new_node.path
info['rev.new'] = new_node.rev # created rev.
+ info['shortrev.new'] = repos.short_rev(new_node.rev)
new_href = self.env.href.browser(new_node.created_path,
rev=new_node.created_rev)
# (same remark as above)
@@ -579,14 +589,16 @@ class ChangesetModule(Component):
# IWikiSyntaxProvider methods
+ CHANGESET_ID = r"[a-fA-F\d]+"
+
def get_wiki_syntax(self):
yield (
# [...] form: start with optional intertrac: [T... or [trac ...
- r"!?\[(?P<it_changeset>%s\s*)?" % Formatter.INTERTRAC_SCHEME +
- # digits + optional path for the restricted changeset
- r"\d+(?:/[^\]]*)?\]|"
+ r"!?\[(?P<it_changeset>%s\s*)" % Formatter.INTERTRAC_SCHEME +
+ # hex digits + optional /path for the restricted changeset
+ r"%s(?:/[^\]]*)?\]|" % self.CHANGESET_ID +
# r... form: allow r1 but not r1:2 (handled by the log syntax)
- r"(?:\b|!)r\d+\b(?!:\d)",
+ r"(?:\b|!)r\d+\b(?!:\d+)", # no r[hexa] because of rfc:...
lambda x, y, z:
self._format_changeset_link(x, 'changeset',
y[0] == 'r' and y[1:] or y[1:-1],
@@ -607,17 +619,16 @@ class ChangesetModule(Component):
rev, path = chgset[:sep], chgset[sep:]
else:
rev, path = chgset, None
- cursor = formatter.db.cursor()
- cursor.execute('SELECT message FROM revision WHERE rev=%s', (rev,))
- row = cursor.fetchone()
- if row:
+ repos = self.env.get_repository()
+ try:
+ chgset = repos.get_changeset(rev)
return '<a class="changeset" title="%s" href="%s">%s</a>' \
- % (util.escape(util.shorten_line(row[0])),
+ % (util.escape(util.shorten_line(chgset.message)),
formatter.href.changeset(rev, path), label)
- else:
- return '<a class="missing changeset" href="%s"' \
+ except TracError, e:
+ return '<a class="missing changeset" title="%s" href="%s"' \
' rel="nofollow">%s</a>' \
- % (formatter.href.changeset(rev, path), label)
+ % (str(e), formatter.href.changeset(rev, path), label)
def _format_diff_link(self, formatter, ns, params, label):
def pathrev(path):
diff -r 503470fdd894 trac/versioncontrol/web_ui/log.py
--- a/trac/versioncontrol/web_ui/log.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/versioncontrol/web_ui/log.py Wed Mar 1 16:53:55 2006 +0100
@@ -26,6 +26,7 @@ from trac.web.chrome import add_link, ad
from trac.web.chrome import add_link, add_stylesheet, INavigationContributor
from trac.wiki import IWikiSyntaxProvider
from trac.versioncontrol import Changeset
+from trac.versioncontrol.web_ui.changeset import ChangesetModule
from trac.versioncontrol.web_ui.util import *
LOG_LIMIT = 100
@@ -201,7 +202,8 @@ class LogModule(Component):
# IWikiSyntaxProvider methods
def get_wiki_syntax(self):
- yield (r"!?\[\d+:\d+\]|(?:\b|!)r\d+:\d+\b",
+ yield (r"!?\[%s:%s\]|(?:\b|!)r%s:%s\b"
+ % ((ChangesetModule.CHANGESET_ID,) * 4),
lambda x, y, z: self._format_link(x, 'log',
'#'+(y[0] == 'r' and y[1:]
or y[1:-1]), y))
diff -r 503470fdd894 trac/wiki/formatter.py
--- a/trac/wiki/formatter.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/wiki/formatter.py Wed Mar 1 16:53:55 2006 +0100
@@ -132,7 +132,7 @@ class Formatter(object):
INLINE_TOKEN = "`"
LINK_SCHEME = r"[\w.+-]+" # as per RFC 2396
- INTERTRAC_SCHEME = r"[a-zA-Z.+-]+?" # no digits (support for shorthand links)
+ INTERTRAC_SCHEME = r"[a-zA-Z.+-]*?" # no digits (support for shorthand links)
QUOTED_STRING = r"'[^']+'|\"[^\"]+\""
diff -r 503470fdd894 trac/wiki/tests/formatter.py
--- a/trac/wiki/tests/formatter.py Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/wiki/tests/formatter.py Wed Mar 1 16:53:55 2006 +0100
@@ -4,6 +4,7 @@ import unittest
import unittest
from trac.core import *
+from trac.test import Mock
from trac.wiki.formatter import Formatter, OneLinerFormatter
from trac.wiki.api import IWikiMacroProvider
@@ -67,6 +68,10 @@ class WikiTestCase(unittest.TestCase):
component.log = self.log
def get_db_cnx(self):
return db
+ def get_repository(self):
+ return Mock(get_changeset=lambda x: self._get_changeset(x))
+ def _get_changeset(self, x):
+ raise TracError("No changeset")
# Load all the components that provide IWikiSyntaxProvider
# implementations that are tested. Ideally those should be tested
diff -r 503470fdd894 trac/wiki/tests/wiki-tests.txt
--- a/trac/wiki/tests/wiki-tests.txt Wed Mar 1 16:49:07 2006 +0100
+++ b/trac/wiki/tests/wiki-tests.txt Wed Mar 1 16:53:55 2006 +0100
@@ -57,9 +57,9 @@ Paragraph
------------------------------
<p>
<a class="missing ticket" href="/ticket/1" rel="nofollow">#1</a>, <a class="report" href="/report/1">{1}</a>, <a class="missing ticket" href="/ticket/2" rel="nofollow">#2</a>
-<a class="missing changeset" href="/changeset/1" rel="nofollow">[1]</a>, <a class="missing changeset" href="/changeset/1" rel="nofollow">r1</a>
-<a class="missing changeset" href="/changeset/1/README.txt" rel="nofollow">[1/README.txt]</a>
-<a class="missing ticket" href="/ticket/12" rel="nofollow">#12</a>, <a class="missing changeset" href="/changeset/12" rel="nofollow">[12]</a>, <a class="missing changeset" href="/changeset/12" rel="nofollow">r12</a>, <a class="report" href="/report/12">{12}</a>
+<a class="missing changeset" title="No changeset" href="/changeset/1" rel="nofollow">[1]</a>, <a class="missing changeset" title="No changeset" href="/changeset/1" rel="nofollow">r1</a>
+<a class="missing changeset" title="No changeset" href="/changeset/1/README.txt" rel="nofollow">[1/README.txt]</a>
+<a class="missing ticket" href="/ticket/12" rel="nofollow">#12</a>, <a class="missing changeset" title="No changeset" href="/changeset/12" rel="nofollow">[12]</a>, <a class="missing changeset" title="No changeset" href="/changeset/12" rel="nofollow">r12</a>, <a class="report" href="/report/12">{12}</a>
</p>
------------------------------
==============================
@@ -101,10 +101,10 @@ Issue [ticket:1], CS[changeset:1], Listi
------------------------------
<p>
<a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a>, <a class="report" href="/report/1">report:1</a>, <a class="source" href="/browser/foo/bar">source:foo/bar</a>
-<a class="missing changeset" href="/changeset/1" rel="nofollow">changeset:1</a>, <a class="missing changeset" href="/changeset/1/README.txt" rel="nofollow">changeset:1/README.txt</a>
-</p>
-<p>
-Issue <a class="missing ticket" href="/ticket/1" rel="nofollow">1</a>, CS<a class="missing changeset" href="/changeset/1" rel="nofollow">1</a>, Listing <a class="report" href="/report/1">1</a>, File <a class="source" href="/browser/foo/bar">foo/bar</a>
+<a class="missing changeset" title="No changeset" href="/changeset/1" rel="nofollow">changeset:1</a>, <a class="missing changeset" title="No changeset" href="/changeset/1/README.txt" rel="nofollow">changeset:1/README.txt</a>
+</p>
+<p>
+Issue <a class="missing ticket" href="/ticket/1" rel="nofollow">1</a>, CS<a class="missing changeset" title="No changeset" href="/changeset/1" rel="nofollow">1</a>, Listing <a class="report" href="/report/1">1</a>, File <a class="source" href="/browser/foo/bar">foo/bar</a>
</p>
------------------------------
==============================
@@ -121,7 +121,7 @@ Issue [ticket:1 number 1], CS[changeset:
[source:foo/bar source foo/bar], [http://www.edgewall.com/ edgewall]
------------------------------
<p>
-<a class="missing ticket" href="/ticket/1" rel="nofollow">ticket 1</a>, <a class="missing changeset" href="/changeset/1" rel="nofollow">changeset 1</a>, <a class="report" href="/report/1">report 1</a>,
+<a class="missing ticket" href="/ticket/1" rel="nofollow">ticket 1</a>, <a class="missing changeset" title="No changeset" href="/changeset/1" rel="nofollow">changeset 1</a>, <a class="report" href="/report/1">report 1</a>,
<a class="source" href="/browser/foo/bar">source foo/bar</a>, <a class="ext-link" href="http://www.edgewall.com/"><span class="icon"></span>edgewall</a>
</p>
------------------------------
@@ -147,20 +147,20 @@ changeset:123&
changeset:123&
------------------------------
<p>
-Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
+Add-on to <a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
Some change.
<a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a>
This ticket is the first one
-<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>>
-<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&
-</p>
-------------------------------
-Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
+<a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>>
+<a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&
+</p>
+------------------------------
+Add-on to <a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
Some change.
<a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a>
This ticket is the first one
-<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>>
-<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&
+<a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>>
+<a class="missing changeset" title="No changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&
==============================
CamelCase AlabamA ABc AlaBamA FooBar
------------------------------
@@ -424,7 +424,7 @@ Test:<br /> There should be a line break
Test:<br /> There should be a line break
</p>
<p>
-Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a>
+Change:<a class="missing changeset" title="No changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" title="No changeset" href="/changeset/10" rel="nofollow">[10]</a>
</p>
<p>
Other test:<strong>bold text</strong> is not bold
@@ -432,7 +432,7 @@ Other test:<strong>bold text</strong> is
------------------------------
Test: There should be a line break
-Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a>
+Change:<a class="missing changeset" title="No changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" title="No changeset" href="/changeset/10" rel="nofollow">[10]</a>
Other test:<strong>bold text</strong> is not bold
==============================
@@ -935,14 +935,12 @@ trac:changeset:2081
trac:changeset:2081
[trac:changeset:2081 Trac r2081]
[T2081]
-[trac2081]
[trac 2081]
------------------------------
<p>
<a class="ext-link" href="http://projects.edgewall.com/trac/changeset/2081" title="changeset:2081 in Trac's Trac"><span class="icon"></span>trac:changeset:2081</a>
<a class="ext-link" href="http://projects.edgewall.com/trac/changeset/2081" title="changeset:2081 in Trac's Trac"><span class="icon"></span>Trac r2081</a>
<a class="ext-link" href="http://projects.edgewall.com/trac/changeset/2081" title="changeset:2081 in Trac's Trac"><span class="icon"></span>[T2081]</a>
-<a class="ext-link" href="http://projects.edgewall.com/trac/changeset/2081" title="changeset:2081 in Trac's Trac"><span class="icon"></span>[trac2081]</a>
<a class="ext-link" href="http://projects.edgewall.com/trac/changeset/2081" title="changeset:2081 in Trac's Trac"><span class="icon"></span>[trac 2081]</a>
</p>
------------------------------
_______________________________________________
Trac-dev mailing list
Trac-dev@lists.edgewall.com
http://lists.edgewall.com/mailman/listinfo/trac-dev