hgext/narrow/narrowcommands.py
changeset 46663 a4c19a162615
parent 46477 3c360ab2688d
child 46895 6085b7f1536d
equal deleted inserted replaced
46662:db8037e38085 46663:a4c19a162615
   593         remotepath = ui.expandpath(remotepath or b'default')
   593         remotepath = ui.expandpath(remotepath or b'default')
   594         url, branches = hg.parseurl(remotepath)
   594         url, branches = hg.parseurl(remotepath)
   595         ui.status(_(b'comparing with %s\n') % util.hidepassword(url))
   595         ui.status(_(b'comparing with %s\n') % util.hidepassword(url))
   596         remote = hg.peer(repo, opts, url)
   596         remote = hg.peer(repo, opts, url)
   597 
   597 
   598         # check narrow support before doing anything if widening needs to be
   598         try:
   599         # performed. In future we should also abort if client is ellipses and
   599             # check narrow support before doing anything if widening needs to be
   600         # server does not support ellipses
   600             # performed. In future we should also abort if client is ellipses and
   601         if widening and wireprototypes.NARROWCAP not in remote.capabilities():
   601             # server does not support ellipses
   602             raise error.Abort(_(b"server does not support narrow clones"))
   602             if (
   603 
   603                 widening
   604         commoninc = discovery.findcommonincoming(repo, remote)
   604                 and wireprototypes.NARROWCAP not in remote.capabilities()
   605 
   605             ):
   606         if autoremoveincludes:
   606                 raise error.Abort(_(b"server does not support narrow clones"))
   607             outgoing = discovery.findcommonoutgoing(
   607 
   608                 repo, remote, commoninc=commoninc
   608             commoninc = discovery.findcommonincoming(repo, remote)
   609             )
   609 
   610             ui.status(_(b'looking for unused includes to remove\n'))
   610             if autoremoveincludes:
   611             localfiles = set()
   611                 outgoing = discovery.findcommonoutgoing(
   612             for n in itertools.chain(outgoing.missing, outgoing.excluded):
   612                     repo, remote, commoninc=commoninc
   613                 localfiles.update(repo[n].files())
   613                 )
   614             suggestedremovals = []
   614                 ui.status(_(b'looking for unused includes to remove\n'))
   615             for include in sorted(oldincludes):
   615                 localfiles = set()
   616                 match = narrowspec.match(repo.root, [include], oldexcludes)
   616                 for n in itertools.chain(outgoing.missing, outgoing.excluded):
   617                 if not any(match(f) for f in localfiles):
   617                     localfiles.update(repo[n].files())
   618                     suggestedremovals.append(include)
   618                 suggestedremovals = []
   619             if suggestedremovals:
   619                 for include in sorted(oldincludes):
   620                 for s in suggestedremovals:
   620                     match = narrowspec.match(repo.root, [include], oldexcludes)
   621                     ui.status(b'%s\n' % s)
   621                     if not any(match(f) for f in localfiles):
   622                 if (
   622                         suggestedremovals.append(include)
   623                     ui.promptchoice(
   623                 if suggestedremovals:
   624                         _(
   624                     for s in suggestedremovals:
   625                             b'remove these unused includes (yn)?'
   625                         ui.status(b'%s\n' % s)
   626                             b'$$ &Yes $$ &No'
   626                     if (
       
   627                         ui.promptchoice(
       
   628                             _(
       
   629                                 b'remove these unused includes (yn)?'
       
   630                                 b'$$ &Yes $$ &No'
       
   631                             )
   627                         )
   632                         )
   628                     )
   633                         == 0
   629                     == 0
   634                     ):
   630                 ):
   635                         removedincludes.update(suggestedremovals)
   631                     removedincludes.update(suggestedremovals)
   636                         narrowing = True
   632                     narrowing = True
   637                 else:
   633             else:
   638                     ui.status(_(b'found no unused includes\n'))
   634                 ui.status(_(b'found no unused includes\n'))
   639 
   635 
   640             if narrowing:
   636         if narrowing:
   641                 newincludes = oldincludes - removedincludes
   637             newincludes = oldincludes - removedincludes
   642                 newexcludes = oldexcludes | addedexcludes
   638             newexcludes = oldexcludes | addedexcludes
   643                 _narrow(
   639             _narrow(
   644                     ui,
   640                 ui,
   645                     repo,
   641                 repo,
   646                     remote,
   642                 remote,
   647                     commoninc,
   643                 commoninc,
   648                     oldincludes,
   644                 oldincludes,
   649                     oldexcludes,
   645                 oldexcludes,
   650                     newincludes,
   646                 newincludes,
   651                     newexcludes,
   647                 newexcludes,
   652                     opts[b'force_delete_local_changes'],
   648                 opts[b'force_delete_local_changes'],
   653                     opts[b'backup'],
   649                 opts[b'backup'],
   654                 )
   650             )
   655                 # _narrow() updated the narrowspec and _widen() below needs to
   651             # _narrow() updated the narrowspec and _widen() below needs to
   656                 # use the updated values as its base (otherwise removed includes
   652             # use the updated values as its base (otherwise removed includes
   657                 # and addedexcludes will be lost in the resulting narrowspec)
   653             # and addedexcludes will be lost in the resulting narrowspec)
   658                 oldincludes = newincludes
   654             oldincludes = newincludes
   659                 oldexcludes = newexcludes
   655             oldexcludes = newexcludes
   660 
   656 
   661             if widening:
   657         if widening:
   662                 newincludes = oldincludes | addedincludes
   658             newincludes = oldincludes | addedincludes
   663                 newexcludes = oldexcludes - removedexcludes
   659             newexcludes = oldexcludes - removedexcludes
   664                 _widen(
   660             _widen(
   665                     ui,
   661                 ui,
   666                     repo,
   662                 repo,
   667                     remote,
   663                 remote,
   668                     commoninc,
   664                 commoninc,
   669                     oldincludes,
   665                 oldincludes,
   670                     oldexcludes,
   666                 oldexcludes,
   671                     newincludes,
   667                 newincludes,
   672                     newexcludes,
   668                 newexcludes,
   673                 )
   669             )
   674         finally:
       
   675             remote.close()
   670 
   676 
   671     return 0
   677     return 0