view tests/test-mq-symlinks.t @ 33373:fb320398a21c

dirstate: expose a sparse matcher on dirstate (API) The sparse extension performs a lot of monkeypatching of dirstate to make it sparse aware. Essentially, various operations need to take the active sparse config into account. They do this by obtaining a matcher representing the sparse config and filtering paths through it. The monkeypatching is done by stuffing a reference to a repo on dirstate and calling sparse.matcher() (which takes a repo instance) during each function call. The reason this function takes a repo instance is because resolving the sparse config may require resolving file contents from filelogs, and that requires a repo. (If the current sparse config references "profile" files, the contents of those files from the dirstate's parent revisions is resolved.) I seem to recall people having strong opinions that the dirstate object not have a reference to a repo. So copying what the sparse extension does probably won't fly in core. Plus, the dirstate modifications shouldn't require a full repo: they only need a matcher. So there's no good reason to stuff a reference to the repo in dirstate. This commit exposes a sparse matcher to dirstate via a property that when looked up will call a function that eventually calls sparse.matcher(). The repo instance is bound in a closure, so it isn't exposed to dirstate. This approach is functionally similar to what the sparse extension does today, except it hides the repo instance from dirstate. The approach is not optimal because we have to call a proxy function and sparse.matcher() on every property lookup. There is room to cache the matcher instance in dirstate. After all, the matcher only changes if the dirstate's parents change or if the sparse config changes. It feels like we should be able to detect both events and update the matcher when this occurs. But for now we preserve the existing semantics so we can move the dirstate sparseness bits into core. Once in core, refactoring becomes a bit easier since it will be clearer how all these components interact. The sparse extension has been updated to use the new property. Because all references to the repo on dirstate have been removed, the code for setting it has been removed.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 08 Jul 2017 16:18:04 -0700
parents c2380b448265
children 55c6ebd11cb9
line wrap: on
line source

#require symlink

  $ echo "[extensions]" >> $HGRCPATH
  $ echo "mq=" >> $HGRCPATH

  $ hg init
  $ hg qinit
  $ hg qnew base.patch
  $ echo aaa > a
  $ echo bbb > b
  $ echo ccc > c
  $ hg add a b c
  $ hg qrefresh
  $ readlink.py a
  a -> a not a symlink


test replacing a file with a symlink

  $ hg qnew symlink.patch
  $ rm a
  $ ln -s b a
  $ hg qrefresh --git
  $ readlink.py a
  a -> b

  $ hg qpop
  popping symlink.patch
  now at: base.patch
  $ hg qpush
  applying symlink.patch
  now at: symlink.patch
  $ readlink.py a
  a -> b


test updating a symlink

  $ rm a
  $ ln -s c a
  $ hg qnew --git -f updatelink
  $ readlink.py a
  a -> c
  $ hg qpop
  popping updatelink
  now at: symlink.patch
  $ hg qpush --debug
  applying updatelink
  patching file a
  committing files:
  a
  committing manifest
  committing changelog
  updating the branch cache
  now at: updatelink
  $ readlink.py a
  a -> c
  $ hg st


test replacing a symlink with a file

  $ ln -s c s
  $ hg add s
  $ hg qnew --git -f addlink
  $ rm s
  $ echo sss > s
  $ hg qnew --git -f replacelinkwithfile
  $ hg qpop
  popping replacelinkwithfile
  now at: addlink
  $ hg qpush
  applying replacelinkwithfile
  now at: replacelinkwithfile
  $ cat s
  sss
  $ hg st


test symlink removal

  $ hg qnew removesl.patch
  $ hg rm a
  $ hg qrefresh --git
  $ hg qpop
  popping removesl.patch
  now at: replacelinkwithfile
  $ hg qpush
  applying removesl.patch
  now at: removesl.patch
  $ hg st -c
  C b
  C c
  C s

replace broken symlink with another broken symlink

  $ ln -s linka linka
  $ hg add linka
  $ hg qnew link
  $ hg mv linka linkb
  $ rm linkb
  $ ln -s linkb linkb
  $ hg qnew movelink
  $ hg qpop
  popping movelink
  now at: link
  $ hg qpush
  applying movelink
  now at: movelink
  $ readlink.py linkb
  linkb -> linkb