tests/test-custom-filters.t
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 07 Mar 2024 04:15:23 +0100
changeset 51536 718f28ea3af4
parent 49621 55c6ebd11cb9
permissions -rw-r--r--
branchcache: add a "pure topological head" fast path In a narrow but actually quick common case, all topological heads are all on the same branch and all open. In this case, computing the branch map is very simple. We can quickly detect situation where this situation will not change. So we update the V3 format to be able to express this situation and upgrade the update code to detect we remains in that mode. The branch cache is populated with the actual value when the branch map is accessed, but the update_disk method can do the update without needing to populate it.

  $ hg init repo
  $ cd repo

  $ cat > .hg/hgrc <<EOF
  > [extensions]
  > prefixfilter = prefix.py
  > [encode]
  > *.txt = stripprefix: Copyright 2046, The Masters
  > [decode]
  > *.txt = insertprefix: Copyright 2046, The Masters
  > EOF

  $ cat > prefix.py <<EOF
  > from mercurial import error
  > def stripprefix(s, cmd, filename, **kwargs):
  >     header = b'%s\n' % cmd
  >     if s[:len(header)] != header:
  >         raise error.Abort(b'missing header "%s" in %s' % (cmd, filename))
  >     return s[len(header):]
  > def insertprefix(s, cmd):
  >     return b'%s\n%s' % (cmd, s)
  > def reposetup(ui, repo):
  >     repo.adddatafilter(b'stripprefix:', stripprefix)
  >     repo.adddatafilter(b'insertprefix:', insertprefix)
  > EOF

  $ cat > .hgignore <<EOF
  > .hgignore
  > prefix.py
  > prefix.pyc
  > __pycache__/
  > EOF

  $ cat > stuff.txt <<EOF
  > Copyright 2046, The Masters
  > Some stuff to ponder very carefully.
  > EOF
  $ hg add stuff.txt
  $ hg ci -m stuff

Repository data:

  $ hg cat stuff.txt
  Some stuff to ponder very carefully.

Fresh checkout:

  $ rm stuff.txt
  $ hg up -C
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cat stuff.txt
  Copyright 2046, The Masters
  Some stuff to ponder very carefully.
  $ echo "Very very carefully." >> stuff.txt
  $ hg stat
  M stuff.txt

  $ echo "Unauthorized material subject to destruction." > morestuff.txt

Problem encoding:

  $ hg add morestuff.txt
  $ hg ci -m morestuff
  abort: missing header "Copyright 2046, The Masters" in morestuff.txt
  [255]
  $ hg stat
  M stuff.txt
  A morestuff.txt