from __future__ import absolute_import, print_function
from binascii import hexlify, unhexlify
from collections import namedtuple
-from errno import EINVAL, ELOOP, ENOENT, ENOTDIR
-from itertools import chain, dropwhile, groupby, tee
+from errno import EINVAL, ELOOP, ENOTDIR
+from itertools import chain, groupby, tee
from random import randrange
from stat import S_IFDIR, S_IFLNK, S_IFREG, S_ISDIR, S_ISLNK, S_ISREG
from time import localtime, strftime
import re, sys
-from bup import git, metadata, vint
-from bup.compat import hexstr, range
-from bup.git import BUP_CHUNKED, cp, get_commit_items, parse_commit, tree_decode
+from bup import git, vint
+from bup.compat import hexstr, range, str_type
+from bup.git import BUP_CHUNKED, parse_commit, tree_decode
from bup.helpers import debug2, last
from bup.io import path_msg
from bup.metadata import Metadata
if not self._size:
self._size = _normal_or_chunked_file_size(self._repo, self.oid)
return self._size
-
+
def seek(self, ofs):
if ofs < 0 or ofs > self._compute_size():
raise IOError(EINVAL, 'Invalid seek offset: %d' % ofs)
if not parts:
must_be_dir = True # e.g. path was effectively '.' or '/', etc.
return is_absolute, must_be_dir, parts
-
+
Item = namedtuple('Item', ('meta', 'oid'))
Chunky = namedtuple('Chunky', ('meta', 'oid'))
RevList = namedtuple('RevList', ('meta', 'oid'))
Commit = namedtuple('Commit', ('meta', 'oid', 'coid'))
-item_types = frozenset((Item, Chunky, Root, Tags, RevList, Commit))
-real_tree_types = frozenset((Item, Commit))
+item_types = (Item, Chunky, Root, Tags, RevList, Commit)
+real_tree_types = (Item, Commit)
def write_item(port, item):
kind = type(item)
rvl:OID -> {'.', commit, '2012...', next_commit, ...}
"""
# Suspect we may eventually add "(container_oid, name) -> ...", and others.
- x_t = type(x)
- if x_t is bytes:
+ if isinstance(x, bytes):
tag = x[:4]
if tag in (b'itm:', b'rvl:') and len(x) == 24:
return True
"""Return (tree_bytes, bupm_oid) where bupm_oid will be None if the
tree has no metadata (i.e. older bup save, or non-bup tree).
- """
+ """
assert len(oid) == 20
it = repo.cat(hexlify(oid))
_, item_t, size = next(it)
tree_ents = sorted(tree_ents, key=lambda x: x[0])
for ent in tree_ents:
yield ent
-
+
def tree_items(oid, tree_data, names=frozenset(), bupm=None):
def tree_item(ent_oid, kind, gitmode):
# Assumes the tree is properly formed, i.e. there are no
# duplicates, and entries will be in git tree order.
- if type(names) not in (frozenset, set):
+ if isinstance(names, (frozenset, set)):
names = frozenset(names)
remaining = len(names)
yield item
_save_name_rx = re.compile(br'^\d\d\d\d-\d\d-\d\d-\d{6}(-\d+)?$')
-
+
def _reverse_suffix_duplicates(strs):
"""Yields the elements of strs, with any runs of duplicate values
suffixed with -N suffixes, where the zero padded integer N
return
# Assumes no duplicate refs
- if type(names) not in (frozenset, set):
+ if isinstance(names, (frozenset, set)):
names = frozenset(names)
remaining = len(names)
last_name = max(names)
global _root, _tags
assert repo
assert S_ISDIR(item_mode(item))
- item_t = type(item)
- if item_t in real_tree_types:
+ if isinstance(item, real_tree_types):
it = repo.cat(hexlify(item.oid))
_, obj_t, size = next(it)
data = b''.join(it)
item_gen = tree_items_with_meta(repo, item.oid, data, names)
else:
item_gen = tree_items(item.oid, data, names)
- elif item_t == RevList:
+ elif isinstance(item, RevList):
item_gen = revlist_items(repo, item.oid, names,
require_meta=want_meta)
- elif item_t == Root:
+ elif isinstance(item, Root):
item_gen = root_items(repo, names, want_meta)
- elif item_t == Tags:
+ elif isinstance(item, Tags):
item_gen = tags_items(repo, names)
else:
raise Exception('unexpected VFS item ' + str(item))
if parent:
for x in parent:
assert len(x) == 2
- assert type(x[0]) in (bytes, str)
- assert type(x[1]) in item_types
+ assert isinstance(x[0], (bytes, str_type))
+ assert isinstance(x[1], item_types)
assert parent[0][1] == _root
if not S_ISDIR(item_mode(parent[-1][1])):
raise IOError(ENOTDIR,
raise_dir_required_but_not_dir(path, parent, past)
return notice_resolution(tuple(past))
# It's treeish
- if want_meta and type(item) in real_tree_types:
+ if want_meta and isinstance(item, real_tree_types):
dir_meta = _find_treeish_oid_metadata(repo, item.oid)
if dir_meta:
item = item._replace(meta=dir_meta)
else:
future.extend(target_future)
hops += 1
-
+
def resolve(repo, path, parent=None, want_meta=True, follow=True):
"""Follow the path in the virtual filesystem and return a tuple
representing the location, if any, denoted by the path. Each