commit - 52328a607b0de317a4d50f1763c91b054df3c1b1
commit + 32820bdabd280c2f60d32014bb7a6dd3eac27a04
blob - e9266b05d801c6d50cc6a8b1149abd5749b773ce
blob + b2f34545e8e96d302115d0791a7a4cf90692bcf1
--- dulwich/index.py
+++ dulwich/index.py
"""Parser for the git index file format."""
-import collections
+from dataclasses import dataclass
import os
import stat
import struct
)
from .pack import ObjectContainer, SHA1Reader, SHA1Writer
-# TODO(jelmer): Switch to dataclass?
-IndexEntry = collections.namedtuple(
- "IndexEntry",
- [
- "ctime",
- "mtime",
- "dev",
- "ino",
- "mode",
- "uid",
- "gid",
- "size",
- "sha",
- "flags",
- "extended_flags",
- ],
-)
+@dataclass
+class IndexEntry:
+ ctime: int | float | Tuple[int, int]
+ mtime: int | float | Tuple[int, int]
+ dev: int
+ ino: int
+ mode: int
+ uid: int
+ gid: int
+ size: int
+ sha: bytes
+ flags: int
+ extended_flags: int
class ConflictedIndexEntry:
blob - 411fb6485f956dec8b810720f0a1172b9bf80eed
blob + 660fa416263b69b99f262355b22775d69912a61f
--- dulwich/tests/test_index.py
+++ dulwich/tests/test_index.py
def test_getitem(self):
self.assertEqual(
- (
+ IndexEntry(
(1230680220, 0),
(1230680220, 0),
2050,
class BuildIndexTests(TestCase):
def assertReasonableIndexEntry(self, index_entry, mode, filesize, sha):
- self.assertEqual(index_entry[4], mode) # mode
- self.assertEqual(index_entry[7], filesize) # filesize
- self.assertEqual(index_entry[8], sha) # sha
+ self.assertEqual(index_entry.mode, mode) # mode
+ self.assertEqual(index_entry.size, filesize) # filesize
+ self.assertEqual(index_entry.sha, sha) # sha
def assertFileContents(self, path, contents, symlink=False):
if symlink:
# dir c
cpath = os.path.join(repo.path, "c")
self.assertTrue(os.path.isdir(cpath))
- self.assertEqual(index[b"c"][4], S_IFGITLINK) # mode
- self.assertEqual(index[b"c"][8], c.id) # sha
+ self.assertEqual(index[b"c"].mode, S_IFGITLINK) # mode
+ self.assertEqual(index[b"c"].sha, c.id) # sha
def test_git_submodule_exists(self):
repo_dir = tempfile.mkdtemp()
# dir c
cpath = os.path.join(repo.path, "c")
self.assertTrue(os.path.isdir(cpath))
- self.assertEqual(index[b"c"][4], S_IFGITLINK) # mode
- self.assertEqual(index[b"c"][8], c.id) # sha
+ self.assertEqual(index[b"c"].mode, S_IFGITLINK) # mode
+ self.assertEqual(index[b"c"].sha, c.id) # sha
class GetUnstagedChangesTests(TestCase):