Skip to content

Commit 2f49a66

Browse files
Reduce to docs-only change per maintainer review
Per @Byron's feedback: dropping the is_shallow property, since a per-commit property re-reads the shallow file on every call, which is IO-heavy when checking many commits. Keeping just the stats() docstring note about the limitation for a quick merge. Happy to follow up with a Repo-level implementation (e.g. returning the set of shallow-boundary hashes) as a separate PR if useful.
1 parent 6b1dd78 commit 2f49a66

2 files changed

Lines changed: 3 additions & 44 deletions

File tree

git/objects/commit.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -369,37 +369,15 @@ def iter_parents(self, paths: Union[PathLike, Sequence[PathLike]] = "", **kwargs
369369

370370
return self.iter_items(self.repo, self, paths, **kwargs)
371371

372-
@property
373-
def is_shallow(self) -> bool:
374-
"""Check whether this commit is a shallow boundary (graft) commit.
375-
376-
A commit at the boundary of a shallow clone appears to have no
377-
parents from Git's perspective, even though the underlying commit
378-
object still references a parent SHA that was never fetched. Calling
379-
:attr:`stats` (or anything else that diffs against the parent) on
380-
such a commit will raise :exc:`~git.exc.GitCommandError` because the
381-
parent object does not exist locally.
382-
383-
:return:
384-
True if this commit's hexsha appears in the repository's
385-
``shallow`` file, False otherwise (including for non-shallow
386-
repositories).
387-
"""
388-
shallow_file = os.path.join(self.repo.git_dir, "shallow")
389-
if not os.path.isfile(shallow_file):
390-
return False
391-
with open(shallow_file, "r") as f:
392-
return self.hexsha in f.read().split()
393-
394372
@property
395373
def stats(self) -> Stats:
396374
"""Create a git stat from changes between this commit and its first parent
397375
or from all changes done if this is the very first commit.
398376
399377
:note:
400-
If this commit is at the boundary of a shallow clone (see
401-
:attr:`is_shallow`), this will raise :exc:`~git.exc.GitCommandError`
402-
because the parent object was never fetched.
378+
If this commit is at the boundary of a shallow clone, this will
379+
raise :exc:`~git.exc.GitCommandError`, since the parent object
380+
was never fetched and only exists as a reference on this commit.
403381
404382
:return:
405383
:class:`Stats`

test/test_commit.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,6 @@ def check_entries(d, has_change_type=False):
164164
self.assertEqual(commit.committer_tz_offset, 14400, commit.committer_tz_offset)
165165
self.assertEqual(commit.message, "initial project\n")
166166

167-
@with_rw_directory
168-
def test_is_shallow(self, rw_dir):
169-
"""A commit at the shallow boundary should report is_shallow, and
170-
accessing its stats should raise GitCommandError."""
171-
full_repo = self.rorepo
172-
shallow_path = osp.join(rw_dir, "shallow_clone")
173-
shallow_repo = Repo.clone_from(full_repo.git_dir, shallow_path, depth=2, no_local=True)
174-
175-
commits = list(shallow_repo.iter_commits())
176-
boundary_commit = commits[-1]
177-
178-
self.assertTrue(boundary_commit.is_shallow)
179-
with self.assertRaises(GitCommandError):
180-
boundary_commit.stats
181-
182-
if len(commits) > 1:
183-
non_boundary_commit = commits[0]
184-
self.assertFalse(non_boundary_commit.is_shallow)
185-
186167
def test_renames(self):
187168
commit = self.rorepo.commit("185d847ec7647fd2642a82d9205fb3d07ea71715")
188169
files = commit.stats.files

0 commit comments

Comments
 (0)