Пример #1
0
	def add(self, sha, mode, name, force=False):
		"""Add the given item to the tree. If an item with the given name already
		exists, nothing will be done, but a ValueError will be raised if the 
		sha and mode of the existing item do not match the one you add, unless 
		force is True
		
		:param sha: The 20 or 40 byte sha of the item to add
		:param mode: int representing the stat compatible mode of the item
		:param force: If True, an item with your name and information will overwrite
			any existing item with the same name, no matter which information it has
		:return: self"""
		if '/' in name:
			raise ValueError("Name must not contain '/' characters")
		if (mode >> 12) not in Tree._map_id_to_type:
			raise ValueError("Invalid object type according to mode %o" % mode)
			
		sha = to_bin_sha(sha)
		index = self._index_by_name(name)
		item = (sha, mode, name)
		if index == -1:
			self._cache.append(item)
		else:
			if force:
				self._cache[index] = item
			else:
				ex_item = self._cache[index]
				if ex_item[0] != sha or ex_item[1] != mode:
					raise ValueError("Item %r existed with different properties" % name)
				# END handle mismatch
			# END handle force
		# END handle name exists
		return self
Пример #2
0
    def new(cls, repo, *tree_sha):
        """ Merge the given treeish revisions into a new index which is returned.
        This method behaves like git-read-tree --aggressive when doing the merge.

        :param repo: The repository treeish are located in.

        :param tree_sha:
            20 byte or 40 byte tree sha or tree objects

        :return:
            New IndexFile instance. Its path will be undefined.
            If you intend to write such a merged Index, supply an alternate file_path
            to its 'write' method."""
        base_entries = aggressive_tree_merge(repo.odb, [to_bin_sha(str(t)) for t in tree_sha])

        inst = cls(repo)
        # convert to entries dict
        entries = dict(izip(((e.path, e.stage) for e in base_entries), (IndexEntry.from_base(e) for e in base_entries)))

        inst.entries = entries
        return inst
Пример #3
0
def bin_sha_from_filename(filename):
    return to_bin_sha(os.path.splitext(os.path.basename(filename))[0][5:])
 def test_basics(self):
     assert to_hex_sha(NULL_HEX_SHA) == NULL_HEX_SHA
     assert len(to_bin_sha(NULL_HEX_SHA)) == 20
     assert to_hex_sha(to_bin_sha(NULL_HEX_SHA)) == NULL_HEX_SHA
Пример #5
0
 def test_basics(self):
     assert to_hex_sha(NULL_HEX_SHA) == NULL_HEX_SHA
     assert len(to_bin_sha(NULL_HEX_SHA)) == 20
     assert to_hex_sha(to_bin_sha(NULL_HEX_SHA)) == NULL_HEX_SHA.encode("ascii")
Пример #6
0
def bin_sha_from_filename(filename):
	return to_bin_sha(os.path.splitext(os.path.basename(filename))[0][5:])