|
@@ -41,8 +41,8 @@ from dulwich.pack import (
|
|
|
|
|
|
IndexEntry = collections.namedtuple(
|
|
|
'IndexEntry', [
|
|
|
- 'name', 'ctime', 'mtime', 'dev', 'ino',
|
|
|
- 'mode', 'uid', 'gid', 'size', 'sha', 'flags'])
|
|
|
+ 'ctime', 'mtime', 'dev', 'ino', 'mode', 'uid', 'gid', 'size', 'sha',
|
|
|
+ 'flags'])
|
|
|
|
|
|
|
|
|
def pathsplit(path):
|
|
@@ -106,8 +106,8 @@ def read_cache_entry(f):
|
|
|
# Padding:
|
|
|
real_size = ((f.tell() - beginoffset + 8) & ~7)
|
|
|
f.read((beginoffset + real_size) - f.tell())
|
|
|
- return IndexEntry(name, ctime, mtime, dev, ino, mode, uid, gid, size,
|
|
|
- sha_to_hex(sha), flags & ~0x0fff)
|
|
|
+ return (name, ctime, mtime, dev, ino, mode, uid, gid, size,
|
|
|
+ sha_to_hex(sha), flags & ~0x0fff)
|
|
|
|
|
|
|
|
|
def write_cache_entry(f, entry):
|
|
@@ -146,7 +146,7 @@ def read_index_dict(f):
|
|
|
"""
|
|
|
ret = {}
|
|
|
for x in read_index(f):
|
|
|
- ret[x[0]] = tuple(x[1:])
|
|
|
+ ret[x[0]] = IndexEntry(*x[1:])
|
|
|
return ret
|
|
|
|
|
|
|
|
@@ -222,7 +222,7 @@ class Index(object):
|
|
|
try:
|
|
|
f = SHA1Reader(f)
|
|
|
for x in read_index(f):
|
|
|
- self[x[0]] = tuple(x[1:])
|
|
|
+ self[x[0]] = IndexEntry(*x[1:])
|
|
|
# FIXME: Additional data?
|
|
|
f.read(os.path.getsize(self._filename)-f.tell()-20)
|
|
|
f.check_sha()
|
|
@@ -246,17 +246,17 @@ class Index(object):
|
|
|
|
|
|
def get_sha1(self, path):
|
|
|
"""Return the (git object) SHA1 for the object at a path."""
|
|
|
- return self[path][-2]
|
|
|
+ return self[path].sha
|
|
|
|
|
|
def get_mode(self, path):
|
|
|
"""Return the POSIX file mode for the object at a path."""
|
|
|
- return self[path][-6]
|
|
|
+ return self[path].mode
|
|
|
|
|
|
def iterblobs(self):
|
|
|
"""Iterate over path, sha, mode tuples for use with commit_tree."""
|
|
|
for path in self:
|
|
|
entry = self[path]
|
|
|
- yield path, entry[-2], cleanup_mode(entry[-6])
|
|
|
+ yield path, entry.sha, cleanup_mode(entry.mode)
|
|
|
|
|
|
def clear(self):
|
|
|
"""Remove all contents from this index."""
|
|
@@ -289,7 +289,7 @@ class Index(object):
|
|
|
"""
|
|
|
def lookup_entry(path):
|
|
|
entry = self[path]
|
|
|
- return entry[-2], entry[-6]
|
|
|
+ return entry.sha, entry.mode
|
|
|
for (name, mode, sha) in changes_from_tree(self._byname.keys(),
|
|
|
lookup_entry, object_store, tree,
|
|
|
want_unchanged=want_unchanged):
|
|
@@ -479,11 +479,11 @@ def get_unstaged_changes(index, path):
|
|
|
|
|
|
:param index: index to check
|
|
|
:param path: path in which to find files
|
|
|
- :yields: paths with unstaged changes
|
|
|
+ :return: iterator over paths with unstaged changes
|
|
|
"""
|
|
|
# For each entry in the index check the sha1 & ensure not staged
|
|
|
for name, entry in index.iteritems():
|
|
|
fp = os.path.join(path, name)
|
|
|
blob = blob_from_path_and_stat(fp, os.lstat(fp))
|
|
|
- if blob.id != entry[-2]:
|
|
|
+ if blob.id != entry.sha:
|
|
|
yield name
|