mercurial/sparse.py
changeset 45334 b9b055f15035
parent 45295 6a8eafaeff3b
child 45339 9320f66854f6
equal deleted inserted replaced
45333:f569ca3eb430 45334:b9b055f15035
   267         # Still have pending changes. Don't bother trying to prune.
   267         # Still have pending changes. Don't bother trying to prune.
   268         return
   268         return
   269 
   269 
   270     sparsematch = matcher(repo, includetemp=False)
   270     sparsematch = matcher(repo, includetemp=False)
   271     dirstate = repo.dirstate
   271     dirstate = repo.dirstate
   272     actions = []
   272     mresult = mergemod.mergeresult()
   273     dropped = []
   273     dropped = []
   274     tempincludes = readtemporaryincludes(repo)
   274     tempincludes = readtemporaryincludes(repo)
   275     for file in tempincludes:
   275     for file in tempincludes:
   276         if file in dirstate and not sparsematch(file):
   276         if file in dirstate and not sparsematch(file):
   277             message = _(b'dropping temporarily included sparse files')
   277             message = _(b'dropping temporarily included sparse files')
   278             actions.append((file, None, message))
   278             mresult.addfile(file, b'r', None, message)
   279             dropped.append(file)
   279             dropped.append(file)
   280 
   280 
   281     typeactions = mergemod.emptyactions()
       
   282     typeactions[b'r'] = actions
       
   283     mergemod.applyupdates(
   281     mergemod.applyupdates(
   284         repo, typeactions, repo[None], repo[b'.'], False, wantfiledata=False
   282         repo, mresult, repo[None], repo[b'.'], False, wantfiledata=False
   285     )
   283     )
   286 
   284 
   287     # Fix dirstate
   285     # Fix dirstate
   288     for file in dropped:
   286     for file in dropped:
   289         dirstate.drop(file)
   287         dirstate.drop(file)
   427             % len(temporaryfiles)
   425             % len(temporaryfiles)
   428         )
   426         )
   429         addtemporaryincludes(repo, temporaryfiles)
   427         addtemporaryincludes(repo, temporaryfiles)
   430 
   428 
   431         # Add the new files to the working copy so they can be merged, etc
   429         # Add the new files to the working copy so they can be merged, etc
   432         actions = []
   430         tmresult = mergemod.mergeresult()
   433         message = b'temporarily adding to sparse checkout'
   431         message = b'temporarily adding to sparse checkout'
   434         wctxmanifest = repo[None].manifest()
   432         wctxmanifest = repo[None].manifest()
   435         for file in temporaryfiles:
   433         for file in temporaryfiles:
   436             if file in wctxmanifest:
   434             if file in wctxmanifest:
   437                 fctx = repo[None][file]
   435                 fctx = repo[None][file]
   438                 actions.append((file, (fctx.flags(), False), message))
   436                 tmresult.addfile(
   439 
   437                     file,
   440         typeactions = mergemod.emptyactions()
   438                     mergestatemod.ACTION_GET,
   441         typeactions[mergestatemod.ACTION_GET] = actions
   439                     (fctx.flags(), False),
       
   440                     message,
       
   441                 )
       
   442 
   442         mergemod.applyupdates(
   443         mergemod.applyupdates(
   443             repo, typeactions, repo[None], repo[b'.'], False, wantfiledata=False
   444             repo, tmresult, repo[None], repo[b'.'], False, wantfiledata=False
   444         )
   445         )
   445 
   446 
   446         dirstate = repo.dirstate
   447         dirstate = repo.dirstate
   447         for file, flags, msg in actions:
   448         for file, flags, msg in tmresult.getactions([mergestatemod.ACTION_GET]):
   448             dirstate.normal(file)
   449             dirstate.normal(file)
   449 
   450 
   450     profiles = activeconfig(repo)[2]
   451     profiles = activeconfig(repo)[2]
   451     changedprofiles = profiles & files
   452     changedprofiles = profiles & files
   452     # If an active profile changed during the update, refresh the checkout.
   453     # If an active profile changed during the update, refresh the checkout.
   495     if abort:
   496     if abort:
   496         raise error.Abort(
   497         raise error.Abort(
   497             _(b'could not update sparseness due to pending changes')
   498             _(b'could not update sparseness due to pending changes')
   498         )
   499         )
   499 
   500 
   500     # Calculate actions
   501     # Calculate merge result
   501     dirstate = repo.dirstate
   502     dirstate = repo.dirstate
   502     ctx = repo[b'.']
   503     ctx = repo[b'.']
   503     added = []
   504     added = []
   504     lookup = []
   505     lookup = []
   505     dropped = []
   506     dropped = []
   506     mf = ctx.manifest()
   507     mf = ctx.manifest()
   507     files = set(mf)
   508     files = set(mf)
   508 
   509     mresult = mergemod.mergeresult()
   509     actions = {}
       
   510 
   510 
   511     for file in files:
   511     for file in files:
   512         old = origsparsematch(file)
   512         old = origsparsematch(file)
   513         new = sparsematch(file)
   513         new = sparsematch(file)
   514         # Add files that are newly included, or that don't exist in
   514         # Add files that are newly included, or that don't exist in
   515         # the dirstate yet.
   515         # the dirstate yet.
   516         if (new and not old) or (old and new and not file in dirstate):
   516         if (new and not old) or (old and new and not file in dirstate):
   517             fl = mf.flags(file)
   517             fl = mf.flags(file)
   518             if repo.wvfs.exists(file):
   518             if repo.wvfs.exists(file):
   519                 actions[file] = (b'e', (fl,), b'')
   519                 mresult.addfile(file, b'e', (fl,), b'')
   520                 lookup.append(file)
   520                 lookup.append(file)
   521             else:
   521             else:
   522                 actions[file] = (b'g', (fl, False), b'')
   522                 mresult.addfile(file, b'g', (fl, False), b'')
   523                 added.append(file)
   523                 added.append(file)
   524         # Drop files that are newly excluded, or that still exist in
   524         # Drop files that are newly excluded, or that still exist in
   525         # the dirstate.
   525         # the dirstate.
   526         elif (old and not new) or (not old and not new and file in dirstate):
   526         elif (old and not new) or (not old and not new and file in dirstate):
   527             dropped.append(file)
   527             dropped.append(file)
   528             if file not in pending:
   528             if file not in pending:
   529                 actions[file] = (b'r', [], b'')
   529                 mresult.addfile(file, b'r', [], b'')
   530 
   530 
   531     # Verify there are no pending changes in newly included files
   531     # Verify there are no pending changes in newly included files
   532     abort = False
   532     abort = False
   533     for file in lookup:
   533     for file in lookup:
   534         repo.ui.warn(_(b"pending changes to '%s'\n") % file)
   534         repo.ui.warn(_(b"pending changes to '%s'\n") % file)
   548             old = origsparsematch(file)
   548             old = origsparsematch(file)
   549             new = sparsematch(file)
   549             new = sparsematch(file)
   550             if old and not new:
   550             if old and not new:
   551                 dropped.append(file)
   551                 dropped.append(file)
   552 
   552 
   553     # Apply changes to disk
       
   554     typeactions = mergemod.emptyactions()
       
   555     for f, (m, args, msg) in pycompat.iteritems(actions):
       
   556         typeactions[m].append((f, args, msg))
       
   557 
       
   558     mergemod.applyupdates(
   553     mergemod.applyupdates(
   559         repo, typeactions, repo[None], repo[b'.'], False, wantfiledata=False
   554         repo, mresult, repo[None], repo[b'.'], False, wantfiledata=False
   560     )
   555     )
   561 
   556 
   562     # Fix dirstate
   557     # Fix dirstate
   563     for file in added:
   558     for file in added:
   564         dirstate.normal(file)
   559         dirstate.normal(file)