Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d5d143

Browse files
committed
repo: minor code and doc correcions.
+ Expansion of paths also `osp.normalize()` them.+ Make Repo-fields --> class-fields to avoid initializations onconstruct.+ Explain and rename `git.repo.fun.find_git_dir()` is for submodules(`find_submodule_git_dir()`).
1 parentb29388a commit9d5d143

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

‎git/repo/base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .funimport (
4848
rev_parse,
4949
is_git_dir,
50-
find_git_dir,
50+
find_submodule_git_dir,
5151
touch,
5252
)
5353
fromgit.compatimport (
@@ -79,7 +79,7 @@
7979

8080

8181
def_expand_path(p):
82-
returnos.path.abspath(os.path.expandvars(os.path.expanduser(p)))
82+
returnos.path.normpath(os.path.abspath(os.path.expandvars(os.path.expanduser(p))))
8383

8484

8585
classRepo(object):
@@ -98,6 +98,11 @@ class Repo(object):
9898
'git_dir' is the .git repository directory, which is always set."""
9999
DAEMON_EXPORT_FILE='git-daemon-export-ok'
100100

101+
git=None# Must exist, or __del__ will fail in case we raise on `__init__()`
102+
working_dir=None
103+
_working_tree_dir=None
104+
git_dir=None
105+
101106
# precompiled regex
102107
re_whitespace=re.compile(r'\s+')
103108
re_hexsha_only=re.compile('^[0-9A-Fa-f]{40}$')
@@ -138,16 +143,11 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
138143
:raise InvalidGitRepositoryError:
139144
:raise NoSuchPathError:
140145
:return: git.Repo """
141-
self.git=None# should be set for __del__ not to fail in case we raise
142146
epath=os.getenv('GIT_DIR')
143147
epath=_expand_path(epathorpathoros.getcwd())
144148
ifnotos.path.exists(epath):
145149
raiseNoSuchPathError(epath)
146150

147-
self.working_dir=None
148-
self._working_tree_dir=None
149-
self.git_dir=None
150-
151151
## Walk up the path to find the `.git` dir.
152152
#
153153
curpath=epath
@@ -157,20 +157,20 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
157157
# repo instances with paths that depend on path-portions that will not exist after being
158158
# removed. It's just cleaner.
159159
ifis_git_dir(curpath):
160-
self.git_dir=os.path.normpath(curpath)
160+
self.git_dir=curpath
161161
self._working_tree_dir=os.path.dirname(self.git_dir)
162162
break
163163

164-
gitpath=find_git_dir(join(curpath,'.git'))
165-
ifgitpathisnotNone:
166-
self.git_dir=os.path.normpath(gitpath)
164+
sm_gitpath=find_submodule_git_dir(join(curpath,'.git'))
165+
ifsm_gitpathisnotNone:
166+
self.git_dir=os.path.normpath(sm_gitpath)
167167
self._working_tree_dir=curpath
168168
break
169169

170170
ifnotsearch_parent_directories:
171171
break
172-
curpath,dummy=os.path.split(curpath)
173-
ifnotdummy:
172+
curpath,tail=os.path.split(curpath)
173+
ifnottail:
174174
break
175175
# END while curpath
176176

‎git/repo/fun.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
fromgit.compatimportxrange
2121

2222

23-
__all__= ('rev_parse','is_git_dir','touch','find_git_dir','name_to_object','short_to_long','deref_tag',
23+
__all__= ('rev_parse','is_git_dir','touch','find_submodule_git_dir','name_to_object','short_to_long','deref_tag',
2424
'to_commit')
2525

2626

@@ -49,7 +49,8 @@ def is_git_dir(d):
4949
returnFalse
5050

5151

52-
deffind_git_dir(d):
52+
deffind_submodule_git_dir(d):
53+
"""Search for a submodule repo."""
5354
ifis_git_dir(d):
5455
returnd
5556

@@ -64,7 +65,7 @@ def find_git_dir(d):
6465
path=content[8:]
6566
ifnotos.path.isabs(path):
6667
path=join(dirname(d),path)
67-
returnfind_git_dir(path)
68+
returnfind_submodule_git_dir(path)
6869
# end handle exception
6970
returnNone
7071

‎git/test/test_submodule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
fromgit.objects.submodule.baseimportSubmodule
1515
fromgit.objects.submodule.rootimportRootModule,RootUpdateProgress
1616
fromgit.repo.funimport (
17-
find_git_dir,
17+
find_submodule_git_dir,
1818
touch
1919
)
2020
fromgit.test.libimport (
@@ -757,7 +757,7 @@ def assert_exists(sm, value=True):
757757
else:
758758
assertosp.isfile(module_repo_path)
759759
assertsm.module().has_separate_working_tree()
760-
assertfind_git_dir(module_repo_path)isnotNone,"module pointed to by .git file must be valid"
760+
assertfind_submodule_git_dir(module_repo_path)isnotNone,"module pointed to by .git file must be valid"
761761
# end verify submodule 'style'
762762

763763
# test move

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp