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

Commitd0f24c9

Browse files
committed
Merge branch 'submodupdate'
2 parentscf1d5bd +523fb31 commitd0f24c9

File tree

6 files changed

+478
-295
lines changed

6 files changed

+478
-295
lines changed

‎doc/source/changes.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ Changelog
2121

2222
* ``create(...)`` method now supports the reflog, but will not raise ``GitCommandError`` anymore as it is a pure python implementation now. Instead, it raises ``OSError``.
2323

24-
* **Intrusive Changes** to ``Actor`` type
25-
26-
* the *name* field is now using unicode if ascii does not match
27-
2824
* **Intrusive Changes** to ``Repo`` type
2925

30-
* ``create_head(...)`` method does not support**kwargs anymore, instead it supports a logmsg parameter
26+
* ``create_head(...)`` method does not support kwargs anymore, instead it supports a logmsg parameter
3127

32-
* Repo.rev_parse now supports the [ref]@{n} syntax, wheren is the number of steps to look into the reference's past
28+
* Repo.rev_parse now supports the [ref]@{n} syntax, where*n* is the number of steps to look into the reference's past
3329

3430
* **BugFixes**
3531

‎objects/submodule/base.py

Lines changed: 117 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
fromgit.utilimport (
1313
Iterable,
1414
join_path_native,
15-
to_native_path_linux
15+
to_native_path_linux,
16+
RemoteProgress
1617
)
1718

1819
fromgit.configimportSectionConstraint
1920
fromgit.excimport (
2021
InvalidGitRepositoryError,
2122
NoSuchPathError
2223
)
24+
2325
importstat
2426
importgit
2527

@@ -29,7 +31,23 @@
2931

3032
importshutil
3133

32-
__all__= ["Submodule"]
34+
__all__= ["Submodule","UpdateProgress"]
35+
36+
37+
classUpdateProgress(RemoteProgress):
38+
"""Class providing detailed progress information to the caller who should
39+
derive from it and implement the ``update(...)`` message"""
40+
CLONE,FETCH,UPDWKTREE= [1<<xforxinrange(RemoteProgress._num_op_codes,RemoteProgress._num_op_codes+3)]
41+
_num_op_codes=RemoteProgress._num_op_codes+3
42+
43+
__slots__=tuple()
44+
45+
46+
BEGIN=UpdateProgress.BEGIN
47+
END=UpdateProgress.END
48+
CLONE=UpdateProgress.CLONE
49+
FETCH=UpdateProgress.FETCH
50+
UPDWKTREE=UpdateProgress.UPDWKTREE
3351

3452

3553
# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import
@@ -285,7 +303,8 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
285303

286304
returnsm
287305

288-
defupdate(self,recursive=False,init=True,to_latest_revision=False):
306+
defupdate(self,recursive=False,init=True,to_latest_revision=False,progress=None,
307+
dry_run=False):
289308
"""Update the repository of this submodule to point to the checkout
290309
we point at with the binsha of this instance.
291310
@@ -297,20 +316,51 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
297316
This only works if we have a local tracking branch, which is the case
298317
if the remote repository had a master branch, or of the 'branch' option
299318
was specified for this submodule and the branch existed remotely
319+
:param progress: UpdateProgress instance or None of no progress should be shown
320+
:param dry_run: if True, the operation will only be simulated, but not performed.
321+
All performed operations are read-only
300322
:note: does nothing in bare repositories
301323
:note: method is definitely not atomic if recurisve is True
302324
:return: self"""
303325
ifself.repo.bare:
304326
returnself
305327
#END pass in bare mode
306328

329+
ifprogressisNone:
330+
progress=UpdateProgress()
331+
#END handle progress
332+
prefix=''
333+
ifdry_run:
334+
prefix="DRY-RUN: "
335+
#END handle prefix
336+
337+
# to keep things plausible in dry-run mode
338+
ifdry_run:
339+
mrepo=None
340+
#END init mrepo
307341

308342
# ASSURE REPO IS PRESENT AND UPTODATE
309343
#####################################
310344
try:
311345
mrepo=self.module()
312-
forremoteinmrepo.remotes:
313-
remote.fetch()
346+
rmts=mrepo.remotes
347+
len_rmts=len(rmts)
348+
fori,remoteinenumerate(rmts):
349+
op=FETCH
350+
ifi==0:
351+
op|=BEGIN
352+
#END handle start
353+
354+
progress.update(op,i,len_rmts,prefix+"Fetching remote %s of submodule %r"% (remote,self.name))
355+
#===============================
356+
ifnotdry_run:
357+
remote.fetch(progress=progress)
358+
#END handle dry-run
359+
#===============================
360+
ifi==len_rmts-1:
361+
op|=END
362+
#END handle end
363+
progress.update(op,i,len_rmts,prefix+"Done fetching remote of submodule %r"%self.name)
314364
#END fetch new data
315365
exceptInvalidGitRepositoryError:
316366
ifnotinit:
@@ -320,7 +370,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
320370

321371
# there is no git-repository yet - but delete empty paths
322372
module_path=join_path_native(self.repo.working_tree_dir,self.path)
323-
ifos.path.isdir(module_path):
373+
ifnotdry_runandos.path.isdir(module_path):
324374
try:
325375
os.rmdir(module_path)
326376
exceptOSError:
@@ -330,40 +380,51 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
330380

331381
# don't check it out at first - nonetheless it will create a local
332382
# branch according to the remote-HEAD if possible
333-
mrepo=git.Repo.clone_from(self.url,module_path,n=True)
383+
progress.update(BEGIN|CLONE,0,1,prefix+"Cloning %s to %s in submodule %r"% (self.url,module_path,self.name))
384+
ifnotdry_run:
385+
mrepo=git.Repo.clone_from(self.url,module_path,n=True)
386+
#END handle dry-run
387+
progress.update(END|CLONE,0,1,prefix+"Done cloning to %s"%module_path)
334388

335-
# see whether we have a valid branch to checkout
336-
try:
337-
# find a remote which has our branch - we try to be flexible
338-
remote_branch=find_first_remote_branch(mrepo.remotes,self.branch_name)
339-
local_branch=mkhead(mrepo,self.branch_path)
340-
341-
# have a valid branch, but no checkout - make sure we can figure
342-
# that out by marking the commit with a null_sha
343-
local_branch.set_object(util.Object(mrepo,self.NULL_BIN_SHA))
344-
# END initial checkout + branch creation
345-
346-
# make sure HEAD is not detached
347-
mrepo.head.set_reference(local_branch,logmsg="submodule: attaching head to %s"%local_branch)
348-
mrepo.head.ref.set_tracking_branch(remote_branch)
349-
exceptIndexError:
350-
print>>sys.stderr,"Warning: Failed to checkout tracking branch %s"%self.branch_path
351-
#END handle tracking branch
352389

353-
# NOTE: Have to write the repo config file as well, otherwise
354-
# the default implementation will be offended and not update the repository
355-
# Maybe this is a good way to assure it doesn't get into our way, but
356-
# we want to stay backwards compatible too ... . Its so redundant !
357-
self.repo.config_writer().set_value(sm_section(self.name),'url',self.url)
390+
ifnotdry_run:
391+
# see whether we have a valid branch to checkout
392+
try:
393+
# find a remote which has our branch - we try to be flexible
394+
remote_branch=find_first_remote_branch(mrepo.remotes,self.branch_name)
395+
local_branch=mkhead(mrepo,self.branch_path)
396+
397+
# have a valid branch, but no checkout - make sure we can figure
398+
# that out by marking the commit with a null_sha
399+
local_branch.set_object(util.Object(mrepo,self.NULL_BIN_SHA))
400+
# END initial checkout + branch creation
401+
402+
# make sure HEAD is not detached
403+
mrepo.head.set_reference(local_branch,logmsg="submodule: attaching head to %s"%local_branch)
404+
mrepo.head.ref.set_tracking_branch(remote_branch)
405+
exceptIndexError:
406+
print>>sys.stderr,"Warning: Failed to checkout tracking branch %s"%self.branch_path
407+
#END handle tracking branch
408+
409+
# NOTE: Have to write the repo config file as well, otherwise
410+
# the default implementation will be offended and not update the repository
411+
# Maybe this is a good way to assure it doesn't get into our way, but
412+
# we want to stay backwards compatible too ... . Its so redundant !
413+
self.repo.config_writer().set_value(sm_section(self.name),'url',self.url)
414+
#END handle dry_run
358415
#END handle initalization
359416

360417

361418
# DETERMINE SHAS TO CHECKOUT
362419
############################
363420
binsha=self.binsha
364421
hexsha=self.hexsha
365-
is_detached=mrepo.head.is_detached
366-
ifto_latest_revision:
422+
ifmrepoisnotNone:
423+
# mrepo is only set if we are not in dry-run mode or if the module existed
424+
is_detached=mrepo.head.is_detached
425+
#END handle dry_run
426+
427+
ifnotdry_runandto_latest_revision:
367428
msg_base="Cannot update to latest revision in repository at %r as "%mrepo.working_dir
368429
ifnotis_detached:
369430
rref=mrepo.head.ref.tracking_branch()
@@ -380,27 +441,35 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
380441
# END handle to_latest_revision option
381442

382443
# update the working tree
383-
ifmrepo.head.commit.binsha!=binsha:
384-
ifis_detached:
385-
# NOTE: for now we force, the user is no supposed to change detached
386-
# submodules anyway. Maybe at some point this becomes an option, to
387-
# properly handle user modifications - see below for future options
388-
# regarding rebase and merge.
389-
mrepo.git.checkout(hexsha,force=True)
390-
else:
391-
# TODO: allow to specify a rebase, merge, or reset
392-
# TODO: Warn if the hexsha forces the tracking branch off the remote
393-
# branch - this should be prevented when setting the branch option
394-
mrepo.head.reset(hexsha,index=True,working_tree=True)
395-
# END handle checkout
444+
# handles dry_run
445+
ifmrepoisnotNoneandmrepo.head.commit.binsha!=binsha:
446+
progress.update(BEGIN|UPDWKTREE,0,1,prefix+"Updating working tree at %s for submodule %r"% (self.path,self.name))
447+
ifnotdry_run:
448+
ifis_detached:
449+
# NOTE: for now we force, the user is no supposed to change detached
450+
# submodules anyway. Maybe at some point this becomes an option, to
451+
# properly handle user modifications - see below for future options
452+
# regarding rebase and merge.
453+
mrepo.git.checkout(hexsha,force=True)
454+
else:
455+
# TODO: allow to specify a rebase, merge, or reset
456+
# TODO: Warn if the hexsha forces the tracking branch off the remote
457+
# branch - this should be prevented when setting the branch option
458+
mrepo.head.reset(hexsha,index=True,working_tree=True)
459+
# END handle checkout
460+
#END handle dry_run
461+
progress.update(END|UPDWKTREE,0,1,prefix+"Done updating working tree for submodule %r"%self.name)
396462
# END update to new commit only if needed
397463

398464
# HANDLE RECURSION
399465
##################
400466
ifrecursive:
401-
forsubmoduleinself.iter_items(self.module()):
402-
submodule.update(recursive,init,to_latest_revision)
403-
# END handle recursive update
467+
# in dry_run mode, the module might not exist
468+
ifmrepoisnotNone:
469+
forsubmoduleinself.iter_items(self.module()):
470+
submodule.update(recursive,init,to_latest_revision,progress=progress,dry_run=dry_run)
471+
# END handle recursive update
472+
#END handle dry run
404473
# END for each submodule
405474

406475
returnself
@@ -800,8 +869,7 @@ def config_reader(self):
800869
defchildren(self):
801870
"""
802871
:return: IterableList(Submodule, ...) an iterable list of submodules instances
803-
which are children of this submodule
804-
:raise InvalidGitRepositoryError: if the submodule is not checked-out"""
872+
which are children of this submodule or 0 if the submodule is not checked out"""
805873
returnself._get_intermediate_items(self)
806874

807875
#} END query interface

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp