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

Commit21b4db5

Browse files
committed
Improved efficiency of the submodule.update process, improved test
1 parent9f73e8b commit21b4db5

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

‎lib/git/objects/submodule.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def __hash__(self):
144144
"""Hash this instance using its logical id, not the sha"""
145145
returnhash(self._name)
146146

147+
def__str__(self):
148+
returnself._name
149+
147150
@classmethod
148151
def_config_parser(cls,repo,parent_commit,read_only):
149152
""":return: Config Parser constrained to our submodule in read or write mode
@@ -250,20 +253,24 @@ def update(self, recursive=False, init=True):
250253
remote_branch=mrepo.remotes.origin.refs[self.branch]
251254
local_branch=git.Head(mrepo,git.Head.to_full_path(self.branch))
252255
ifnotlocal_branch.is_valid():
253-
mrepo.git.checkout(remote_branch,b=self.branch)
254-
else:
255-
# have a valid branch, but no checkout - make sure we can figure
256-
# that out by marking the commit with a null_sha
257-
# have to write it directly as .commit = NULLSHA tries to resolve the sha
258-
ref=mrepo.head.ref
259-
refpath=join_path_native(mrepo.git_dir,ref.to_full_path(ref.path))
260-
refdir=os.path.dirname(refpath)
261-
ifnotos.path.isdir(refdir):
262-
os.makedirs(refdir)
263-
#END handle directory
264-
open(refpath,'w').write(self.NULL_HEX_SHA)
256+
# Setup a tracking configuration - branch doesn't need to
257+
# exist to do that
258+
local_branch.set_tracking_branch(remote_branch)
259+
#END handle local branch
260+
261+
# have a valid branch, but no checkout - make sure we can figure
262+
# that out by marking the commit with a null_sha
263+
# have to write it directly as .commit = NULLSHA tries to resolve the sha
264+
# This will bring the branch into existance
265+
refpath=join_path_native(mrepo.git_dir,local_branch.path)
266+
refdir=os.path.dirname(refpath)
267+
ifnotos.path.isdir(refdir):
268+
os.makedirs(refdir)
269+
#END handle directory
270+
open(refpath,'w').write(self.NULL_HEX_SHA)
265271
# END initial checkout + branch creation
266-
# make sure we are not detached
272+
273+
# make sure HEAD is not detached
267274
mrepo.head.ref=local_branch
268275
exceptIndexError:
269276
print>>sys.stderr,"Warning: Failed to checkout tracking branch %s"%self.branch
@@ -280,13 +287,14 @@ def update(self, recursive=False, init=True):
280287
# branch - this should be prevented when setting the branch option
281288
mrepo.head.reset(self.hexsha,index=True,working_tree=True)
282289
# END handle checkout
283-
284-
ifrecursive:
285-
forsubmoduleinself.iter_items(self.module()):
286-
submodule.update(recursive,init)
287-
# END handle recursive update
288-
# END for each submodule
289290
# END update to new commit only if needed
291+
292+
# HANDLE RECURSION
293+
ifrecursive:
294+
forsubmoduleinself.iter_items(self.module()):
295+
submodule.update(recursive,init)
296+
# END handle recursive update
297+
# END for each submodule
290298

291299
returnself
292300

‎test/git/test_submodule.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def _do_base_tests(self, rwrepo):
8282

8383
# TEST TODO: if a path in the gitmodules file, but not in the index, it raises
8484

85+
# TEST UPDATE
86+
##############
8587
# module retrieval is not always possible
8688
ifrwrepo.bare:
8789
self.failUnlessRaises(InvalidGitRepositoryError,sm.module)
@@ -106,6 +108,9 @@ def _do_base_tests(self, rwrepo):
106108
assertisinstance(sm.module(),git.Repo)
107109
assertsm.module().working_tree_dir==sm.module_path()
108110

111+
# we should have setup a tracking branch, which is also active
112+
assertsm.module().head.ref.tracking_branch()isnotNone
113+
109114
# delete the whole directory and re-initialize
110115
shutil.rmtree(sm.module_path())
111116
sm.update(recursive=False)
@@ -119,10 +124,12 @@ def _do_base_tests(self, rwrepo):
119124
csm.config_writer().set_value('url',new_csm_path)
120125
assertcsm.url==new_csm_path
121126

122-
123127
# update recuesively again
124128
sm.update(recursive=True)
125129

130+
# tracking branch once again
131+
csm.module().head.ref.tracking_branch()isnotNone
132+
126133
# this flushed in a sub-submodule
127134
assertlen(list(rwrepo.iter_submodules()))==2
128135
# END handle bare mode

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp