]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/tvfs.py
vfs2: distinguish commits with a Commit type
[bup.git] / lib / bup / t / tvfs.py
index e8387c0089eaf5b7a8eb884556459dc316f4d91e..c0630125d539de2069f371aa4210e544bb684639 100644 (file)
@@ -35,7 +35,7 @@ def tree_items(repo, oid):
     """
     # This is a simpler approach than the one in the vfs, used to
     # cross-check its behavior.
-    tree_data, bupm_oid = vfs._tree_data_and_bupm(repo, oid)
+    tree_data, bupm_oid = vfs.tree_data_and_bupm(repo, oid)
     bupm = vfs._FileReader(repo, bupm_oid) if bupm_oid else None
     try:
         maybe_meta = lambda : Metadata.read(bupm) if bupm else None
@@ -129,6 +129,18 @@ def test_item_mode():
         wvpasseq(mode, vfs.item_mode(vfs.Item(oid=oid, meta=mode)))
         wvpasseq(meta.mode, vfs.item_mode(vfs.Item(oid=oid, meta=meta)))
 
+@wvtest
+def test_reverse_suffix_duplicates():
+    suffix = lambda x: tuple(vfs._reverse_suffix_duplicates(x))
+    wvpasseq(('x',), suffix(('x',)))
+    wvpasseq(('x', 'y'), suffix(('x', 'y')))
+    wvpasseq(('x-1', 'x-0'), suffix(('x',) * 2))
+    wvpasseq(['x-%02d' % n for n in reversed(range(11))],
+             list(suffix(('x',) * 11)))
+    wvpasseq(('x-1', 'x-0', 'y'), suffix(('x', 'x', 'y')))
+    wvpasseq(('x', 'y-1', 'y-0'), suffix(('x', 'y', 'y')))
+    wvpasseq(('x', 'y-1', 'y-0', 'z'), suffix(('x', 'y', 'y', 'z')))
+
 @wvtest
 def test_misc():
     with no_lingering_errors():
@@ -252,8 +264,9 @@ def test_resolve():
             wvpasseq((('', vfs._root), ('test', test_revlist)), res)
             ignore, test_item = res[1]
             test_content = frozenset(vfs.contents(repo, test_item))
-            expected_latest_item = vfs.Item(meta=S_IFDIR | 0o755,
-                                                    oid=tip_tree_oid)
+            expected_latest_item = vfs.Commit(meta=S_IFDIR | 0o755,
+                                              oid=tip_tree_oid,
+                                              coid=tip_oid)
             wvpasseq(frozenset([('.', test_revlist),
                                 (save_time_str, expected_latest_item),
                                 ('latest', expected_latest_item)]),
@@ -262,8 +275,9 @@ def test_resolve():
             wvstart('resolve: /test/latest')
             res = resolve(repo, '/test/latest')
             wvpasseq(3, len(res))
-            expected_latest_item_w_meta = vfs.Item(meta=tip_tree['.'].meta,
-                                                   oid=tip_tree_oid)
+            expected_latest_item_w_meta = vfs.Commit(meta=tip_tree['.'].meta,
+                                                     oid=tip_tree_oid,
+                                                     coid=tip_oid)
             expected = (('', vfs._root),
                         ('test', test_revlist),
                         ('latest', expected_latest_item_w_meta))
@@ -373,4 +387,41 @@ def test_contents_with_mismatched_bupm_git_ordering():
             name, item = next(((n, i) for n, i in contents if n == 'foo.'))
             wvpass(S_ISREG(item.meta.mode))
 
+@wvtest
+def test_duplicate_save_dates():
+    with no_lingering_errors():
+        with test_tempdir('bup-tvfs-') as tmpdir:
+            bup_dir = tmpdir + '/bup'
+            environ['GIT_DIR'] = bup_dir
+            environ['BUP_DIR'] = bup_dir
+            environ['TZ'] = 'UTC'
+            git.repodir = bup_dir
+            data_path = tmpdir + '/src'
+            os.mkdir(data_path)
+            with open(data_path + '/file', 'w+') as tmpfile:
+                tmpfile.write(b'canary\n')
+            ex((bup_path, 'init'))
+            ex((bup_path, 'index', '-v', data_path))
+            for i in range(11):
+                ex((bup_path, 'save', '-d', '100000', '-n', 'test', data_path))
+            repo = LocalRepo()
+            res = vfs.resolve(repo, '/test')
+            wvpasseq(2, len(res))
+            name, revlist = res[-1]
+            wvpasseq('test', name)
+            wvpasseq(('.',
+                      '1970-01-02-034640-10',
+                      '1970-01-02-034640-09',
+                      '1970-01-02-034640-08',
+                      '1970-01-02-034640-07',
+                      '1970-01-02-034640-06',
+                      '1970-01-02-034640-05',
+                      '1970-01-02-034640-04',
+                      '1970-01-02-034640-03',
+                      '1970-01-02-034640-02',
+                      '1970-01-02-034640-01',
+                      '1970-01-02-034640-00',
+                      'latest'),
+                     tuple(x[0] for x in vfs.contents(repo, revlist)))
+
 # FIXME: add tests for the want_meta=False cases.