Merge lp:~abentley/bzr/last-revision into lp:~bzr/bzr/trunk-old

Proposed by Aaron Bentley
Status: Rejected
Rejected by: Aaron Bentley
Proposed branch: lp:~abentley/bzr/last-revision
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 124 lines
To merge this branch: bzr merge lp:~abentley/bzr/last-revision
Reviewer Review Type Date Requested Status
Martin Pool Needs Information
John A Meinel Needs Information
Ian Clatworthy Approve
Review via email: mp+6742@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

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

Hi all,

This patch cleans up our support for last_revision. This API was
supposed to be deprecated, but has turned out to be too useful.
Therefore, I've added tests and a default implementation on Tree.

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

iEYEARECAAYFAkoWlIEACgkQ0F+nu1YWqI0a/QCfSCzyrts6HY0902CCsW2Mr2F7
rN4An05UjaT5msCupEINNLe3CxPaypof
=GsVB
-----END PGP SIGNATURE-----

Revision history for this message
Ian Clatworthy (ian-clatworthy) :
review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

I use Branch.last_revision() all the time, but I don't feel that maps well into "Tree.last_revision()".

I would really prefer it to use a different name, since it doesn't return the 'same' results. For Tree/WorkingTree it seems to be returning the revision of the left-hand parent, while for Branch it is giving the *current* revision.

Can you define what/where you are using it? (I overlooked this patch originally because I was thinking about Branch.last_revision().)

The code change is fine, I'm just trying to understand the utility of "give me one of, but not all of the parents". Especially considering what answer do we want to give if the left-hand parent is a ghost, etc.

review: Needs Information
Revision history for this message
Martin Pool (mbp) wrote :

I agree with John, this seems kind of questionable.

review: Needs Information
lp:~abentley/bzr/last-revision updated
4378. By Aaron Bentley

Merge bzr.dev ito last-revision.

Unmerged revisions

4378. By Aaron Bentley

Merge bzr.dev ito last-revision.

4377. By Aaron Bentley

Merge bzr.dev into last-revision.

4376. By Aaron Bentley

Clean up last_revision support.

4375. By Aaron Bentley

Implement and test Tree.last_revision.

4374. By Canonical.com Patch Queue Manager <email address hidden>

(abentley) Enable committing from a PreviewTree.

4373. By Canonical.com Patch Queue Manager <email address hidden>

(Jelmer) Mention --default-rich-root rather than a particular format
 in the user guide.

4372. By Canonical.com Patch Queue Manager <email address hidden>

(igc) added osutils.parent_directories() (Ian Clatworthy)

4371. By Canonical.com Patch Queue Manager <email address hidden>

(Jelmer) Make dpush help/error a bit more generic.

4370. By Canonical.com Patch Queue Manager <email address hidden>

(tanner) merge bzr-1.15rc1 to trunk.

4369. By Canonical.com Patch Queue Manager <email address hidden>

(Jelmer) Include stdlib.h for malloc/realloc/free in Pyrex RIO
 implementation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/mutabletree.py'
--- bzrlib/mutabletree.py 2009-04-09 20:23:07 +0000
+++ bzrlib/mutabletree.py 2009-05-28 12:36:11 +0000
@@ -246,22 +246,6 @@
246 """246 """
247 return (self.get_file(file_id, path), None)247 return (self.get_file(file_id, path), None)
248248
249 @needs_read_lock
250 def last_revision(self):
251 """Return the revision id of the last commit performed in this tree.
252
253 In early tree formats the result of last_revision is the same as the
254 branch last_revision, but that is no longer the case for modern tree
255 formats.
256
257 last_revision returns the left most parent id, or None if there are no
258 parents.
259
260 last_revision was deprecated as of 0.11. Please use get_parent_ids
261 instead.
262 """
263 raise NotImplementedError(self.last_revision)
264
265 def lock_tree_write(self):249 def lock_tree_write(self):
266 """Lock the working tree for write, and the branch for read.250 """Lock the working tree for write, and the branch for read.
267251
268252
=== modified file 'bzrlib/tests/tree_implementations/test_tree.py'
--- bzrlib/tests/tree_implementations/test_tree.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/tree_implementations/test_tree.py 2009-05-28 12:36:11 +0000
@@ -18,6 +18,7 @@
18 errors,18 errors,
19 conflicts,19 conflicts,
20 osutils,20 osutils,
21 revision,
21 revisiontree,22 revisiontree,
22 tests,23 tests,
23 workingtree_4,24 workingtree_4,
@@ -292,3 +293,30 @@
292 self.addCleanup(tree.unlock)293 self.addCleanup(tree.unlock)
293 expected = osutils.sha_strings('file content')294 expected = osutils.sha_strings('file content')
294 self.assertEqual(expected, tree.get_file_sha1('file-id'))295 self.assertEqual(expected, tree.get_file_sha1('file-id'))
296
297
298class TestParentIDs(TestCaseWithTree):
299
300 def test_get_parent_ids_NULL(self):
301 work_tree = self.make_branch_and_tree('tree')
302 tree = self._convert_tree(work_tree)
303 self.assertEqual([], tree.get_parent_ids())
304
305 def test_last_revsion_NULL(self):
306 work_tree = self.make_branch_and_tree('tree')
307 tree = self._convert_tree(work_tree)
308 self.assertEqual(revision.NULL_REVISION, tree.last_revision())
309
310 def make_tree_with_commit(self):
311 work_tree = self.make_branch_and_tree('tree')
312 rev_id = work_tree.commit('message')
313 tree = self._convert_tree(work_tree)
314 return tree, rev_id
315
316 def test_get_parent_ids_one(self):
317 tree, rev_id = self.make_tree_with_commit()
318 self.assertEqual([rev_id], tree.get_parent_ids())
319
320 def test_last_revision_one(self):
321 tree, rev_id = self.make_tree_with_commit()
322 self.assertEqual(rev_id, tree.last_revision())
295323
=== modified file 'bzrlib/tree.py'
--- bzrlib/tree.py 2009-05-23 04:55:52 +0000
+++ bzrlib/tree.py 2009-05-28 12:36:11 +0000
@@ -124,6 +124,22 @@
124 """124 """
125 raise NotImplementedError(self.get_parent_ids)125 raise NotImplementedError(self.get_parent_ids)
126126
127 def last_revision(self):
128 """Return the lefthand parent of the tree.
129
130 For working trees, this will be the last revision committed to the
131 tree.
132
133 For trees with no obvious parents, this is revision.NULL_REVISION
134 The default implementation simply uses get_parent_ids.
135 :return: revision_id, as a unicode string.
136 """
137 parent_ids = self.get_parent_ids()
138 if len(parent_ids) > 0:
139 return parent_ids[0]
140 else:
141 return _mod_revision.NULL_REVISION
142
127 def has_filename(self, filename):143 def has_filename(self, filename):
128 """True if the tree has given filename."""144 """True if the tree has given filename."""
129 raise NotImplementedError(self.has_filename)145 raise NotImplementedError(self.has_filename)
130146
=== modified file 'bzrlib/workingtree_4.py'
--- bzrlib/workingtree_4.py 2009-05-23 04:55:52 +0000
+++ bzrlib/workingtree_4.py 2009-05-28 12:36:11 +0000
@@ -57,6 +57,7 @@
57 textui,57 textui,
58 trace,58 trace,
59 transform,59 transform,
60 tree,
60 urlutils,61 urlutils,
61 views,62 views,
62 xml5,63 xml5,
@@ -583,13 +584,9 @@
583 return kind584 return kind
584585
585 @needs_read_lock586 @needs_read_lock
586 def _last_revision(self):587 def last_revision(self):
587 """See Mutable.last_revision."""588 """See Mutable.last_revision."""
588 parent_ids = self.current_dirstate().get_parent_ids()589 return tree.Tree.last_revision(self)
589 if parent_ids:
590 return parent_ids[0]
591 else:
592 return _mod_revision.NULL_REVISION
593590
594 def lock_read(self):591 def lock_read(self):
595 """See Branch.lock_read, and WorkingTree.unlock."""592 """See Branch.lock_read, and WorkingTree.unlock."""