Merge lp:~jelmer/bzr/847435-diff-time into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 6154
Proposed branch: lp:~jelmer/bzr/847435-diff-time
Merge into: lp:bzr
Diff against target: 95 lines (+32/-2)
5 files modified
bzrlib/tests/per_tree/test_get_file_mtime.py (+9/-0)
bzrlib/tests/per_workingtree/test_get_file_mtime.py (+13/-0)
bzrlib/workingtree.py (+6/-1)
bzrlib/workingtree_4.py (+1/-1)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/847435-diff-time
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+76313@code.launchpad.net

Commit message

Raise NoSuchId from Tree.get_file_mtime if the file id was not found.

Description of the change

Test the Tree.get_file_mtime API to raise NoSuchId if an unknown file id is specified.

the working tree 4 basis tree implementations would return None rather than raising NoSuchId, which was inconsistent with the other tree implementations.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

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

On 9/21/2011 2:49 AM, Jelmer Vernooij wrote:
> Jelmer Vernooij has proposed merging
> lp:~jelmer/bzr/847435-diff-time into lp:bzr.
>
> Requested reviews: bzr-core (bzr-core) Related bugs: Bug #847435 in
> Bazaar: "bzr crashed with TypeError in format_patch_date():
> unsupported operand type(s) for +: 'NoneType' and 'int'"
> https://bugs.launchpad.net/bzr/+bug/847435
>
> For more details, see:
> https://code.launchpad.net/~jelmer/bzr/847435-diff-time/+merge/76313
>
> Test the Tree.get_file_mtime API to raise NoSuchId if an unknown
> file id is specified.
>
> the working tree 4 basis tree implementations would return None
> rather than raising NoSuchId, which was inconsistent with the other
> tree implementations.

 merge: approve

John
=:->

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

iEYEARECAAYFAk55wpUACgkQJdeBCYSNAAPP8ACeI63+qGSFUjZuN7ao6KyBJOCe
xUsAnioPJOLFmkelOa/b0sHlVeE9+psD
=ucm3
-----END PGP SIGNATURE-----

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

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/per_tree/test_get_file_mtime.py'
2--- bzrlib/tests/per_tree/test_get_file_mtime.py 2011-05-13 12:51:05 +0000
3+++ bzrlib/tests/per_tree/test_get_file_mtime.py 2011-09-21 00:52:23 +0000
4@@ -18,6 +18,8 @@
5
6 import time
7
8+from bzrlib import errors
9+
10 from bzrlib.tests.per_tree import TestCaseWithTree
11
12
13@@ -42,3 +44,10 @@
14 'now: %f, mtime_file_id: %f' % (now, mtime_file_id ))
15 mtime_path = tree.get_file_mtime(file_id='one-id', path='one')
16 self.assertEqual(mtime_file_id, mtime_path)
17+
18+ def test_nonexistant(self):
19+ tree = self.get_basic_tree()
20+ tree.lock_read()
21+ self.addCleanup(tree.unlock)
22+ self.assertRaises(errors.NoSuchId,
23+ tree.get_file_mtime, file_id='unexistant')
24
25=== modified file 'bzrlib/tests/per_workingtree/test_get_file_mtime.py'
26--- bzrlib/tests/per_workingtree/test_get_file_mtime.py 2009-07-10 07:14:02 +0000
27+++ bzrlib/tests/per_workingtree/test_get_file_mtime.py 2011-09-21 00:52:23 +0000
28@@ -18,6 +18,7 @@
29
30 import os
31
32+from bzrlib import errors
33 from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
34
35
36@@ -98,3 +99,15 @@
37 self.assertAlmostEqual(st.st_mtime, mtime)
38 finally:
39 tree.unlock()
40+
41+ def test_missing(self):
42+ tree = self.make_basic_tree()
43+
44+ os.remove('tree/one')
45+ tree.lock_read()
46+ try:
47+ self.assertRaises(errors.FileTimestampUnavailable,
48+ tree.get_file_mtime, file_id='one-id')
49+ finally:
50+ tree.unlock()
51+
52
53=== modified file 'bzrlib/workingtree.py'
54--- bzrlib/workingtree.py 2011-09-15 11:31:47 +0000
55+++ bzrlib/workingtree.py 2011-09-21 00:52:23 +0000
56@@ -2134,7 +2134,12 @@
57 """See Tree.get_file_mtime."""
58 if not path:
59 path = self.inventory.id2path(file_id)
60- return os.lstat(self.abspath(path)).st_mtime
61+ try:
62+ return os.lstat(self.abspath(path)).st_mtime
63+ except OSError, e:
64+ if e.errno == errno.ENOENT:
65+ raise errors.FileTimestampUnavailable(path)
66+ raise
67
68 def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
69 file_id = self.path2id(path)
70
71=== modified file 'bzrlib/workingtree_4.py'
72--- bzrlib/workingtree_4.py 2011-08-12 14:47:42 +0000
73+++ bzrlib/workingtree_4.py 2011-09-21 00:52:23 +0000
74@@ -1849,7 +1849,7 @@
75 # Make sure the file exists
76 entry = self._get_entry(file_id, path=path)
77 if entry == (None, None): # do we raise?
78- return None
79+ raise errors.NoSuchId(self, file_id)
80 parent_index = self._get_parent_index()
81 last_changed_revision = entry[1][parent_index][4]
82 try:
83
84=== modified file 'doc/en/release-notes/bzr-2.5.txt'
85--- doc/en/release-notes/bzr-2.5.txt 2011-09-19 15:22:23 +0000
86+++ doc/en/release-notes/bzr-2.5.txt 2011-09-21 00:52:23 +0000
87@@ -35,6 +35,9 @@
88 * Redirects between http and https no longer discard path information
89 in some cases. (Jelmer Vernooij, #853765)
90
91+* ``WorkingTree.get_file_mtime`` now raises NoSuchId if a file id is
92+ specified that is unknown. (Jelmer Vernooij, #847435)
93+
94 Documentation
95 *************
96