def test_check_repo_or_die(): initial_failures = wvfailure_count() orig_cwd = os.getcwd() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-') os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" try: os.chdir(tmpdir) git.init_repo(bupdir) git.check_repo_or_die() WVPASS('check_repo_or_die' ) # if we reach this point the call above passed os.rename(bupdir + '/objects/pack', bupdir + '/objects/pack.tmp') open(bupdir + '/objects/pack', 'w').close() try: git.check_repo_or_die() except SystemExit as e: WVPASSEQ(e.code, 14) else: WVFAIL() os.unlink(bupdir + '/objects/pack') os.rename(bupdir + '/objects/pack.tmp', bupdir + '/objects/pack') try: git.check_repo_or_die('nonexistantbup.tmp') except SystemExit as e: WVPASSEQ(e.code, 15) else: WVFAIL() finally: os.chdir(orig_cwd) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_long_index(): 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" git.init_repo(bupdir) w = git.PackWriter() obj_bin = struct.pack('!IIIII', 0x00112233, 0x44556677, 0x88990011, 0x22334455, 0x66778899) obj2_bin = struct.pack('!IIIII', 0x11223344, 0x55667788, 0x99001122, 0x33445566, 0x77889900) obj3_bin = struct.pack('!IIIII', 0x22334455, 0x66778899, 0x00112233, 0x44556677, 0x88990011) pack_bin = struct.pack('!IIIII', 0x99887766, 0x55443322, 0x11009988, 0x77665544, 0x33221100) idx = list(list() for i in xrange(256)) idx[0].append((obj_bin, 1, 0xfffffffff)) idx[0x11].append((obj2_bin, 2, 0xffffffffff)) idx[0x22].append((obj3_bin, 3, 0xff)) (fd, name) = tempfile.mkstemp(suffix='.idx', dir=git.repo('objects')) os.close(fd) w.count = 3 r = w._write_pack_idx_v2(name, idx, pack_bin) i = git.PackIdxV2(name, open(name, 'rb')) WVPASSEQ(i.find_offset(obj_bin), 0xfffffffff) WVPASSEQ(i.find_offset(obj2_bin), 0xffffffffff) WVPASSEQ(i.find_offset(obj3_bin), 0xff) if wvfailure_count() == initial_failures: os.remove(name) subprocess.call(['rm', '-rf', tmpdir])
def test_pack_name_lookup(): 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" git.init_repo(bupdir) git.verbose = 1 packdir = git.repo('objects/pack') idxnames = [] hashes = [] for start in range(0,28,2): w = git.PackWriter() for i in range(start, start+2): hashes.append(w.new_blob(str(i))) log('\n') idxnames.append(os.path.basename(w.close() + '.idx')) r = git.PackIdxList(packdir) WVPASSEQ(len(r.packs), 2) for e,idxname in enumerate(idxnames): for i in range(e*2, (e+1)*2): WVPASSEQ(r.exists(hashes[i], want_source=True), idxname) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_new_commit(): with no_lingering_errors(), test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() tree = os.urandom(20) parent = os.urandom(20) author_name = 'Author' author_mail = 'author@somewhere' adate_sec = 1439657836 cdate_sec = adate_sec + 1 committer_name = 'Committer' committer_mail = 'committer@somewhere' adate_tz_sec = cdate_tz_sec = None commit = w.new_commit(tree, parent, '%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, '%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, 'There is a small mailbox here') adate_tz_sec = -60 * 60 cdate_tz_sec = 120 * 60 commit_off = w.new_commit(tree, parent, '%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, '%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, 'There is a small mailbox here') w.close() commit_items = git.get_commit_items(commit.encode('hex'), git.cp()) local_author_offset = localtime(adate_sec).tm_gmtoff local_committer_offset = localtime(cdate_sec).tm_gmtoff WVPASSEQ(tree, commit_items.tree.decode('hex')) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, commit_items.parents[0].decode('hex')) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(local_author_offset, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(local_committer_offset, commit_items.committer_offset) commit_items = git.get_commit_items(commit_off.encode('hex'), git.cp()) WVPASSEQ(tree, commit_items.tree.decode('hex')) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, commit_items.parents[0].decode('hex')) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(adate_tz_sec, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(cdate_tz_sec, commit_items.committer_offset)
def test_multiple_suggestions(): with no_lingering_errors(): with test_tempdir(b'bup-tclient-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.close() lw = git.PackWriter() lw.new_blob(s2) lw.close() WVPASSEQ(len(glob.glob(git.repo(b'objects/pack' + IDX_PAT))), 2) c = client.Client(bupdir, create=True) WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 0) rw = c.new_packwriter() s1sha = rw.new_blob(s1) WVPASS(rw.exists(s1sha)) s2sha = rw.new_blob(s2) # This is a little hacky, but ensures that we test the # code under test while (len(glob.glob(c.cachedir + IDX_PAT)) < 2 and not c.conn.has_input()): pass rw.new_blob(s2) WVPASS(rw.objcache.exists(s1sha)) WVPASS(rw.objcache.exists(s2sha)) rw.new_blob(s3) WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 3)
def test_long_index(): 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" git.init_repo(bupdir) w = git.PackWriter() obj_bin = struct.pack('!IIIII', 0x00112233, 0x44556677, 0x88990011, 0x22334455, 0x66778899) obj2_bin = struct.pack('!IIIII', 0x11223344, 0x55667788, 0x99001122, 0x33445566, 0x77889900) obj3_bin = struct.pack('!IIIII', 0x22334455, 0x66778899, 0x00112233, 0x44556677, 0x88990011) pack_bin = struct.pack('!IIIII', 0x99887766, 0x55443322, 0x11009988, 0x77665544, 0x33221100) idx = list(list() for i in xrange(256)) idx[0].append((obj_bin, 1, 0xfffffffff)) idx[0x11].append((obj2_bin, 2, 0xffffffffff)) idx[0x22].append((obj3_bin, 3, 0xff)) w.count = 3 name = tmpdir + '/tmp.idx' r = w._write_pack_idx_v2(name, idx, pack_bin) i = git.PackIdxV2(name, open(name, 'rb')) WVPASSEQ(i.find_offset(obj_bin), 0xfffffffff) WVPASSEQ(i.find_offset(obj2_bin), 0xffffffffff) WVPASSEQ(i.find_offset(obj3_bin), 0xff)
def test_midx_refreshing(tmpdir): environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) c = client.Client(bupdir, create=True) rw = c.new_packwriter() rw.new_blob(s1) p1base = rw.breakpoint() p1name = os.path.join(c.cachedir, p1base) s1sha = rw.new_blob(s1) # should not be written; it's already in p1 s2sha = rw.new_blob(s2) p2base = rw.close() p2name = os.path.join(c.cachedir, p2base) del rw pi = git.PackIdxList(bupdir + b'/objects/pack') assert len(pi.packs) == 2 pi.refresh() assert len(pi.packs) == 2 assert sorted([os.path.basename(i.name) for i in pi.packs]) == sorted([p1base, p2base]) p1 = git.open_idx(p1name) assert p1.exists(s1sha) p2 = git.open_idx(p2name) assert not p2.exists(s1sha) assert p2.exists(s2sha) subprocess.call([path.exe(), b'midx', b'-f']) pi.refresh() assert len(pi.packs) == 1 pi.refresh(skip_midx=True) assert len(pi.packs) == 2 pi.refresh(skip_midx=False) assert len(pi.packs) == 1
def test_check_repo_or_die(): initial_failures = wvfailure_count() orig_cwd = os.getcwd() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-') os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" try: os.chdir(tmpdir) git.init_repo(bupdir) git.check_repo_or_die() WVPASS('check_repo_or_die') # if we reach this point the call above passed os.rename(bupdir + '/objects/pack', bupdir + '/objects/pack.tmp') open(bupdir + '/objects/pack', 'w').close() try: git.check_repo_or_die() except SystemExit as e: WVPASSEQ(e.code, 14) else: WVFAIL() os.unlink(bupdir + '/objects/pack') os.rename(bupdir + '/objects/pack.tmp', bupdir + '/objects/pack') try: git.check_repo_or_die('nonexistantbup.tmp') except SystemExit as e: WVPASSEQ(e.code, 15) else: WVFAIL() finally: os.chdir(orig_cwd) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_check_repo_or_die(): with no_lingering_errors(), test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" orig_cwd = os.getcwd() try: os.chdir(tmpdir) git.init_repo(bupdir) git.check_repo_or_die() WVPASS('check_repo_or_die') # if we reach this point the call above passed os.rename(bupdir + '/objects/pack', bupdir + '/objects/pack.tmp') open(bupdir + '/objects/pack', 'w').close() try: git.check_repo_or_die() except SystemExit as e: WVPASSEQ(e.code, 14) else: WVFAIL() os.unlink(bupdir + '/objects/pack') os.rename(bupdir + '/objects/pack.tmp', bupdir + '/objects/pack') try: git.check_repo_or_die('nonexistantbup.tmp') except SystemExit as e: WVPASSEQ(e.code, 15) else: WVFAIL() finally: os.chdir(orig_cwd)
def create(self, repo_dir=None): # FIXME: this is not ideal, we should somehow # be able to call the constructor instead? git.init_repo(repo_dir) git.check_repo_or_die(repo_dir) # ensure it gets a repo-id LocalRepo(repo_dir)
def test_long_index(): 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" git.init_repo(bupdir) w = git.PackWriter() obj_bin = struct.pack('!IIIII', 0x00112233, 0x44556677, 0x88990011, 0x22334455, 0x66778899) obj2_bin = struct.pack('!IIIII', 0x11223344, 0x55667788, 0x99001122, 0x33445566, 0x77889900) obj3_bin = struct.pack('!IIIII', 0x22334455, 0x66778899, 0x00112233, 0x44556677, 0x88990011) pack_bin = struct.pack('!IIIII', 0x99887766, 0x55443322, 0x11009988, 0x77665544, 0x33221100) idx = list(list() for i in xrange(256)) idx[0].append((obj_bin, 1, 0xfffffffff)) idx[0x11].append((obj2_bin, 2, 0xffffffffff)) idx[0x22].append((obj3_bin, 3, 0xff)) (fd,name) = tempfile.mkstemp(suffix='.idx', dir=git.repo('objects')) os.close(fd) w.count = 3 r = w._write_pack_idx_v2(name, idx, pack_bin) i = git.PackIdxV2(name, open(name, 'rb')) WVPASSEQ(i.find_offset(obj_bin), 0xfffffffff) WVPASSEQ(i.find_offset(obj2_bin), 0xffffffffff) WVPASSEQ(i.find_offset(obj3_bin), 0xff) if wvfailure_count() == initial_failures: os.remove(name) subprocess.call(['rm', '-rf', tmpdir])
def test_multiple_suggestions(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.close() lw = git.PackWriter() lw.new_blob(s2) lw.close() WVPASSEQ(len(glob.glob(git.repo('objects/pack'+IDX_PAT))), 2) c = client.Client(bupdir, create=True) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 0) rw = c.new_packwriter() s1sha = rw.new_blob(s1) WVPASS(rw.exists(s1sha)) s2sha = rw.new_blob(s2) # This is a little hacky, but ensures that we test the code under test while (len(glob.glob(c.cachedir+IDX_PAT)) < 2 and not c.conn.has_input()): pass rw.new_blob(s2) WVPASS(rw.objcache.exists(s1sha)) WVPASS(rw.objcache.exists(s2sha)) rw.new_blob(s3) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 3) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_multiple_suggestions(): with no_lingering_errors(): with test_tempdir('bup-tclient-') as tmpdir: os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.close() lw = git.PackWriter() lw.new_blob(s2) lw.close() WVPASSEQ(len(glob.glob(git.repo('objects/pack'+IDX_PAT))), 2) c = client.Client(bupdir, create=True) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 0) rw = c.new_packwriter() s1sha = rw.new_blob(s1) WVPASS(rw.exists(s1sha)) s2sha = rw.new_blob(s2) # This is a little hacky, but ensures that we test the # code under test while (len(glob.glob(c.cachedir+IDX_PAT)) < 2 and not c.conn.has_input()): pass rw.new_blob(s2) WVPASS(rw.objcache.exists(s1sha)) WVPASS(rw.objcache.exists(s2sha)) rw.new_blob(s3) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 3)
def test_new_commit(): with no_lingering_errors(): with test_tempdir(b'bup-tgit-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup' git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() tree = os.urandom(20) parent = os.urandom(20) author_name = b'Author' author_mail = b'author@somewhere' adate_sec = 1439657836 cdate_sec = adate_sec + 1 committer_name = b'Committer' committer_mail = b'committer@somewhere' adate_tz_sec = cdate_tz_sec = None commit = w.new_commit(tree, parent, b'%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, b'%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, b'There is a small mailbox here') adate_tz_sec = -60 * 60 cdate_tz_sec = 120 * 60 commit_off = w.new_commit(tree, parent, b'%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, b'%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, b'There is a small mailbox here') w.close() commit_items = git.get_commit_items(hexlify(commit), git.cp()) local_author_offset = localtime(adate_sec).tm_gmtoff local_committer_offset = localtime(cdate_sec).tm_gmtoff WVPASSEQ(tree, unhexlify(commit_items.tree)) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, unhexlify(commit_items.parents[0])) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(local_author_offset, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(local_committer_offset, commit_items.committer_offset) commit_items = git.get_commit_items(hexlify(commit_off), git.cp()) WVPASSEQ(tree, unhexlify(commit_items.tree)) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, unhexlify(commit_items.parents[0])) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(adate_tz_sec, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(cdate_tz_sec, commit_items.committer_offset)
def test_check_repo_or_die(): with no_lingering_errors(): with test_tempdir(b'bup-tgit-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup' orig_cwd = os.getcwd() try: os.chdir(tmpdir) git.init_repo(bupdir) git.check_repo_or_die() # if we reach this point the call above passed WVPASS('check_repo_or_die') os.rename(bupdir + b'/objects/pack', bupdir + b'/objects/pack.tmp') open(bupdir + b'/objects/pack', 'w').close() try: git.check_repo_or_die() except SystemExit as e: WVPASSEQ(e.code, 14) else: WVFAIL() os.unlink(bupdir + b'/objects/pack') os.rename(bupdir + b'/objects/pack.tmp', bupdir + b'/objects/pack') try: git.check_repo_or_die(b'nonexistantbup.tmp') except SystemExit as e: WVPASSEQ(e.code, 15) else: WVFAIL() finally: os.chdir(orig_cwd)
def test_multiple_suggestions(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.close() lw = git.PackWriter() lw.new_blob(s2) lw.close() WVPASSEQ(len(glob.glob(git.repo('objects/pack' + IDX_PAT))), 2) c = client.Client(bupdir, create=True) WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 0) rw = c.new_packwriter() s1sha = rw.new_blob(s1) WVPASS(rw.exists(s1sha)) s2sha = rw.new_blob(s2) # This is a little hacky, but ensures that we test the code under test while (len(glob.glob(c.cachedir + IDX_PAT)) < 2 and not c.conn.has_input()): pass rw.new_blob(s2) WVPASS(rw.objcache.exists(s1sha)) WVPASS(rw.objcache.exists(s2sha)) rw.new_blob(s3) WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 3) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_long_index(): with no_lingering_errors(), test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" git.init_repo(bupdir) w = git.PackWriter() obj_bin = struct.pack('!IIIII', 0x00112233, 0x44556677, 0x88990011, 0x22334455, 0x66778899) obj2_bin = struct.pack('!IIIII', 0x11223344, 0x55667788, 0x99001122, 0x33445566, 0x77889900) obj3_bin = struct.pack('!IIIII', 0x22334455, 0x66778899, 0x00112233, 0x44556677, 0x88990011) pack_bin = struct.pack('!IIIII', 0x99887766, 0x55443322, 0x11009988, 0x77665544, 0x33221100) idx = list(list() for i in xrange(256)) idx[0].append((obj_bin, 1, 0xfffffffff)) idx[0x11].append((obj2_bin, 2, 0xffffffffff)) idx[0x22].append((obj3_bin, 3, 0xff)) w.count = 3 name = tmpdir + '/tmp.idx' r = w._write_pack_idx_v2(name, idx, pack_bin) i = git.PackIdxV2(name, open(name, 'rb')) WVPASSEQ(i.find_offset(obj_bin), 0xfffffffff) WVPASSEQ(i.find_offset(obj2_bin), 0xffffffffff) WVPASSEQ(i.find_offset(obj3_bin), 0xff)
def test_pack_name_lookup(): 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" git.init_repo(bupdir) git.verbose = 1 packdir = git.repo('objects/pack') idxnames = [] hashes = [] for start in range(0, 28, 2): w = git.PackWriter() for i in range(start, start + 2): hashes.append(w.new_blob(str(i))) log('\n') idxnames.append(os.path.basename(w.close() + '.idx')) r = git.PackIdxList(packdir) WVPASSEQ(len(r.packs), 2) for e, idxname in enumerate(idxnames): for i in range(e * 2, (e + 1) * 2): WVPASSEQ(r.exists(hashes[i], want_source=True), idxname) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_multiple_suggestions(tmpdir): environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.close() lw = git.PackWriter() lw.new_blob(s2) lw.close() assert len(glob.glob(git.repo(b'objects/pack' + IDX_PAT, repo_dir=bupdir))) == 2 c = client.Client(bupdir, create=True) assert len(glob.glob(c.cachedir + IDX_PAT)) == 0 rw = c.new_packwriter() s1sha = rw.new_blob(s1) assert rw.exists(s1sha) s2sha = rw.new_blob(s2) # This is a little hacky, but ensures that we test the # code under test. First, flush to ensure that we've # actually sent all the command ('receive-objects-v2') # and their data to the server. This may be needed if # the output buffer size is bigger than the data (both # command and objects) we're writing. To see the need # for this, change the object sizes at the beginning # of this file to be very small (e.g. 10 instead of 10k) c.conn.outp.flush() # Then, check if we've already received the idx files. # This may happen if we're preempted just after writing # the data, then the server runs and suggests, and only # then we continue in PackWriter_Remote::_raw_write() # and check the has_input(), in that case we'll receive # the idx still in the rw.new_blob() calls above. # # In most cases though, that doesn't happen, and we'll # get past the has_input() check before the server has # a chance to respond - it has to actually hash the new # object here, so it takes some time. So also break out # of the loop if the server has sent something on the # connection. # # Finally, abort this after a little while (about one # second) just in case something's actually broken. n = 0 while (len(glob.glob(c.cachedir + IDX_PAT)) < 2 and not c.conn.has_input() and n < 10): time.sleep(0.1) n += 1 assert len(glob.glob(c.cachedir + IDX_PAT)) == 2 or c.conn.has_input() rw.new_blob(s2) assert rw.objcache.exists(s1sha) assert rw.objcache.exists(s2sha) rw.new_blob(s3) assert len(glob.glob(c.cachedir + IDX_PAT)) == 2 rw.close() assert len(glob.glob(c.cachedir + IDX_PAT)) == 3
def test_midx_close(): fddir = b'/proc/self/fd' try: os.listdir(fddir) except Exception: # not supported, not Linux, I guess return def openfiles(): for fd in os.listdir(fddir): try: yield os.readlink(os.path.join(fddir, fd)) except OSError: pass def force_midx(objdir): args = [path.exe(), b'midx', b'--auto', b'--dir', objdir] check_call(args) with no_lingering_errors(), \ test_tempdir(b'bup-tgit-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup' git.init_repo(bupdir) # create a few dummy idxes for i in range(10): _create_idx(tmpdir, i) git.auto_midx(tmpdir) l = git.PackIdxList(tmpdir) # this doesn't exist (yet) WVPASSEQ(None, l.exists(struct.pack('18xBB', 10, 0))) for i in range(10, 15): _create_idx(tmpdir, i) # delete the midx ... # TODO: why do we need to? git.auto_midx() below doesn't?! for fn in os.listdir(tmpdir): if fn.endswith(b'.midx'): os.unlink(os.path.join(tmpdir, fn)) # and make a new one git.auto_midx(tmpdir) # check it still doesn't exist - we haven't refreshed WVPASSEQ(None, l.exists(struct.pack('18xBB', 10, 0))) # check that we still have the midx open, this really # just checks more for the kernel API ('deleted' string) for fn in openfiles(): if not b'midx-' in fn: continue WVPASSEQ(True, b'deleted' in fn) # refresh the PackIdxList l.refresh() # and check that an object in pack 10 exists now WVPASSEQ(True, l.exists(struct.pack('18xBB', 10, 0))) for fn in openfiles(): if not b'midx-' in fn: continue # check that we don't have it open anymore WVPASSEQ(False, b'deleted' in fn)
def test_server_split_with_indexes(tmpdir): environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) with git.PackWriter() as lw: lw.new_blob(s1) with client.Client(bupdir, create=True) as c, \ c.new_packwriter() as rw: rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1)
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(): 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 test_server_split_with_indexes(tmpdir): environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() c = client.Client(bupdir, create=True) rw = c.new_packwriter() lw.new_blob(s1) lw.close() rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1) rw.close()
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_dumb_client_server(tmpdir): environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) open(git.repo(b'bup-dumb-server'), 'w').close() with git.PackWriter() as lw: lw.new_blob(s1) with client.Client(bupdir, create=True) as c, \ c.new_packwriter() as rw: assert len(glob.glob(c.cachedir + IDX_PAT)) == 1 rw.new_blob(s1) assert len(glob.glob(c.cachedir + IDX_PAT)) == 1 rw.new_blob(s2) assert len(glob.glob(c.cachedir + IDX_PAT)) == 2
def test_server_split_with_indexes(): os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = 'buptest_tclient.tmp' subprocess.call(['rm', '-rf', bupdir]) git.init_repo(bupdir) lw = git.PackWriter() c = client.Client(bupdir, create=True) rw = c.new_packwriter() lw.new_blob(s1) lw.close() rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1)
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 test_server_split_with_indexes(): with no_lingering_errors(): with test_tempdir(b'bup-tclient-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() c = client.Client(bupdir, create=True) rw = c.new_packwriter() lw.new_blob(s1) lw.close() rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1) rw.close()
def test_server_split_with_indexes(): with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir: os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() c = client.Client(bupdir, create=True) rw = c.new_packwriter() lw.new_blob(s1) lw.close() rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1) rw.close()
def main(argv): o = options.Options(optspec) opt, flags, extra = o.parse_bytes(argv[1:]) if extra: o.fatal("no arguments expected") try: git.init_repo() # local repo except git.GitError as e: log("bup: error: could not init repository: %s" % e) sys.exit(1) if opt.remote: git.check_repo_or_die() cli = client.Client(argv_bytes(opt.remote), create=True) cli.close()
def test_cat_pipe(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) exc(bup_exe, b'index', src) oidx = exo(bup_exe, b'save', b'-cn', b'src', b'--strip', src).strip() typ = exo(b'git', b'--git-dir', bupdir, b'cat-file', b'-t', b'src').strip() size = int(exo(b'git', b'--git-dir', bupdir, b'cat-file', b'-s', b'src')) it = git.cp().get(b'src') get_info = next(it) for buf in next(it): pass WVPASSEQ((oidx, typ, size), get_info)
def test_server_split_with_indexes(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) lw = git.PackWriter() c = client.Client(bupdir, create=True) rw = c.new_packwriter() lw.new_blob(s1) lw.close() rw.new_blob(s2) rw.breakpoint() rw.new_blob(s1) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_check_repo_or_die(): initial_failures = wvfailure_count() orig_cwd = os.getcwd() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-') os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" try: os.chdir(tmpdir) git.init_repo(bupdir) git.check_repo_or_die() WVPASS('check_repo_or_die') # if we reach this point the call above passed os.rename(bupdir + '/objects/pack', bupdir + '/objects/pack.tmp') open(bupdir + '/objects/pack', 'w').close() try: git.check_repo_or_die() except SystemExit, e: WVPASSEQ(e.code, 14) else:
def testpacks(): 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" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.open_idx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0'*20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0'*20)) r = git.PackIdxList(bupdir + '/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0'*20)) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def testpacks(): 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" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.open_idx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0' * 20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0' * 20)) r = git.PackIdxList(bupdir + '/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0' * 20)) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_dumb_client_server(): with no_lingering_errors(): with test_tempdir(b'bup-tclient-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) open(git.repo(b'bup-dumb-server'), 'w').close() lw = git.PackWriter() lw.new_blob(s1) lw.close() c = client.Client(bupdir, create=True) rw = c.new_packwriter() WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 1) rw.new_blob(s1) WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 1) rw.new_blob(s2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir + IDX_PAT)), 2)
def test_dumb_client_server(): with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir: os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) open(git.repo('bup-dumb-server'), 'w').close() lw = git.PackWriter() lw.new_blob(s1) lw.close() c = client.Client(bupdir, create=True) rw = c.new_packwriter() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s1) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
def test_dumb_client_server(): os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = 'buptest_tclient.tmp' subprocess.call(['rm', '-rf', bupdir]) git.init_repo(bupdir) open(git.repo('bup-dumb-server'), 'w').close() lw = git.PackWriter() lw.new_blob(s1) lw.close() c = client.Client(bupdir, create=True) rw = c.new_packwriter() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s1) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
def testpacks(): 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" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.open_idx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0'*20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0'*20)) r = git.PackIdxList(bupdir + '/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0'*20))
def testpacks(): 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" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.open_idx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0' * 20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0' * 20)) r = git.PackIdxList(bupdir + '/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0' * 20))
def testpacks(): os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup' os.environ['BUP_DIR'] = bupdir = 'pybuptest.tmp' subprocess.call(['rm','-rf', bupdir]) git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.open_idx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0'*20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0'*20)) r = git.PackIdxList('pybuptest.tmp/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0'*20))
def testpacks(): with no_lingering_errors(): with test_tempdir(b'bup-tgit-') as tmpdir: environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup' git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() w.new_blob(os.urandom(100)) w.new_blob(os.urandom(100)) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.new_blob(b'%d' % i)) log('\n') nameprefix = w.close() print(repr(nameprefix)) WVPASS(os.path.exists(nameprefix + b'.pack')) WVPASS(os.path.exists(nameprefix + b'.idx')) r = git.open_idx(nameprefix + b'.idx') print(repr(r.fanout)) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists(b'\0'*20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(hexlify(next(pi)), hexlify(h)) WVFAIL(r.find_offset(b'\0'*20)) r = git.PackIdxList(bupdir + b'/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists(b'\0'*20))
def test_midx_refreshing(): os.environ['BUP_MAIN_EXE'] = bupmain = './bup' os.environ['BUP_DIR'] = bupdir = 'buptest_tmidx.tmp' subprocess.call(['rm', '-rf', bupdir]) git.init_repo(bupdir) lw = git.PackWriter() lw.new_blob(s1) lw.breakpoint() lw.new_blob(s2) del lw pi = git.PackIdxList(bupdir + '/objects/pack') WVPASSEQ(len(pi.packs), 2) pi.refresh() WVPASSEQ(len(pi.packs), 2) subprocess.call([bupmain, 'midx', '-f']) pi.refresh() WVPASSEQ(len(pi.packs), 1) pi.refresh(skip_midx=True) WVPASSEQ(len(pi.packs), 2) pi.refresh(skip_midx=False) WVPASSEQ(len(pi.packs), 1)
def test_dumb_client_server(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) open(git.repo('bup-dumb-server'), 'w').close() lw = git.PackWriter() lw.new_blob(s1) lw.close() c = client.Client(bupdir, create=True) rw = c.new_packwriter() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s1) WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1) rw.new_blob(s2) rw.close() WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_midx_refreshing(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) c = client.Client(bupdir, create=True) rw = c.new_packwriter() rw.new_blob(s1) p1base = rw.breakpoint() p1name = os.path.join(c.cachedir, p1base) s1sha = rw.new_blob(s1) # should not be written; it's already in p1 s2sha = rw.new_blob(s2) p2base = rw.close() p2name = os.path.join(c.cachedir, p2base) del rw pi = git.PackIdxList(bupdir + '/objects/pack') WVPASSEQ(len(pi.packs), 2) pi.refresh() WVPASSEQ(len(pi.packs), 2) WVPASSEQ(sorted([os.path.basename(i.name) for i in pi.packs]), sorted([p1base, p2base])) p1 = git.open_idx(p1name) WVPASS(p1.exists(s1sha)) p2 = git.open_idx(p2name) WVFAIL(p2.exists(s1sha)) WVPASS(p2.exists(s2sha)) subprocess.call([bupmain, 'midx', '-f']) pi.refresh() WVPASSEQ(len(pi.packs), 1) pi.refresh(skip_midx=True) WVPASSEQ(len(pi.packs), 2) pi.refresh(skip_midx=False) WVPASSEQ(len(pi.packs), 1) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def testpacks(): git.init_repo('pybuptest.tmp') git.verbose = 1 now = str(time.time()) # hopefully not in any packs yet w = git.PackWriter() w.write('blob', now) w.write('blob', now) w.abort() w = git.PackWriter() hashes = [] nobj = 1000 for i in range(nobj): hashes.append(w.write('blob', str(i))) log('\n') nameprefix = w.close() print repr(nameprefix) WVPASS(os.path.exists(nameprefix + '.pack')) WVPASS(os.path.exists(nameprefix + '.idx')) r = git.PackIdx(nameprefix + '.idx') print repr(r.fanout) for i in range(nobj): WVPASS(r.find_offset(hashes[i]) > 0) WVPASS(r.exists(hashes[99])) WVFAIL(r.exists('\0'*20)) pi = iter(r) for h in sorted(hashes): WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex')) WVFAIL(r.find_offset('\0'*20)) r = git.PackIdxList('pybuptest.tmp/objects/pack') WVPASS(r.exists(hashes[5])) WVPASS(r.exists(hashes[6])) WVFAIL(r.exists('\0'*20))
def test_pack_name_lookup(): with no_lingering_errors(), test_tempdir('bup-tgit-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bup_exe os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup" git.init_repo(bupdir) git.verbose = 1 packdir = git.repo('objects/pack') idxnames = [] hashes = [] for start in range(0,28,2): w = git.PackWriter() for i in range(start, start+2): hashes.append(w.new_blob(str(i))) log('\n') idxnames.append(os.path.basename(w.close() + '.idx')) r = git.PackIdxList(packdir) WVPASSEQ(len(r.packs), 2) for e,idxname in enumerate(idxnames): for i in range(e*2, (e+1)*2): WVPASSEQ(r.exists(hashes[i], want_source=True), idxname)
def test_pack_name_lookup(): os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup' os.environ['BUP_DIR'] = bupdir = 'pybuptest.tmp' subprocess.call(['rm','-rf', bupdir]) git.init_repo(bupdir) git.verbose = 1 packdir = git.repo('objects/pack') idxnames = [] hashes = [] for start in range(0,28,2): w = git.PackWriter() for i in range(start, start+2): hashes.append(w.new_blob(str(i))) log('\n') idxnames.append(os.path.basename(w.close() + '.idx')) r = git.PackIdxList(packdir) WVPASSEQ(len(r.packs), 2) for e,idxname in enumerate(idxnames): for i in range(e*2, (e+1)*2): WVPASSEQ(r.exists(hashes[i], want_source=True), idxname)
def test_midx_refreshing(): with no_lingering_errors(): with test_tempdir('bup-tclient-') as tmpdir: os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir git.init_repo(bupdir) c = client.Client(bupdir, create=True) rw = c.new_packwriter() rw.new_blob(s1) p1base = rw.breakpoint() p1name = os.path.join(c.cachedir, p1base) s1sha = rw.new_blob(s1) # should not be written; it's already in p1 s2sha = rw.new_blob(s2) p2base = rw.close() p2name = os.path.join(c.cachedir, p2base) del rw pi = git.PackIdxList(bupdir + '/objects/pack') WVPASSEQ(len(pi.packs), 2) pi.refresh() WVPASSEQ(len(pi.packs), 2) WVPASSEQ(sorted([os.path.basename(i.name) for i in pi.packs]), sorted([p1base, p2base])) p1 = git.open_idx(p1name) WVPASS(p1.exists(s1sha)) p2 = git.open_idx(p2name) WVFAIL(p2.exists(s1sha)) WVPASS(p2.exists(s2sha)) subprocess.call([bupmain, 'midx', '-f']) pi.refresh() WVPASSEQ(len(pi.packs), 1) pi.refresh(skip_midx=True) WVPASSEQ(len(pi.packs), 2) pi.refresh(skip_midx=False) WVPASSEQ(len(pi.packs), 1)
def test_object_info(): 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) WVPASSEQ(list(git.object_info([])), []) ex(bup_exe, 'index', src) ex(bup_exe, 'save', '-n', 'src', '--strip', src) src_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src').strip().split('\n')[0] src_size = int(exo('git', '--git-dir', bupdir, 'cat-file', '-s', 'src').strip().split('\n')[0]) tree_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:').strip().split('\n')[0] tree_size = int(exo('git', '--git-dir', bupdir, 'cat-file', '-s', 'src:').strip().split('\n')[0]) blob_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0] blob_size = int(exo('git', '--git-dir', bupdir, 'cat-file', '-s', 'src:1').strip().split('\n')[0]) WVPASSEQ(tuple(git.object_info([src_hash, tree_hash, blob_hash])), ((src_hash.decode('hex'), 'commit', src_size), (tree_hash.decode('hex'), 'tree', tree_size), (blob_hash.decode('hex'), 'blob', blob_size))) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def init_dir(conn, arg): git.init_repo(arg) debug1('bup server: bupdir initialized: %r\n' % git.repodir) _set_mode() conn.ok()
def test_path_info(): initial_failures = wvfailure_count() tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tclient-') os.environ['BUP_MAIN_EXE'] = '../../../bup' os.environ['BUP_DIR'] = bupdir = tmpdir 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' os.mkdir(src + '/dir') git.init_repo(bupdir) c = client.Client(bupdir, create=True) info = c.path_info(['/']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) name, id, type = info[0] WVPASSEQ(type, 'root') info = c.path_info(['/not-there/']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0] is None) data = exo(bup_exe, 'random', '128k') with open(src + '/chunky', 'wb+') as f: f.write(data) ex(bup_exe, 'index', '-vv', src) ex(bup_exe, 'save', '-n', 'src', '--strip', src) ex(bup_exe, 'tag', 'src-latest-tag', '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:dir').strip().split('\n')[0].decode('hex') file_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:1').strip().split('\n')[0].decode('hex') chunky_hash = exo('git', '--git-dir', bupdir, 'rev-parse', 'src:chunky.bup').strip().split('\n')[0].decode('hex') info = c.path_info(['/src']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/src', src_hash, 'branch']) info = c.path_info(['/src/latest']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/src/latest', src_hash, 'save']) info = c.path_info(['/src/latest/dir']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/src/latest/dir', tree_hash, 'dir']) info = c.path_info(['/src/latest/1']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/src/latest/1', file_hash, 'file']) info = c.path_info(['/src/latest/chunky']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/src/latest/chunky', chunky_hash, 'chunked-file']) info = c.path_info(['/.tag/src-latest-tag']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/.tag/src-latest-tag', src_hash, 'commit']) info = c.path_info(['.tag////src-latest-tag']) WVPASS(info) WVPASS(len(info) == 1) WVPASS(info[0]) WVPASSEQ(info[0], ['/.tag/src-latest-tag', src_hash, 'commit']) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])
def test_new_commit(): 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" git.init_repo(bupdir) git.verbose = 1 w = git.PackWriter() tree = os.urandom(20) parent = os.urandom(20) author_name = 'Author' author_mail = 'author@somewhere' adate_sec = 1439657836 cdate_sec = adate_sec + 1 committer_name = 'Committer' committer_mail = 'committer@somewhere' adate_tz_sec = cdate_tz_sec = None commit = w.new_commit(tree, parent, '%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, '%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, 'There is a small mailbox here') adate_tz_sec = -60 * 60 cdate_tz_sec = 120 * 60 commit_off = w.new_commit(tree, parent, '%s <%s>' % (author_name, author_mail), adate_sec, adate_tz_sec, '%s <%s>' % (committer_name, committer_mail), cdate_sec, cdate_tz_sec, 'There is a small mailbox here') w.close() commit_items = git.get_commit_items(commit.encode('hex'), git.cp()) local_author_offset = localtime(adate_sec).tm_gmtoff local_committer_offset = localtime(cdate_sec).tm_gmtoff WVPASSEQ(tree, commit_items.tree.decode('hex')) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, commit_items.parents[0].decode('hex')) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(local_author_offset, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(local_committer_offset, commit_items.committer_offset) commit_items = git.get_commit_items(commit_off.encode('hex'), git.cp()) WVPASSEQ(tree, commit_items.tree.decode('hex')) WVPASSEQ(1, len(commit_items.parents)) WVPASSEQ(parent, commit_items.parents[0].decode('hex')) WVPASSEQ(author_name, commit_items.author_name) WVPASSEQ(author_mail, commit_items.author_mail) WVPASSEQ(adate_sec, commit_items.author_sec) WVPASSEQ(adate_tz_sec, commit_items.author_offset) WVPASSEQ(committer_name, commit_items.committer_name) WVPASSEQ(committer_mail, commit_items.committer_mail) WVPASSEQ(cdate_sec, commit_items.committer_sec) WVPASSEQ(cdate_tz_sec, commit_items.committer_offset) if wvfailure_count() == initial_failures: subprocess.call(['rm', '-rf', tmpdir])