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
=== modified file '__init__.py'
--- __init__.py 2009-04-06 22:40:14 +0000
+++ __init__.py 2010-04-18 08:51:20 +0000
@@ -61,6 +61,7 @@
61 Date the date and time the file was last modified61 Date the date and time the file was last modified
62 Committer the committer (name and email) of the last change62 Committer the committer (name and email) of the last change
63 Authors the authors (names and emails) of the last change63 Authors the authors (names and emails) of the last change
64 Revno the revision number that last changed the file
64 Revision-Id the unique id of the revision that last changed the file65 Revision-Id the unique id of the revision that last changed the file
65 Path the relative path of the file in the tree66 Path the relative path of the file in the tree
66 Filename just the name part of the relative path67 Filename just the name part of the relative path
@@ -68,6 +69,8 @@
68 File-Id the unique id assigned to this file69 File-Id the unique id assigned to this file
69 Now the current date and time70 Now the current date and time
70 User the current user (name and email)71 User the current user (name and email)
72 CurRevno the current revision number on the branch
73 CurRevid the current unique id on the branch
71 ============= =========================================================74 ============= =========================================================
7275
73If you want finer control over the formatting of names and email76If you want finer control over the formatting of names and email
@@ -107,11 +110,16 @@
107110
108111
109import re, time112import re, time
113
114from bzrlib.lazy_import import lazy_import
115lazy_import(globals(), """
110from bzrlib import (116from bzrlib import (
111 builtins,117 builtins,
118 branch,
112 commands,119 commands,
113 config,120 config,
114 debug,121 debug,
122 errors,
115 filters,123 filters,
116 option,124 option,
117 osutils,125 osutils,
@@ -119,6 +127,7 @@
119 trace,127 trace,
120 xml8,128 xml8,
121 )129 )
130""")
122131
123132
124def test_suite():133def test_suite():
@@ -165,6 +174,8 @@
165 lambda c: c.revision().committer)174 lambda c: c.revision().committer)
166keyword_registry.register('Authors',175keyword_registry.register('Authors',
167 lambda c: ", ".join(c.revision().get_apparent_authors()))176 lambda c: ", ".join(c.revision().get_apparent_authors()))
177keyword_registry.register('Revno',
178 lambda c: _revision_id_to_revno(c.revision_id()))
168keyword_registry.register('Revision-Id',179keyword_registry.register('Revision-Id',
169 lambda c: c.revision_id())180 lambda c: c.revision_id())
170keyword_registry.register('Path',181keyword_registry.register('Path',
@@ -181,6 +192,10 @@
181 lambda c: format_date(time.time(), time.timezone, c.config(), 'Now'))192 lambda c: format_date(time.time(), time.timezone, c.config(), 'Now'))
182keyword_registry.register('User',193keyword_registry.register('User',
183 lambda c: c.config().username())194 lambda c: c.config().username())
195keyword_registry.register('CurRevno',
196 lambda c: _get_current()[0])
197keyword_registry.register('CurRevid',
198 lambda c: _get_current()[1])
184199
185# Keywords for finer control over name & address formatting200# Keywords for finer control over name & address formatting
186keyword_registry.register('Committer-Name',201keyword_registry.register('Committer-Name',
@@ -264,7 +279,7 @@
264279
265def compress_keywords(s):280def compress_keywords(s):
266 """Replace cooked style keywords with raw style in a string.281 """Replace cooked style keywords with raw style in a string.
267 282
268 :param s: the string283 :param s: the string
269 :return: the string with keywords compressed284 :return: the string with keywords compressed
270 """285 """
@@ -284,7 +299,7 @@
284299
285def expand_keywords(s, keyword_dicts, context=None, encoder=None, style=None):300def expand_keywords(s, keyword_dicts, context=None, encoder=None, style=None):
286 """Replace raw style keywords with another style in a string.301 """Replace raw style keywords with another style in a string.
287 302
288 Note: If the keyword is already in the expanded style, the value is303 Note: If the keyword is already in the expanded style, the value is
289 not replaced.304 not replaced.
290305
@@ -385,6 +400,58 @@
385400
386filters.register_filter_stack_map('keywords', _keywords_filter_stack_lookup)401filters.register_filter_stack_map('keywords', _keywords_filter_stack_lookup)
387402
403_keyword_current = registry.Registry()
404
405def _get_branch(location=u'.', b=None):
406 if 'branch' in _keyword_current.keys():
407 return _keyword_current.get('branch')
408 else:
409 if b is None: b = branch.Branch.open_containing(location)[0]
410 _keyword_current.register('branch', b)
411 return b
412
413def _revision_id_to_revno(revid):
414 b = _get_branch()
415 try:
416 revno = b.revision_id_to_revno(revid)
417 return str(revno)
418 except:
419 # We need to load and use the full revno map after all
420 result = b.get_revision_id_to_revno_map().get(revid)
421 if result is None:
422 return result
423 return ".".join(result)
424
425def _get_current(location=None, revid=None, b=None):
426 b = _get_branch(location, b)
427 if 'current' in _keyword_current.keys():
428 return _keyword_current.get('current')
429 else:
430 if revid is None: revid = b.last_revision()
431 revno = _revision_id_to_revno(revid)
432 _keyword_current.register('current', (revno, revid))
433 return (revno, revid)
434
435def _refilter_tree(p):
436 t = p.branch.basis_tree()
437 _get_current(b=p.branch, revid=p.new_revid)
438 t.lock_read()
439 for path, entry in t.inventory.iter_entries():
440 stack = t._content_filter_stack(path)
441 for i in stack:
442 if i.reader == _kw_compressor:
443 context = filters.ContentFilterContext(path, t, entry)
444 chunks = t.get_file_lines(t.path2id(path))
445 contents = filters.filtered_output_bytes(chunks, stack, context)
446 content = ''.join(contents)
447 file_object = open(path, 'wb')
448 file_object.writelines(content)
449 file_object.close()
450 t.unlock()
451
452branch.Branch.hooks.install_named_hook("post_change_branch_tip",
453 _refilter_tree,
454 "Applying keywords")
388455
389class cmd_cat(builtins.cmd_cat):456class cmd_cat(builtins.cmd_cat):
390 """457 """
@@ -408,22 +475,27 @@
408 # Add a new option to the builtin command and475 # Add a new option to the builtin command and
409 # override the inherited run() and help() methods476 # override the inherited run() and help() methods
410477
478 takes_args = builtins.cmd_cat.takes_args
411 takes_options = builtins.cmd_cat.takes_options + [479 takes_options = builtins.cmd_cat.takes_options + [
412 option.RegistryOption('keywords',480 option.RegistryOption('keywords',
413 registry=_keyword_style_registry,481 registry=_keyword_style_registry,
414 converter=lambda s: s,482 converter=lambda s: s,
415 help='Keyword expansion style.')]483 help='Keyword expansion style.')]
416 484
417 def run(self, *args, **kwargs):485 def run(self, filename, **kwargs):
418 """Process special options and delegate to superclass."""486 """Process special options and delegate to superclass."""
419 if 'keywords' in kwargs:487 if 'keywords' in kwargs:
420 # Implicitly set the filters option488 # Implicitly set the filters option
421 kwargs['filters'] = True489 kwargs['filters'] = True
422 style = kwargs['keywords']490 style = kwargs['keywords']
423 _keyword_style_registry.default_key = style491 _keyword_style_registry.default_key = style
492 revid = None
493 if 'revision' in kwargs:
494 revid = kwargs['revision'][0].as_revision_id(b)
495 _get_current(filename,revid)
424 del kwargs['keywords']496 del kwargs['keywords']
425 return super(cmd_cat, self).run(*args, **kwargs)497 return super(cmd_cat, self).run(filename, **kwargs)
426 498
427 def help(self):499 def help(self):
428 """Return help message including text from superclass."""500 """Return help message including text from superclass."""
429 from inspect import getdoc501 from inspect import getdoc
@@ -434,13 +506,14 @@
434 # Add a new option to the builtin command and506 # Add a new option to the builtin command and
435 # override the inherited run() and help() methods507 # override the inherited run() and help() methods
436508
509 takes_args = builtins.cmd_export.takes_args
437 takes_options = builtins.cmd_export.takes_options + [510 takes_options = builtins.cmd_export.takes_options + [
438 option.RegistryOption('keywords',511 option.RegistryOption('keywords',
439 registry=_keyword_style_registry,512 registry=_keyword_style_registry,
440 converter=lambda s: s,513 converter=lambda s: s,
441 help='Keyword expansion style.')]514 help='Keyword expansion style.')]
442 515
443 def run(self, *args, **kwargs):516 def run(self, dest, branch_or_subdir=None, **kwargs):
444 """Process special options and delegate to superclass."""517 """Process special options and delegate to superclass."""
445 if 'keywords' in kwargs:518 if 'keywords' in kwargs:
446 # Implicitly set the filters option519 # Implicitly set the filters option
@@ -448,15 +521,18 @@
448 style = kwargs['keywords']521 style = kwargs['keywords']
449 _keyword_style_registry.default_key = style522 _keyword_style_registry.default_key = style
450 del kwargs['keywords']523 del kwargs['keywords']
451 return super(cmd_export, self).run(*args, **kwargs)524 revid = None
452 525 if 'revision' in kwargs:
526 revid = kwargs['revision'][0].as_revision_id(b)
527 _get_current(branch_or_subdir,revid)
528 return super(cmd_export, self).run(dest, branch_or_subdir, **kwargs)
529
453 def help(self):530 def help(self):
454 """Return help message including text from superclass."""531 """Return help message including text from superclass."""
455 from inspect import getdoc532 from inspect import getdoc
456 # NOTE: Reuse of cmd_cat help below is deliberate, not a bug533 # NOTE: Reuse of cmd_cat help below is deliberate, not a bug
457 return getdoc(super(cmd_export, self)) + '\n\n' + getdoc(cmd_cat)534 return getdoc(super(cmd_export, self)) + '\n\n' + getdoc(cmd_cat)
458535
459
460# Register the command wrappers536# Register the command wrappers
461commands.register_command(cmd_cat, decorate=False)537commands.register_command(cmd_cat, decorate=False)
462commands.register_command(cmd_export, decorate=False)538commands.register_command(cmd_export, decorate=False)
463539
=== modified file 'tests/test_keywords_in_trees.py'
--- tests/test_keywords_in_trees.py 2009-08-11 05:14:31 +0000
+++ tests/test_keywords_in_trees.py 2010-04-18 08:51:20 +0000
@@ -34,10 +34,13 @@
34Committer-Name: $Committer-Name$34Committer-Name: $Committer-Name$
35Authors: $Authors$35Authors: $Authors$
36Author1-Email: $Author1-Email$36Author1-Email: $Author1-Email$
37Revno: $Revno$
37Revision-Id: $Revision-Id$38Revision-Id: $Revision-Id$
38Filename: $Filename$39Filename: $Filename$
39Directory: $Directory$40Directory: $Directory$
40File-Id: $File-Id$41File-Id: $File-Id$
42CurRevno: $CurRevno$
43CurRevid: $CurRevid
41"""44"""
42#User: $User$45#User: $User$
43#User-Email: $User-Email$46#User-Email: $User-Email$
@@ -46,10 +49,13 @@
46Committer-Name: $Committer-Name: Jane Smith $49Committer-Name: $Committer-Name: Jane Smith $
47Authors: $Authors: Sue Smith <sue@example.com> $50Authors: $Authors: Sue Smith <sue@example.com> $
48Author1-Email: $Author1-Email: sue@example.com $51Author1-Email: $Author1-Email: sue@example.com $
52Revno: $Revno: 1 $
49Revision-Id: $Revision-Id: rev1-id $53Revision-Id: $Revision-Id: rev1-id $
50Filename: $Filename: file1 $54Filename: $Filename: file1 $
51Directory: $Directory: $55Directory: $Directory: $
52File-Id: $File-Id: file1-id $56File-Id: $File-Id: file1-id $
57CurRevno: $CurRevno: 1 $
58CurRevid: $CurRevid: rev1-id $
53"""59"""
54#User: $User: Dave Smith <dave@example.com>$60#User: $User: Dave Smith <dave@example.com>$
55#User-Email: $User-Email: dave@example.com $61#User-Email: $User-Email: dave@example.com $

Subscribers

People subscribed via source and target branches