def _import_one(self, name, data, message, author=None): """Import a single object. :param name: name of the object :param data: serialized object as list of bytes :param message: Commit message :param author: Optional author :return: etag """ try: with locked_index(self.repo.index_path()) as index: p = os.path.join(self.repo.path, name) with open(p, 'wb') as f: f.writelines(data) st = os.lstat(p) blob = Blob.from_string(b''.join(data)) encoded_name = name.encode(DEFAULT_ENCODING) if (encoded_name not in index or blob.id != index[encoded_name].sha): self.repo.object_store.add_object(blob) index[encoded_name] = IndexEntry( *index_entry_from_stat(st, blob.id, 0)) self._commit_tree(index, message.encode(DEFAULT_ENCODING), author=author) return blob.id except OSError as e: if e.errno == errno.ENOSPC: raise OutOfSpaceError() raise
def test_override_mode(self): st = os.stat_result(( stat.S_IFREG + 0o644, 131078, 64769, 154, 1000, 1000, 12288, 1323629595, 1324180496, 1324180496, )) entry = index_entry_from_stat(st, "22" * 20, 0, mode=stat.S_IFREG + 0o755) self.assertEqual( entry, IndexEntry( 1324180496, 1324180496, 64769, 131078, 33261, 1000, 1000, 12288, "2222222222222222222222222222222222222222", 0, None, ), )
def test_simple(self): st = os.stat_result(( 16877, 131078, 64769, 154, 1000, 1000, 12288, 1323629595, 1324180496, 1324180496, )) entry = index_entry_from_stat(st, "22" * 20, 0) self.assertEqual( entry, IndexEntry( 1324180496, 1324180496, 64769, 131078, 16384, 1000, 1000, 12288, "2222222222222222222222222222222222222222", 0, None, ), )
def test_submodule(self): self.build_tree(['a/']) a = Blob.from_string(b'irrelevant\n') with self.wt.lock_tree_write(): (index, index_path) = self.wt._lookup_index(b'a') index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0) self.wt._index_dirty = True t = Tree() t.add(b"a", S_IFGITLINK, a.id) self.store.add_object(t) self.expectDelta([], tree_id=t.id)
def test_submodule_not_checked_out(self): a = Blob.from_string(b'irrelevant\n') with self.wt.lock_tree_write(): (index, index_path) = self.wt._lookup_index(b'a') index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0) self.wt._index_dirty = True os.mkdir(self.wt.abspath('a')) t = Tree() t.add(b"a", S_IFGITLINK, a.id) self.store.add_object(t) self.expectDelta([], tree_id=t.id)
def test_submodule(self): self.subtree = self.make_branch_and_tree('a', format="git") a = Blob.from_string(b'irrelevant\n') self.build_tree_contents([('a/.git/HEAD', a.id)]) with self.wt.lock_tree_write(): (index, index_path) = self.wt._lookup_index(b'a') index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0) self.wt._index_dirty = True t = Tree() t.add(b"a", S_IFGITLINK, a.id) self.store.add_object(t) self.expectDelta([], tree_id=t.id)
def test_simple_write(self): entries = [(b"barbla", IndexEntry((1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, b"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 0, 0))] filename = os.path.join(self.tempdir, "test-simple-write-index") with open(filename, "wb+") as x: write_index(x, entries) with open(filename, "rb") as x: self.assertEqual(entries, list(read_index(x)))
def _import_one(self, name, data, message, author=None): """Import a single object. :param name: name of the object :param data: serialized object as list of bytes :param message: Commit message :param author: Optional author :return: etag """ with locked_index(self.repo.index_path()) as index: p = os.path.join(self.repo.path, name) with open(p, 'wb') as f: f.writelines(data) st = os.lstat(p) blob = Blob.from_string(b''.join(data)) self.repo.object_store.add_object(blob) index[name.encode(DEFAULT_ENCODING)] = IndexEntry( *index_entry_from_stat(st, blob.id, 0)) self._commit_tree(index, message.encode(DEFAULT_ENCODING), author=author) return blob.id
def save_data(self, title, data, author=None, comment=None, parent_rev=None, ts=None, new=False): data, user, text, created = super(WikiStorage, self).save_data( title, data, author=author, comment=comment, parent_rev=parent_rev, ts=ts, new=new) ctime = mtime = int(created.timestamp()) if data is not None: obj = Blob.from_string(data) self.repo.object_store.add_object(obj) index = self.tip index[self._title_to_file(title).encode('utf8')] = IndexEntry( ctime, mtime, 0, 0, 0o100644, 1, 1, len(data), obj.id, 0, 0) self._do_commit(index, user, text, ctime, parent_rev=parent_rev)