def _mksubs(self): self._subs = {} heads = git.list_refs(repo_dir=self._repo_dir, limit_to_heads=True) tags = git.list_refs(repo_dir=self._repo_dir, limit_to_tags=True) tags, tags_dup = tee(tags) tags_info = git.object_info((x[1].encode('hex') for x in tags_dup), repo_dir=self._repo_dir) commit_tags = (ref for ref, info in izip(tags, tags_info) if info[1] == 'commit') for ref in sorted(chain(heads, commit_tags)): #debug2('ref name: %s\n' % ref[0]) revs = git.rev_list(ref[1].encode('hex'), repo_dir = self._repo_dir) for (date, commit) in revs: #debug2('commit: %s date: %s\n' % (commit.encode('hex'), date)) commithex = commit.encode('hex') containername = commithex[:2] dirname = commithex[2:] n1 = self._subs.get(containername) if not n1: n1 = CommitList(self, containername, self._repo_dir) self._subs[containername] = n1 if n1.commits.get(dirname): # Stop work for this ref, the rest should already be present break n1.commits[dirname] = (commit, date)
def find_live_objects(existing_count, cat_pipe, opt): prune_visited_trees = True # In case we want a command line option later pack_dir = git.repo('objects/pack') ffd, bloom_filename = tempfile.mkstemp('.bloom', 'tmp-gc-', pack_dir) os.close(ffd) # FIXME: allow selection of k? # FIXME: support ephemeral bloom filters (i.e. *never* written to disk) live_objs = bloom.create(bloom_filename, expected=existing_count, k=None) stop_at, trees_visited = None, None if prune_visited_trees: trees_visited = set() stop_at = lambda (x): x.decode('hex') in trees_visited approx_live_count = 0 for ref_name, ref_id in git.list_refs(): for item in walk_object(cat_pipe, ref_id.encode('hex'), stop_at=stop_at, include_data=None): # FIXME: batch ids if opt.verbose: report_live_item(approx_live_count, existing_count, ref_name, ref_id, item) bin_id = item.id.decode('hex') if trees_visited is not None and item.type == 'tree': trees_visited.add(bin_id) if opt.verbose: if not live_objs.exists(bin_id): live_objs.add(bin_id) approx_live_count += 1 else: live_objs.add(bin_id) trees_visited = None if opt.verbose: log('expecting to retain about %.2f%% unnecessary objects\n' % live_objs.pfalse_positive()) return live_objs
def find_live_objects(existing_count, cat_pipe, verbosity=0): prune_visited_trees = True # In case we want a command line option later pack_dir = git.repo(b'objects/pack') ffd, bloom_filename = tempfile.mkstemp(b'.bloom', b'tmp-gc-', pack_dir) os.close(ffd) # FIXME: allow selection of k? # FIXME: support ephemeral bloom filters (i.e. *never* written to disk) live_objs = bloom.create(bloom_filename, expected=existing_count, k=None) # live_objs will hold on to the fd until close or exit os.unlink(bloom_filename) stop_at, trees_visited = None, None if prune_visited_trees: trees_visited = set() stop_at = lambda x: unhexlify(x) in trees_visited approx_live_count = 0 for ref_name, ref_id in git.list_refs(): for item in walk_object(cat_pipe.get, hexlify(ref_id), stop_at=stop_at, include_data=None): # FIXME: batch ids if verbosity: report_live_item(approx_live_count, existing_count, ref_name, ref_id, item, verbosity) if trees_visited is not None and item.type == b'tree': trees_visited.add(item.oid) if verbosity: if not live_objs.exists(item.oid): live_objs.add(item.oid) approx_live_count += 1 else: live_objs.add(item.oid) trees_visited = None if verbosity: log('expecting to retain about %.2f%% unnecessary objects\n' % live_objs.pfalse_positive()) return live_objs
def _mksubs(self): self._subs = {} tags = git.list_refs(repo_dir=self._repo_dir, limit_to_tags=True) tags, tags_dup = tee(tags) tags_info = git.object_info((x[1].encode('hex') for x in tags_dup), repo_dir=self._repo_dir) for (name, sha), info in izip(tags, tags_info): assert(name.startswith('refs/tags/')) name = name[10:] commithex = sha.encode('hex') type = info[1] if type == 'commit': # FIXME: handle this in bulk. date = git.get_commit_dates([sha.encode('hex')], repo_dir=self._repo_dir)[0] target = '../.commit/%s/%s' % (commithex[:2], commithex[2:]) tag1 = CommitLink(self, name, target, repo_dir=self._repo_dir) tag1.ctime = tag1.mtime = date elif type == 'tree': tag1 = Dir(self, name, GIT_MODE_TREE, sha, repo_dir=self._repo_dir) elif type == 'blob': tag1 = File(self, name, GIT_MODE_FILE, sha, git.BUP_NORMAL, repo_dir=self._repo_dir) else: assert(False) self._subs[name] = tag1
def _mksubs(self): self._subs = {} for (name,sha) in git.list_refs(): if name.startswith('refs/heads/'): name = name[11:] date = git.rev_get_date(sha.encode('hex')) n1 = CommitList(self, name, sha) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} for (name, sha) in git.list_refs(): if name.startswith('refs/tags/'): name = name[10:] date = git.rev_get_date(sha.encode('hex')) commithex = sha.encode('hex') target = '../.commit/%s/%s' % (commithex[:2], commithex[2:]) tag1 = FakeSymlink(self, name, target) tag1.ctime = tag1.mtime = date self._subs[name] = tag1
def _mksubs(self): self._subs = {} for (name, sha) in git.list_refs(repo_dir=self._repo_dir): if name.startswith("refs/tags/"): name = name[10:] date = git.get_commit_dates([sha.encode("hex")], repo_dir=self._repo_dir)[0] commithex = sha.encode("hex") target = "../.commit/%s/%s" % (commithex[:2], commithex[2:]) tag1 = FakeSymlink(self, name, target, repo_dir, self._repo_dir) tag1.ctime = tag1.mtime = date self._subs[name] = tag1
def _mksubs(self): self._subs = {} for (name, sha) in git.list_refs(repo_dir = self._repo_dir): if name.startswith('refs/tags/'): name = name[10:] date = git.get_commit_dates([sha.encode('hex')], repo_dir=self._repo_dir)[0] commithex = sha.encode('hex') target = '../.commit/%s/%s' % (commithex[:2], commithex[2:]) tag1 = FakeSymlink(self, name, target, self._repo_dir) tag1.ctime = tag1.mtime = date self._subs[name] = tag1
def _mksubs(self): self._subs = {} self._nlinks_for_dir = 2 for (name, sha) in git.list_refs(): if name.startswith('refs/tags/'): name = name[10:] date = git.rev_get_date(sha.encode('hex')) commithex = sha.encode('hex') target = '../.commit/%s/%s' % (commithex[:2], commithex[2:]) tag1 = FakeSymlink(self, name, target) tag1._set_time_nsec_from_git_date(date) self._subs[name] = tag1
def refs(conn, args): limit_to_heads, limit_to_tags = args.split() assert limit_to_heads in ('0', '1') assert limit_to_tags in ('0', '1') limit_to_heads = int(limit_to_heads) limit_to_tags = int(limit_to_tags) _init_session() patterns = tuple(x[:-1] for x in lines_until_sentinel(conn, '\n', Exception)) for name, oid in git.list_refs(patterns=patterns, limit_to_heads=limit_to_heads, limit_to_tags=limit_to_tags): assert '\n' not in name conn.write('%s %s\n' % (oid.encode('hex'), name)) conn.write('\n') conn.ok()
def _mksubs(self): self._subs = {} commit_dir = CommitDir(self, '.commit') self._subs['.commit'] = commit_dir tag_dir = TagDir(self, '.tag') self._subs['.tag'] = tag_dir for (name, sha) in git.list_refs(): if name.startswith('refs/heads/'): name = name[11:] date = git.rev_get_date(sha.encode('hex')) n1 = BranchList(self, name, sha) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} commit_dir = CommitDir(self, '.commit') self._subs['.commit'] = commit_dir tag_dir = TagDir(self, '.tag') self._subs['.tag'] = tag_dir for (name,sha) in git.list_refs(): if name.startswith('refs/heads/'): name = name[11:] date = git.rev_get_date(sha.encode('hex')) n1 = BranchList(self, name, sha) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} commit_dir = CommitDir(self, ".commit", self._repo_dir) self._subs[".commit"] = commit_dir tag_dir = TagDir(self, ".tag", self._repo_dir) self._subs[".tag"] = tag_dir refs_info = [ (name[11:], sha) for (name, sha) in git.list_refs(repo_dir=self._repo_dir) if name.startswith("refs/heads/") ] dates = git.get_commit_dates([sha.encode("hex") for (name, sha) in refs_info], repo_dir=self._repo_dir) for (name, sha), date in zip(refs_info, dates): n1 = BranchList(self, name, sha, self._repo_dir) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} commit_dir = CommitDir(self, '.commit', self._repo_dir) self._subs['.commit'] = commit_dir tag_dir = TagDir(self, '.tag', self._repo_dir) self._subs['.tag'] = tag_dir refs_info = [(name[11:], sha) for (name, sha) in git.list_refs(repo_dir=self._repo_dir) if name.startswith('refs/heads/')] dates = git.get_commit_dates( [sha.encode('hex') for (name, sha) in refs_info], repo_dir=self._repo_dir) for (name, sha), date in zip(refs_info, dates): n1 = BranchList(self, name, sha, self._repo_dir) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} commit_dir = CommitDir(self, '.commit') self._subs['.commit'] = commit_dir tag_dir = TagDir(self, '.tag') self._subs['.tag'] = tag_dir refs_info = [(name[11:], sha) for (name,sha) in git.list_refs() \ if name.startswith('refs/heads/')] dates = git.get_commit_dates([sha.encode('hex') for (name, sha) in refs_info]) for (name, sha), date in zip(refs_info, dates): n1 = BranchList(self, name, sha) n1.ctime = n1.mtime = date self._subs[name] = n1
def _mksubs(self): self._subs = {} self._nlinks_for_dir = 4 commit_dir = CommitDir(self, '.commit') self._subs['.commit'] = commit_dir commit_dir._try_set_inode(3) tag_dir = TagDir(self, '.tag') self._subs['.tag'] = tag_dir tag_dir._try_set_inode(4) for (name,sha) in git.list_refs(): if name.startswith('refs/heads/'): name = name[11:] date = git.rev_get_date(sha.encode('hex')) n1 = BranchList(self, name, sha) n1._set_time_nsec_from_git_date(date) self._subs[name] = n1 self._nlinks_for_dir += 1
def _mksubs(self): self._subs = {} self._nlinks_for_dir = 4 commit_dir = CommitDir(self, '.commit') self._subs['.commit'] = commit_dir commit_dir._try_set_inode(3) tag_dir = TagDir(self, '.tag') self._subs['.tag'] = tag_dir tag_dir._try_set_inode(4) for (name, sha) in git.list_refs(): if name.startswith('refs/heads/'): name = name[11:] date = git.rev_get_date(sha.encode('hex')) n1 = BranchList(self, name, sha) n1._set_time_nsec_from_git_date(date) self._subs[name] = n1 self._nlinks_for_dir += 1
def _mksubs(self): self._subs = {} refs = git.list_refs() for ref in refs: #debug2('ref name: %s\n' % ref[0]) revs = git.rev_list(ref[1].encode('hex')) for (date, commit) in revs: #debug2('commit: %s date: %s\n' % (commit.encode('hex'), date)) commithex = commit.encode('hex') containername = commithex[:2] dirname = commithex[2:] n1 = self._subs.get(containername) if not n1: n1 = CommitList(self, containername) self._subs[containername] = n1 if n1.commits.get(dirname): # Stop work for this ref, the rest should already be present break n1.commits[dirname] = (commit, date)
def _mksubs(self): self._subs = {} refs = git.list_refs(repo_dir=self._repo_dir) for ref in refs: #debug2('ref name: %s\n' % ref[0]) revs = git.rev_list(ref[1].encode('hex'), format='%at', parse=lambda f: int(f.readline().strip()), repo_dir=self._repo_dir) for commithex, date in revs: #debug2('commit: %s date: %s\n' % (commit.encode('hex'), date)) commit = commithex.decode('hex') containername = commithex[:2] dirname = commithex[2:] n1 = self._subs.get(containername) if not n1: n1 = CommitList(self, containername, self._repo_dir) self._subs[containername] = n1 if n1.commits.get(dirname): # Stop work for this ref, the rest should already be present break n1.commits[dirname] = (commit, date)
def test_list_refs(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-') os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" src = tmpdir + '/src' mkdirp(src) with open(src + '/1', 'w+') as f: print f, 'something' with open(src + '/2', 'w+') as f: print f, 'something else' git.init_repo(bupdir) emptyset = frozenset() WVPASSEQ(frozenset(git.list_refs()), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset) exc(bup_exe, 'index', src) exc(bup_exe, 'save', '-n', 'src', '--strip', src) src_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src').strip().split('\n') assert(len(src_hash) == 1) src_hash = src_hash[0].decode('hex') tree_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:').strip().split('\n')[0].decode('hex') blob_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0].decode('hex') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'commit-tag', 'src') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash), ('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), frozenset([('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'tree-tag', 'src:') exc('git', '--git-dir', bupdir, 'tag', 'blob-tag', 'src:1') os.unlink(bupdir + '/refs/heads/src') expected_tags = frozenset([('refs/tags/commit-tag', src_hash), ('refs/tags/tree-tag', tree_hash), ('refs/tags/blob-tag', blob_hash)]) WVPASSEQ(frozenset(git.list_refs()), expected_tags) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def branches(refnames=()): return ((name[11:], sha) for (name,sha) in git.list_refs(refnames=('refs/heads/' + n for n in refnames), limit_to_heads=True))
def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False): for ref in git.list_refs(patterns=patterns, limit_to_heads=limit_to_heads, limit_to_tags=limit_to_tags, repo_dir=self.repo_dir): yield ref
def test_list_refs(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-') os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" src = tmpdir + '/src' mkdirp(src) with open(src + '/1', 'w+') as f: print f, 'something' with open(src + '/2', 'w+') as f: print f, 'something else' git.init_repo(bupdir) emptyset = frozenset() WVPASSEQ(frozenset(git.list_refs()), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset) exc(bup_exe, 'index', src) exc(bup_exe, 'save', '-n', 'src', '--strip', src) src_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src').strip().split('\n') assert (len(src_hash) == 1) src_hash = src_hash[0].decode('hex') tree_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:').strip().split('\n')[0].decode('hex') blob_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0].decode('hex') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'commit-tag', 'src') WVPASSEQ( frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash), ('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), frozenset([('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'tree-tag', 'src:') exc('git', '--git-dir', bupdir, 'tag', 'blob-tag', 'src:1') os.unlink(bupdir + '/refs/heads/src') expected_tags = frozenset([('refs/tags/commit-tag', src_hash), ('refs/tags/tree-tag', tree_hash), ('refs/tags/blob-tag', blob_hash)]) WVPASSEQ(frozenset(git.list_refs()), expected_tags) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_list_refs(): with no_lingering_errors(): with test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" src = tmpdir + '/src' mkdirp(src) with open(src + '/1', 'w+') as f: print f, 'something' with open(src + '/2', 'w+') as f: print f, 'something else' git.init_repo(bupdir) emptyset = frozenset() WVPASSEQ(frozenset(git.list_refs()), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset) exc(bup_exe, 'index', src) exc(bup_exe, 'save', '-n', 'src', '--strip', src) src_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src').strip().split('\n') assert (len(src_hash) == 1) src_hash = src_hash[0].decode('hex') tree_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:').strip().split('\n')[0].decode('hex') blob_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0].decode('hex') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'commit-tag', 'src') WVPASSEQ( frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash), ('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), frozenset([('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'tree-tag', 'src:') exc('git', '--git-dir', bupdir, 'tag', 'blob-tag', 'src:1') os.unlink(bupdir + '/refs/heads/src') expected_tags = frozenset([('refs/tags/commit-tag', src_hash), ('refs/tags/tree-tag', tree_hash), ('refs/tags/blob-tag', blob_hash)]) WVPASSEQ(frozenset(git.list_refs()), expected_tags) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags)
def branches(refnames=tuple()): return ((name[11:], hexlify(sha)) for (name, sha) in git.list_refs( patterns=(b'refs/heads/' + n for n in refnames), limit_to_heads=True))
def branches(refnames=()): return ((name[11:], sha) for (name, sha) in git.list_refs( refnames=('refs/heads/' + n for n in refnames), limit_to_heads=True))
def test_list_refs(): with no_lingering_errors(): with test_tempdir(b'bup-tgit-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup' src = tmpdir + b'/src' mkdirp(src) with open(src + b'/1', 'wb+') as f: f.write(b'something\n') with open(src + b'/2', 'wb+') as f: f.write(b'something else\n') git.init_repo(bupdir) emptyset = frozenset() WVPASSEQ(frozenset(git.list_refs()), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset) exc(bup_exe, b'index', src) exc(bup_exe, b'save', b'-n', b'src', b'--strip', src) src_hash = exo(b'git', b'--git-dir', bupdir, b'rev-parse', b'src').strip().split(b'\n') assert(len(src_hash) == 1) src_hash = unhexlify(src_hash[0]) tree_hash = unhexlify(exo(b'git', b'--git-dir', bupdir, b'rev-parse', b'src:').strip().split(b'\n')[0]) blob_hash = unhexlify(exo(b'git', b'--git-dir', bupdir, b'rev-parse', b'src:1').strip().split(b'\n')[0]) WVPASSEQ(frozenset(git.list_refs()), frozenset([(b'refs/heads/src', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([(b'refs/heads/src', src_hash)])) exc(b'git', b'--git-dir', bupdir, b'tag', b'commit-tag', b'src') WVPASSEQ(frozenset(git.list_refs()), frozenset([(b'refs/heads/src', src_hash), (b'refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), frozenset([(b'refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([(b'refs/heads/src', src_hash)])) exc(b'git', b'--git-dir', bupdir, b'tag', b'tree-tag', b'src:') exc(b'git', b'--git-dir', bupdir, b'tag', b'blob-tag', b'src:1') os.unlink(bupdir + b'/refs/heads/src') expected_tags = frozenset([(b'refs/tags/commit-tag', src_hash), (b'refs/tags/tree-tag', tree_hash), (b'refs/tags/blob-tag', blob_hash)]) WVPASSEQ(frozenset(git.list_refs()), expected_tags) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags)
def test_list_refs(): with no_lingering_errors(), test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" src = tmpdir + '/src' mkdirp(src) with open(src + '/1', 'w+') as f: print f, 'something' with open(src + '/2', 'w+') as f: print f, 'something else' git.init_repo(bupdir) emptyset = frozenset() WVPASSEQ(frozenset(git.list_refs()), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset) exc(bup_exe, 'index', src) exc(bup_exe, 'save', '-n', 'src', '--strip', src) src_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src').strip().split('\n') assert(len(src_hash) == 1) src_hash = src_hash[0].decode('hex') tree_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:').strip().split('\n')[0].decode('hex') blob_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0].decode('hex') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'commit-tag', 'src') WVPASSEQ(frozenset(git.list_refs()), frozenset([('refs/heads/src', src_hash), ('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), frozenset([('refs/tags/commit-tag', src_hash)])) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([('refs/heads/src', src_hash)])) exc('git', '--git-dir', bupdir, 'tag', 'tree-tag', 'src:') exc('git', '--git-dir', bupdir, 'tag', 'blob-tag', 'src:1') os.unlink(bupdir + '/refs/heads/src') expected_tags = frozenset([('refs/tags/commit-tag', src_hash), ('refs/tags/tree-tag', tree_hash), ('refs/tags/blob-tag', blob_hash)]) WVPASSEQ(frozenset(git.list_refs()), expected_tags) WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([])) WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags)