Skip to content

Commit 1b2615c

Browse files
committed
review
- speedup additional .gitmodules check
1 parent 999c765 commit 1b2615c

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

‎git/util.py‎

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,63 +29,62 @@
2929
if sys.platform == "win32":
3030
__all__.append("to_native_path_windows")
3131

32-
from abc import abstractmethod
3332
import contextlib
34-
from functools import wraps
3533
import getpass
3634
import logging
3735
import ntpath
3836
import os
3937
import os.path as osp
40-
from pathlib import Path
4138
import platform
4239
import re
4340
import shutil
4441
import stat
4542
import subprocess
4643
import time
47-
from urllib.parse import urlsplit, urlunsplit
4844
import warnings
49-
50-
# NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of
51-
# these be used indirectly through other GitPython modules, which avoids having to write
52-
# gitdb all the time in their imports. They are not in __all__, at least currently,
53-
# because they could be removed or changed at any time, and so should not be considered
54-
# conceptually public to code outside GitPython. Linters of course do not like it.
55-
from gitdb.util import (
56-
LazyMixin, # noqa: F401
57-
LockedFD, # noqa: F401
58-
bin_to_hex, # noqa: F401
59-
file_contents_ro, # noqa: F401
60-
file_contents_ro_filepath, # noqa: F401
61-
hex_to_bin, # noqa: F401
62-
make_sha,
63-
to_bin_sha, # noqa: F401
64-
to_hex_sha, # noqa: F401
65-
)
45+
from abc import abstractmethod
46+
from functools import wraps
47+
from pathlib import Path
6648

6749
# typing ---------------------------------------------------------
68-
6950
from typing import (
51+
IO,
52+
TYPE_CHECKING,
7053
Any,
7154
AnyStr,
7255
Callable,
7356
Dict,
7457
Generator,
75-
IO,
7658
Iterator,
7759
List,
7860
Optional,
7961
Pattern,
8062
Sequence,
8163
Tuple,
82-
TYPE_CHECKING,
8364
Type,
8465
TypeVar,
8566
Union,
8667
cast,
8768
overload,
8869
)
70+
from urllib.parse import urlsplit, urlunsplit
71+
72+
# NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of
73+
# these be used indirectly through other GitPython modules, which avoids having to write
74+
# gitdb all the time in their imports. They are not in __all__, at least currently,
75+
# because they could be removed or changed at any time, and so should not be considered
76+
# conceptually public to code outside GitPython. Linters of course do not like it.
77+
from gitdb.util import (
78+
LazyMixin, # noqa: F401
79+
LockedFD, # noqa: F401
80+
bin_to_hex, # noqa: F401
81+
file_contents_ro, # noqa: F401
82+
file_contents_ro_filepath, # noqa: F401
83+
hex_to_bin, # noqa: F401
84+
make_sha,
85+
to_bin_sha, # noqa: F401
86+
to_hex_sha, # noqa: F401
87+
)
8988

9089
if TYPE_CHECKING:
9190
from git.cmd import Git
@@ -94,9 +93,9 @@
9493
from git.repo.base import Repo
9594

9695
from git.types import (
96+
HSH_TD,
9797
Files_TD,
9898
Has_id_attribute,
99-
HSH_TD,
10099
Literal,
101100
PathLike,
102101
Protocol,
@@ -419,11 +418,13 @@ def _validate_repo_path(path: PathLike, mode: Union[int, None] = None) -> None:
419418
hfs_name = part.translate(_HFS_IGNORABLES).lower()
420419
if ntfs_name in (".git", "git~1") or hfs_name == ".git":
421420
raise ValueError("Repository path aliases Git metadata: %r" % name)
422-
aliases_gitmodules = (
423-
ntfs_name == ".gitmodules" or hfs_name == ".gitmodules" or ntfs_name in _NTFS_DOTGITMODULES_SHORT_NAMES
424-
)
425-
if aliases_gitmodules and mode is not None and stat.S_ISLNK(mode):
426-
raise ValueError("Symbolic link aliases the submodule configuration: %r" % name)
421+
if mode is not None and stat.S_ISLNK(mode):
422+
if (
423+
ntfs_name == ".gitmodules"
424+
or hfs_name == ".gitmodules"
425+
or ntfs_name in _NTFS_DOTGITMODULES_SHORT_NAMES
426+
):
427+
raise ValueError("Symbolic link aliases the submodule configuration: %r" % name)
427428

428429

429430
def assure_directory_exists(path: PathLike, is_file: bool = False) -> bool:

0 commit comments

Comments
 (0)