Merge lp:~xnox/bzr-keywords/more-keywords into lp:bzr-keywords

Proposed by Dimitri John Ledkov
Status: Work in progress
Proposed branch: lp:~xnox/bzr-keywords/more-keywords
Merge into: lp:bzr-keywords
Diff against target: 245 lines (+93/-11)
2 files modified
__init__.py (+87/-11)
tests/test_keywords_in_trees.py (+6/-0)
To merge this branch: bzr merge lp:~xnox/bzr-keywords/more-keywords
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Abstain
Ian Clatworthy Pending
Review via email: mp+23626@code.launchpad.net

Description of the change

This branch adds support for
Revno - RevNo of the Revision-Id
CurRevno - Current Revno of the tree (eg. bzr cat $file --keywords=cooked --revision=$i will print $i and it doesn't matter when that file was actually last modified)
CurRevid - Same as above but id

I've tried hard to get testsuite coverage for this. But with current setup revno's are not generated / committed && I've tried writing one blackbox style, but then keywords plugin wasn't getting imported at all such that self.run_bzr("cat $file --keywords=coocked") would complain that keywords is not a valid argument =(

One more cool thing. I've added a hook such that on branch_tip_change files which are marked to be filtered get refreshed =) so you no longer need to remove-tree && co . to get new values like for example CurRev* and similar stuff.

Hope we can work on fixing test-suite.

To post a comment you must log in.
Revision history for this message
Removed by request (removed3076179) wrote :

In terms of the additional keywords, I vote +1.
I'd be willing to test it if I knew how to start testing. Keywords is something that I used quite a lot in svn.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

@carneeki

If you want to use this now. You can simply do $ bzr branch lp:~dmitrij.ledkov/bzr-keywords/more-keywords ~/.bazaar/plugins/keywords.

Or if you have keywords plugin you can just change into that and pull this branch and start using this to find corner cases or things that you want or don't work.

The testsuite coverage I'm referring to are the automated unit-test suite such that it can keep track of all the bugs for me =)

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

I think Revno and CurRevno are confusing terms - Revno is as much "current" as CurRevno. Perhaps BranchRevno and TreeRevno would be better names?

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3/2/2011 1:36 PM, Jelmer Vernooij wrote:
> You have been requested to review the proposed merge of lp:~dmitrij.ledkov/bzr-keywords/more-keywords into lp:bzr-keywords.
>
> For more details, see:
> https://code.launchpad.net/~dmitrij.ledkov/bzr-keywords/more-keywords/+merge/23626
>
> This branch adds support for
> Revno - RevNo of the Revision-Id
> CurRevno - Current Revno of the tree (eg. bzr cat $file --keywords=cooked --revision=$i will print $i and it doesn't matter when that file was actually last modified)
> CurRevid - Same as above but id
>
> I've tried hard to get testsuite coverage for this. But with current setup revno's are not generated / committed && I've tried writing one blackbox style, but then keywords plugin wasn't getting imported at all such that self.run_bzr("cat $file --keywords=coocked") would complain that keywords is not a valid argument =(
>
> One more cool thing. I've added a hook such that on branch_tip_change files which are marked to be filtered get refreshed =) so you no longer need to remove-tree && co . to get new values like for example CurRev* and similar stuff.
>
> Hope we can work on fixing test-suite.
>

Is this still a serious proposal? If you're still looking for feedback,
I'll be happy to actually review it and comment. But I'm going to skip
it for now, assuming that it is just dormant.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk101P4ACgkQJdeBCYSNAAOe6ACfTuhPSj+7GRyKZm2AcYX8IZwe
6QIAoJGQ72rzrKlzqGY15JXHam2O/Olr
=YNDd
-----END PGP SIGNATURE-----

Revision history for this message
Jelmer Vernooij (jelmer) :
review: Abstain (code)
Revision history for this message
rminsk (robertminsk) wrote :

I would love to see this merged into the main branch but with different keywords. The current keyword names are confusing

Revno -> Revision-Number (follows from the naming of Revision-Id)
CurRevid -> Tree-Revision-Id (more descriptive of its purpose)
CurRevid -> Tree-Revision-Number (follows from the naming of Tree-Revision-Id)

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> I would love to see this merged into the main branch but with different
> keywords. The current keyword names are confusing
>
> Revno -> Revision-Number (follows from the naming of Revision-Id)
> CurRevid -> Tree-Revision-Id (more descriptive of its purpose)
> CurRevid -> Tree-Revision-Number (follows from the naming of Tree-Revision-Id)
Revision-Id currently returns the tree revision id at the moment, so I think "Revno" should return the tree revision number too. We could then add Branch-Revid and Branch-Revno variables for the branch data.

If you're interested in helping land this, I'd be happy to review updated merge proposals.

Unmerged revisions

23. By Dimitri John Ledkov

Spent a lot of time on testsuite can't fix it =(

22. By Dimitri John Ledkov

Need to be flexible with getting additional parameters

21. By Dimitri John Ledkov

export fixed again

20. By Dimitri John Ledkov

Added hook

19. By Dimitri John Ledkov

Fixed export

18. By Dimitri John Ledkov

Lazy imports

17. By Dimitri John Ledkov

Added CurRevno, CurId & Revno

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2009-04-06 22:40:14 +0000
3+++ __init__.py 2010-04-18 08:51:20 +0000
4@@ -61,6 +61,7 @@
5 Date the date and time the file was last modified
6 Committer the committer (name and email) of the last change
7 Authors the authors (names and emails) of the last change
8+ Revno the revision number that last changed the file
9 Revision-Id the unique id of the revision that last changed the file
10 Path the relative path of the file in the tree
11 Filename just the name part of the relative path
12@@ -68,6 +69,8 @@
13 File-Id the unique id assigned to this file
14 Now the current date and time
15 User the current user (name and email)
16+ CurRevno the current revision number on the branch
17+ CurRevid the current unique id on the branch
18 ============= =========================================================
19
20 If you want finer control over the formatting of names and email
21@@ -107,11 +110,16 @@
22
23
24 import re, time
25+
26+from bzrlib.lazy_import import lazy_import
27+lazy_import(globals(), """
28 from bzrlib import (
29 builtins,
30+ branch,
31 commands,
32 config,
33 debug,
34+ errors,
35 filters,
36 option,
37 osutils,
38@@ -119,6 +127,7 @@
39 trace,
40 xml8,
41 )
42+""")
43
44
45 def test_suite():
46@@ -165,6 +174,8 @@
47 lambda c: c.revision().committer)
48 keyword_registry.register('Authors',
49 lambda c: ", ".join(c.revision().get_apparent_authors()))
50+keyword_registry.register('Revno',
51+ lambda c: _revision_id_to_revno(c.revision_id()))
52 keyword_registry.register('Revision-Id',
53 lambda c: c.revision_id())
54 keyword_registry.register('Path',
55@@ -181,6 +192,10 @@
56 lambda c: format_date(time.time(), time.timezone, c.config(), 'Now'))
57 keyword_registry.register('User',
58 lambda c: c.config().username())
59+keyword_registry.register('CurRevno',
60+ lambda c: _get_current()[0])
61+keyword_registry.register('CurRevid',
62+ lambda c: _get_current()[1])
63
64 # Keywords for finer control over name & address formatting
65 keyword_registry.register('Committer-Name',
66@@ -264,7 +279,7 @@
67
68 def compress_keywords(s):
69 """Replace cooked style keywords with raw style in a string.
70-
71+
72 :param s: the string
73 :return: the string with keywords compressed
74 """
75@@ -284,7 +299,7 @@
76
77 def expand_keywords(s, keyword_dicts, context=None, encoder=None, style=None):
78 """Replace raw style keywords with another style in a string.
79-
80+
81 Note: If the keyword is already in the expanded style, the value is
82 not replaced.
83
84@@ -385,6 +400,58 @@
85
86 filters.register_filter_stack_map('keywords', _keywords_filter_stack_lookup)
87
88+_keyword_current = registry.Registry()
89+
90+def _get_branch(location=u'.', b=None):
91+ if 'branch' in _keyword_current.keys():
92+ return _keyword_current.get('branch')
93+ else:
94+ if b is None: b = branch.Branch.open_containing(location)[0]
95+ _keyword_current.register('branch', b)
96+ return b
97+
98+def _revision_id_to_revno(revid):
99+ b = _get_branch()
100+ try:
101+ revno = b.revision_id_to_revno(revid)
102+ return str(revno)
103+ except:
104+ # We need to load and use the full revno map after all
105+ result = b.get_revision_id_to_revno_map().get(revid)
106+ if result is None:
107+ return result
108+ return ".".join(result)
109+
110+def _get_current(location=None, revid=None, b=None):
111+ b = _get_branch(location, b)
112+ if 'current' in _keyword_current.keys():
113+ return _keyword_current.get('current')
114+ else:
115+ if revid is None: revid = b.last_revision()
116+ revno = _revision_id_to_revno(revid)
117+ _keyword_current.register('current', (revno, revid))
118+ return (revno, revid)
119+
120+def _refilter_tree(p):
121+ t = p.branch.basis_tree()
122+ _get_current(b=p.branch, revid=p.new_revid)
123+ t.lock_read()
124+ for path, entry in t.inventory.iter_entries():
125+ stack = t._content_filter_stack(path)
126+ for i in stack:
127+ if i.reader == _kw_compressor:
128+ context = filters.ContentFilterContext(path, t, entry)
129+ chunks = t.get_file_lines(t.path2id(path))
130+ contents = filters.filtered_output_bytes(chunks, stack, context)
131+ content = ''.join(contents)
132+ file_object = open(path, 'wb')
133+ file_object.writelines(content)
134+ file_object.close()
135+ t.unlock()
136+
137+branch.Branch.hooks.install_named_hook("post_change_branch_tip",
138+ _refilter_tree,
139+ "Applying keywords")
140
141 class cmd_cat(builtins.cmd_cat):
142 """
143@@ -408,22 +475,27 @@
144 # Add a new option to the builtin command and
145 # override the inherited run() and help() methods
146
147+ takes_args = builtins.cmd_cat.takes_args
148 takes_options = builtins.cmd_cat.takes_options + [
149 option.RegistryOption('keywords',
150 registry=_keyword_style_registry,
151 converter=lambda s: s,
152 help='Keyword expansion style.')]
153-
154- def run(self, *args, **kwargs):
155+
156+ def run(self, filename, **kwargs):
157 """Process special options and delegate to superclass."""
158 if 'keywords' in kwargs:
159 # Implicitly set the filters option
160 kwargs['filters'] = True
161 style = kwargs['keywords']
162 _keyword_style_registry.default_key = style
163+ revid = None
164+ if 'revision' in kwargs:
165+ revid = kwargs['revision'][0].as_revision_id(b)
166+ _get_current(filename,revid)
167 del kwargs['keywords']
168- return super(cmd_cat, self).run(*args, **kwargs)
169-
170+ return super(cmd_cat, self).run(filename, **kwargs)
171+
172 def help(self):
173 """Return help message including text from superclass."""
174 from inspect import getdoc
175@@ -434,13 +506,14 @@
176 # Add a new option to the builtin command and
177 # override the inherited run() and help() methods
178
179+ takes_args = builtins.cmd_export.takes_args
180 takes_options = builtins.cmd_export.takes_options + [
181 option.RegistryOption('keywords',
182 registry=_keyword_style_registry,
183 converter=lambda s: s,
184 help='Keyword expansion style.')]
185-
186- def run(self, *args, **kwargs):
187+
188+ def run(self, dest, branch_or_subdir=None, **kwargs):
189 """Process special options and delegate to superclass."""
190 if 'keywords' in kwargs:
191 # Implicitly set the filters option
192@@ -448,15 +521,18 @@
193 style = kwargs['keywords']
194 _keyword_style_registry.default_key = style
195 del kwargs['keywords']
196- return super(cmd_export, self).run(*args, **kwargs)
197-
198+ revid = None
199+ if 'revision' in kwargs:
200+ revid = kwargs['revision'][0].as_revision_id(b)
201+ _get_current(branch_or_subdir,revid)
202+ return super(cmd_export, self).run(dest, branch_or_subdir, **kwargs)
203+
204 def help(self):
205 """Return help message including text from superclass."""
206 from inspect import getdoc
207 # NOTE: Reuse of cmd_cat help below is deliberate, not a bug
208 return getdoc(super(cmd_export, self)) + '\n\n' + getdoc(cmd_cat)
209
210-
211 # Register the command wrappers
212 commands.register_command(cmd_cat, decorate=False)
213 commands.register_command(cmd_export, decorate=False)
214
215=== modified file 'tests/test_keywords_in_trees.py'
216--- tests/test_keywords_in_trees.py 2009-08-11 05:14:31 +0000
217+++ tests/test_keywords_in_trees.py 2010-04-18 08:51:20 +0000
218@@ -34,10 +34,13 @@
219 Committer-Name: $Committer-Name$
220 Authors: $Authors$
221 Author1-Email: $Author1-Email$
222+Revno: $Revno$
223 Revision-Id: $Revision-Id$
224 Filename: $Filename$
225 Directory: $Directory$
226 File-Id: $File-Id$
227+CurRevno: $CurRevno$
228+CurRevid: $CurRevid
229 """
230 #User: $User$
231 #User-Email: $User-Email$
232@@ -46,10 +49,13 @@
233 Committer-Name: $Committer-Name: Jane Smith $
234 Authors: $Authors: Sue Smith <sue@example.com> $
235 Author1-Email: $Author1-Email: sue@example.com $
236+Revno: $Revno: 1 $
237 Revision-Id: $Revision-Id: rev1-id $
238 Filename: $Filename: file1 $
239 Directory: $Directory: $
240 File-Id: $File-Id: file1-id $
241+CurRevno: $CurRevno: 1 $
242+CurRevid: $CurRevid: rev1-id $
243 """
244 #User: $User: Dave Smith <dave@example.com>$
245 #User-Email: $User-Email: dave@example.com $

Subscribers

People subscribed via source and target branches