Rev 2709: New commit --author option (Lukas Lalinsky) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Aug 16 01:00:48 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2709
revision-id: pqm at pqm.ubuntu.com-20070816000043-v5y51f50iolj5he7
parent: pqm at pqm.ubuntu.com-20070815225233-w4gpchswmwvqi12r
parent: abentley at panoramicfeedback.com-20070815214036-tl3ewb659k970o2m
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-08-16 01:00:43 +0100
message:
  New commit --author option (Lukas Lalinsky)
added:
  doc/developers/revision-properties.txt revisionproperties.t-20070807133526-w57m8zv5o7t5kugm-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
  bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
  bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
  bzrlib/tests/test_commit.py    test_commit.py-20050914060732-279f057f8c295434
  bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
    ------------------------------------------------------------
    revno: 2671.2.9
    merged: abentley at panoramicfeedback.com-20070815214036-tl3ewb659k970o2m
    parent: abentley at panoramicfeedback.com-20070815160631-0nynxmmpqgu8h5i8
    parent: pqm at pqm.ubuntu.com-20070815213042-m6nonfyi3cqcq5qc
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: Aaron's integration
    timestamp: Wed 2007-08-15 17:40:36 -0400
    message:
      Merge bzr.dev
    ------------------------------------------------------------
    revno: 2671.2.8
    merged: abentley at panoramicfeedback.com-20070815160631-0nynxmmpqgu8h5i8
    parent: abentley at panoramicfeedback.com-20070815160513-aepyrd0uu9vtedsy
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: Aaron's integration
    timestamp: Wed 2007-08-15 12:06:31 -0400
    message:
      Clean up trailing whitespace
    ------------------------------------------------------------
    revno: 2671.2.7
    merged: abentley at panoramicfeedback.com-20070815160513-aepyrd0uu9vtedsy
    parent: lalinsky at gmail.com-20070808054343-598cls6ybso02utp
    parent: pqm at pqm.ubuntu.com-20070815125647-dx6if7e1osu5fnze
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: Aaron's integration
    timestamp: Wed 2007-08-15 12:05:13 -0400
    message:
      Merge bzr.dev
    ------------------------------------------------------------
    revno: 2671.2.6
    merged: lalinsky at gmail.com-20070808054343-598cls6ybso02utp
    parent: lalinsky at gmail.com-20070807204521-q9iwgzhwei1sf96h
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Wed 2007-08-08 07:43:43 +0200
    message:
      Nuke test_commit_author_conflict.
    ------------------------------------------------------------
    revno: 2671.2.5
    merged: lalinsky at gmail.com-20070807204521-q9iwgzhwei1sf96h
    parent: lalinsky at gmail.com-20070807145735-373c9kkog1lu3w9m
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Tue 2007-08-07 22:45:21 +0200
    message:
      Fixes for comments from the mailing list.
      
       - Raise AssertionError from MutableTree.commit if both author kwarg and revprop are set.
       - Fixed code formatting in LongLogFormatter.log_revision.
       - Fixed punctuation in the developer docs.
    ------------------------------------------------------------
    revno: 2671.2.4
    merged: lalinsky at gmail.com-20070807145735-373c9kkog1lu3w9m
    parent: lalinsky at gmail.com-20070807134037-layt7j3smgzzh4f6
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Tue 2007-08-07 16:57:35 +0200
    message:
      Fixed broken test_author_* blackbox tests.
    ------------------------------------------------------------
    revno: 2671.2.3
    merged: lalinsky at gmail.com-20070807134037-layt7j3smgzzh4f6
    parent: lalinsky at gmail.com-20070807130829-0m0eg3r8i587mtym
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Tue 2007-08-07 15:40:37 +0200
    message:
      Added NEWS entry and a developer documentation about revision properties.
    ------------------------------------------------------------
    revno: 2671.2.2
    merged: lalinsky at gmail.com-20070807130829-0m0eg3r8i587mtym
    parent: lalinsky at gmail.com-20070804122704-e907ln9qy3binzot
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Tue 2007-08-07 15:08:29 +0200
    message:
      Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
    ------------------------------------------------------------
    revno: 2671.2.1
    merged: lalinsky at gmail.com-20070804122704-e907ln9qy3binzot
    parent: pqm at pqm.ubuntu.com-20070803043116-l7u1uypblmx1uxnr
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: author
    timestamp: Sat 2007-08-04 14:27:04 +0200
    message:
      Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
=== added file 'doc/developers/revision-properties.txt'
--- a/doc/developers/revision-properties.txt	1970-01-01 00:00:00 +0000
+++ b/doc/developers/revision-properties.txt	2007-08-07 20:45:21 +0000
@@ -0,0 +1,42 @@
+Revision Properties
+===================
+
+Bazaar repositories support setting of a key/value pairs for each revision.
+Applications can use these properties to store additional information
+about the revision.
+
+Usage
+-----
+
+In general, revision properties are set by passing keyword argument
+``revprops`` to method ``MutableTree.commit``. For example::
+
+ properties = {}
+ properties['my-property'] = 'test'
+ tree.commit(message, revprops=properties)
+
+Properties can be retrieved via the attribute ``properties`` of
+instances of the class ``Revision``::
+
+ if 'my-property' in revision.properties:
+     my_property = revision.properties['my-property']
+     ...
+
+Well-known properties
+---------------------
+
+At the moment, three standardized revision properties are recognized and used
+by bzrlib:
+
+ * ``author`` - Author of the change. This value is in the same format as
+   the committer-id. This property can be set by passing keyword argument
+   ``author`` to function ``MutableTree.commit``.
+ * ``branch-nick`` - Nickname of the branch. It's either the directory name
+   or manually set by ``bzr nick``. The value is set automatically in
+   ``MutableTree.commit``.
+ * ``bugs`` - A list of bug URLs and their statuses. The list is separated
+   by the new-line character (\n) and each entry is in format
+   '<URL> <status>'. Currently, bzrlib uses only status 'fixed'. See
+   `Bug Trackers`_ for more details about using this feature.
+
+.. _Bug Trackers: ../bug_trackers.htm

=== modified file 'NEWS'
--- a/NEWS	2007-08-15 16:39:50 +0000
+++ b/NEWS	2007-08-15 21:40:36 +0000
@@ -8,6 +8,8 @@
     * ``pull -v`` no longer includes deltas, making it much faster.
       (Aaron Bentley)
 
+    * New option ``--author`` in ``bzr commit`` to specify the author of the
+      change, if it's different from the committer.  (Lukáš Lalinský)
 
 bzr 0.90rc1 2007-08-14
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-08-15 05:56:03 +0000
+++ b/bzrlib/builtins.py	2007-08-15 16:05:13 +0000
@@ -2146,6 +2146,10 @@
     committed.  If a directory is specified then the directory and everything 
     within it is committed.
 
+    If author of the change is not the same person as the committer, you can
+    specify the author's name using the --author option. The name should be
+    in the same format as a committer-id, e.g. "John Doe <jdoe at example.com>".
+
     A selected-file commit may fail in some cases where the committed
     tree would be invalid. Consider::
 
@@ -2192,6 +2196,9 @@
                     "files in the working tree."),
              ListOption('fixes', type=str,
                     help="Mark a bug as being fixed by this revision."),
+             Option('author', type=str,
+                    help="Set the author's name, if it's different "
+                         "from the committer."),
              Option('local',
                     help="Perform a local commit in a bound "
                          "branch.  Local commits are not pushed to "
@@ -2224,7 +2231,8 @@
         return '\n'.join(properties)
 
     def run(self, message=None, file=None, verbose=True, selected_list=None,
-            unchanged=False, strict=False, local=False, fixes=None):
+            unchanged=False, strict=False, local=False, fixes=None,
+            author=None):
         from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
         from bzrlib.errors import (PointlessCommit, ConflictsInTree,
                 StrictCommitFailed)
@@ -2281,7 +2289,8 @@
             tree.commit(message_callback=get_message,
                         specific_files=selected_list,
                         allow_pointless=unchanged, strict=strict, local=local,
-                        reporter=reporter, revprops=properties)
+                        reporter=reporter, revprops=properties,
+                        author=author)
         except PointlessCommit:
             # FIXME: This should really happen before the file is read in;
             # perhaps prepare the commit; get the message; then actually commit

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2007-07-31 16:33:46 +0000
+++ b/bzrlib/log.py	2007-08-15 16:05:13 +0000
@@ -619,36 +619,39 @@
     def log_revision(self, revision):
         """Log a revision, either merged or not."""
         from bzrlib.osutils import format_date
-        indent = '    '*revision.merge_depth
+        indent = '    ' * revision.merge_depth
         to_file = self.to_file
-        print >>to_file,  indent+'-' * 60
+        print >>to_file, indent + '-' * 60
         if revision.revno is not None:
-            print >>to_file,  indent+'revno:', revision.revno
+            print >>to_file, indent + 'revno:', revision.revno
         if revision.tags:
-            print >>to_file, indent+'tags: %s' % (', '.join(revision.tags))
+            print >>to_file, indent + 'tags: %s' % (', '.join(revision.tags))
         if self.show_ids:
-            print >>to_file, indent+'revision-id:', revision.rev.revision_id
+            print >>to_file, indent + 'revision-id:', revision.rev.revision_id
             for parent_id in revision.rev.parent_ids:
-                print >>to_file, indent+'parent:', parent_id
-        print >>to_file, indent+'committer:', revision.rev.committer
-
-        try:
-            print >>to_file, indent+'branch nick: %s' % \
-                revision.rev.properties['branch-nick']
-        except KeyError:
-            pass
+                print >>to_file, indent + 'parent:', parent_id
+        print >>to_file, indent + 'committer:', revision.rev.committer
+
+        author = revision.rev.properties.get('author', None)
+        if author is not None:
+            print >>to_file, indent + 'author:', author
+
+        branch_nick = revision.rev.properties.get('branch-nick', None)
+        if branch_nick is not None:
+            print >>to_file, indent + 'branch nick:', branch_nick
+
         date_str = format_date(revision.rev.timestamp,
                                revision.rev.timezone or 0,
                                self.show_timezone)
-        print >>to_file,  indent+'timestamp: %s' % date_str
+        print >>to_file, indent + 'timestamp: %s' % date_str
 
-        print >>to_file,  indent+'message:'
+        print >>to_file, indent + 'message:'
         if not revision.rev.message:
-            print >>to_file,  indent+'  (no message)'
+            print >>to_file, indent + '  (no message)'
         else:
             message = revision.rev.message.rstrip('\r\n')
             for l in message.split('\n'):
-                print >>to_file,  indent+'  ' + l
+                print >>to_file, indent + '  ' + l
         if revision.delta is not None:
             revision.delta.show(to_file, self.show_ids, indent=indent)
 

=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py	2007-07-04 18:24:24 +0000
+++ b/bzrlib/mutabletree.py	2007-08-07 20:45:21 +0000
@@ -201,6 +201,10 @@
             revprops = {}
         if not 'branch-nick' in revprops:
             revprops['branch-nick'] = self.branch.nick
+        author = kwargs.pop('author', None)
+        if author is not None:
+            assert 'author' not in revprops
+            revprops['author'] = author
         # args for wt.commit start at message from the Commit.commit method,
         args = (message, ) + args
         committed_id = commit.Commit().commit(working_tree=self,

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2007-07-13 02:23:34 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2007-08-07 14:57:35 +0000
@@ -470,3 +470,37 @@
              r"Commit refused\."],
             'commit -m add-b --fixes=orange',
             working_dir='tree')
+
+    def test_no_author(self):
+        """If the author is not specified, the author property is not set."""
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/hello.txt'])
+        tree.add('hello.txt')
+        self.run_bzr( 'commit -m hello tree/hello.txt')
+        last_rev = tree.branch.repository.get_revision(tree.last_revision())
+        properties = last_rev.properties
+        self.assertFalse('author' in properties)
+
+    def test_author_sets_property(self):
+        """commit --author='John Doe <jdoe at example.com>' sets the author
+           revprop.
+        """
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/hello.txt'])
+        tree.add('hello.txt')
+        self.run_bzr("commit -m hello --author='John Doe <jdoe at example.com>' "
+                     "tree/hello.txt")
+        last_rev = tree.branch.repository.get_revision(tree.last_revision())
+        properties = last_rev.properties
+        self.assertEqual('John Doe <jdoe at example.com>', properties['author'])
+
+    def test_author_no_email(self):
+        """Author's name without an email address is allowed, too."""
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/hello.txt'])
+        tree.add('hello.txt')
+        out, err = self.run_bzr("commit -m hello --author='John Doe' "
+                                "tree/hello.txt")
+        last_rev = tree.branch.repository.get_revision(tree.last_revision())
+        properties = last_rev.properties
+        self.assertEqual('John Doe', properties['author'])

=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py	2007-07-13 02:23:34 +0000
+++ b/bzrlib/tests/test_commit.py	2007-08-08 05:43:43 +0000
@@ -695,3 +695,22 @@
         self.assertEqual(['bar', 'baz'], err.files)
         self.assertEqual('Selected-file commit of merges is not supported'
                          ' yet: files bar, baz', str(err))
+
+    def test_commit_no_author(self):
+        """The default kwarg author in MutableTree.commit should not add
+        the 'author' revision property.
+        """
+        tree = self.make_branch_and_tree('foo')
+        rev_id = tree.commit('commit 1')
+        rev = tree.branch.repository.get_revision(rev_id)
+        self.assertFalse('author' in rev.properties)
+
+    def test_commit_author(self):
+        """Passing a non-empty author kwarg to MutableTree.commit should add
+        the 'author' revision property.
+        """
+        tree = self.make_branch_and_tree('foo')
+        rev_id = tree.commit('commit 1', author='John Doe <jdoe at example.com>')
+        rev = tree.branch.repository.get_revision(rev_id)
+        self.assertEqual('John Doe <jdoe at example.com>',
+                         rev.properties['author'])

=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2007-07-31 16:33:46 +0000
+++ b/bzrlib/tests/test_log.py	2007-08-15 16:05:13 +0000
@@ -428,6 +428,35 @@
   simple log message
 """)
 
+    def test_author_in_log(self):
+        """Log includes the author name if it's set in
+        the revision properties
+        """
+        wt = self.make_branch_and_tree('.')
+        b = wt.branch
+        self.build_tree(['a'])
+        wt.add('a')
+        b.nick = 'test_author_log'
+        wt.commit(message='add a',
+                  timestamp=1132711707,
+                  timezone=36000,
+                  committer='Lorem Ipsum <test at example.com>',
+                  author='John Doe <jdoe at example.com>')
+        sio = StringIO()
+        formatter = LongLogFormatter(to_file=sio)
+        show_log(b, formatter)
+        self.assertEqualDiff(sio.getvalue(), '''\
+------------------------------------------------------------
+revno: 1
+committer: Lorem Ipsum <test at example.com>
+author: John Doe <jdoe at example.com>
+branch nick: test_author_log
+timestamp: Wed 2005-11-23 12:08:27 +1000
+message:
+  add a
+''')
+
+
 
 class TestLineLogFormatter(TestCaseWithTransport):
 




More information about the bazaar-commits mailing list