comparison mercurial/scmutil.py @ 23537:f1b06a8aad42

commit: propagate --addremove to subrepos if -S is specified (issue3759) The recursive addremove operation occurs completely before the first subrepo is committed. Only hg subrepos support the addremove operation at the moment- svn and git subrepos will warn and abort the commit.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 24 Nov 2014 22:27:49 -0500
parents 83bbedc16b3f
children cb42050f2dad
comparison
equal deleted inserted replaced
23536:fcbc66b5da6a 23537:f1b06a8aad42
711 711
712 def matchfiles(repo, files): 712 def matchfiles(repo, files):
713 '''Return a matcher that will efficiently match exactly these files.''' 713 '''Return a matcher that will efficiently match exactly these files.'''
714 return matchmod.exact(repo.root, repo.getcwd(), files) 714 return matchmod.exact(repo.root, repo.getcwd(), files)
715 715
716 def addremove(repo, matcher, opts={}, dry_run=None, similarity=None): 716 def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
717 m = matcher 717 m = matcher
718 if dry_run is None: 718 if dry_run is None:
719 dry_run = opts.get('dry_run') 719 dry_run = opts.get('dry_run')
720 if similarity is None: 720 if similarity is None:
721 similarity = float(opts.get('similarity') or 0) 721 similarity = float(opts.get('similarity') or 0)
722
723 ret = 0
724 join = lambda f: os.path.join(prefix, f)
725
726 wctx = repo[None]
727 for subpath in sorted(wctx.substate):
728 if opts.get('subrepos'):
729 sub = wctx.sub(subpath)
730 try:
731 submatch = matchmod.narrowmatcher(subpath, m)
732 if sub.addremove(submatch, prefix, opts, dry_run, similarity):
733 ret = 1
734 except error.LookupError:
735 repo.ui.status(_("skipping missing subrepository: %s\n")
736 % join(subpath))
722 737
723 rejected = [] 738 rejected = []
724 origbad = m.bad 739 origbad = m.bad
725 def badfn(f, msg): 740 def badfn(f, msg):
726 if f in m.files(): 741 if f in m.files():
735 toprint = unknownset.copy() 750 toprint = unknownset.copy()
736 toprint.update(deleted) 751 toprint.update(deleted)
737 for abs in sorted(toprint): 752 for abs in sorted(toprint):
738 if repo.ui.verbose or not m.exact(abs): 753 if repo.ui.verbose or not m.exact(abs):
739 if abs in unknownset: 754 if abs in unknownset:
740 status = _('adding %s\n') % m.uipath(abs) 755 status = _('adding %s\n') % m.uipath(join(abs))
741 else: 756 else:
742 status = _('removing %s\n') % m.uipath(abs) 757 status = _('removing %s\n') % m.uipath(join(abs))
743 repo.ui.status(status) 758 repo.ui.status(status)
744 759
745 renames = _findrenames(repo, m, added + unknown, removed + deleted, 760 renames = _findrenames(repo, m, added + unknown, removed + deleted,
746 similarity) 761 similarity)
747 762
749 _markchanges(repo, unknown + forgotten, deleted, renames) 764 _markchanges(repo, unknown + forgotten, deleted, renames)
750 765
751 for f in rejected: 766 for f in rejected:
752 if f in m.files(): 767 if f in m.files():
753 return 1 768 return 1
754 return 0 769 return ret
755 770
756 def marktouched(repo, files, similarity=0.0): 771 def marktouched(repo, files, similarity=0.0):
757 '''Assert that files have somehow been operated upon. files are relative to 772 '''Assert that files have somehow been operated upon. files are relative to
758 the repo root.''' 773 the repo root.'''
759 m = matchfiles(repo, files) 774 m = matchfiles(repo, files)