Rev 2502: Fix Workingtree4.get_file_sha1 on missing files (#118186) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jun 1 23:16:59 BST 2007


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

------------------------------------------------------------
revno: 2502
revision-id: pqm at pqm.ubuntu.com-20070601221655-eeiryluirj5h73hp
parent: pqm at pqm.ubuntu.com-20070601212622-4hy742yfww9270dw
parent: abentley at panoramicfeedback.com-20070601134202-xesyeah3z22v56b4
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-06-01 23:16:55 +0100
message:
  Fix Workingtree4.get_file_sha1 on missing files (#118186)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 2499.3.1
    merged: abentley at panoramicfeedback.com-20070601134202-xesyeah3z22v56b4
    parent: pqm at pqm.ubuntu.com-20070531210833-8ptk86ocu822hjd5
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: fix-118186
    timestamp: Fri 2007-06-01 09:42:02 -0400
    message:
      Fix Workingtree4.get_file_sha1 on missing files
=== modified file 'NEWS'
--- a/NEWS	2007-06-01 05:43:11 +0000
+++ b/NEWS	2007-06-01 22:16:55 +0000
@@ -39,6 +39,9 @@
       into account.
       (Vincent Ladeuil, #112719)
 
+    * WorkingTree4.get_file_sha1 no longer raises an exception when invoked
+      on a missing file.  (Aaron Bentley, #118186)
+
 bzr 0.16  2007-05-07
   
   BUGFIXES:

=== modified file 'bzrlib/tests/workingtree_implementations/test_workingtree.py'
--- a/bzrlib/tests/workingtree_implementations/test_workingtree.py	2007-03-23 01:41:37 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_workingtree.py	2007-06-01 13:42:02 +0000
@@ -825,3 +825,14 @@
             actual_kind = tree.kind(names[i-1] + '-id')
             expected_kind = names[i]
             self.assertEqual(expected_kind, actual_kind)
+
+    def test_missing_file_sha1(self):
+        """If a file is missing, its sha1 should be reported as None."""
+        tree = self.make_branch_and_tree('.')
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+        self.build_tree(['file'])
+        tree.add('file', 'file-id')
+        tree.commit('file added')
+        os.unlink('file')
+        self.assertIs(None, tree.get_file_sha1('file-id'))

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-05-17 18:23:06 +0000
+++ b/bzrlib/workingtree_4.py	2007-06-01 13:42:02 +0000
@@ -414,7 +414,13 @@
         file_abspath = self.abspath(path)
         state = self.current_dirstate()
         if stat_value is None:
-            stat_value = os.lstat(file_abspath)
+            try:
+                stat_value = os.lstat(file_abspath)
+            except OSError, e:
+                if e.errno == errno.ENOENT:
+                    return None
+                else:
+                    raise
         link_or_sha1 = state.update_entry(entry, file_abspath,
                                           stat_value=stat_value)
         if entry[1][0][0] == 'f':




More information about the bazaar-commits mailing list