Mercurial > hg
diff mercurial/narrowspec.py @ 50186:8bc14ac53a41
narrow: delegate the narrow spec writing to the transaction
This make it more transactional and will help us to simplify their backup.
The implementation is not great, but it keep the patch simple as this is not the
time for a larger refactoring yet.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 23 Feb 2023 04:15:16 +0100 |
parents | 99296ca9f29e |
children | f18e4608bb61 |
line wrap: on
line diff
--- a/mercurial/narrowspec.py Thu Feb 23 04:02:38 2023 +0100 +++ b/mercurial/narrowspec.py Thu Feb 23 04:15:16 2023 +0100 @@ -5,6 +5,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +import weakref from .i18n import _ from .pycompat import getattr @@ -174,10 +175,40 @@ def save(repo, includepats, excludepats): + repo = repo.unfiltered() + validatepatterns(includepats) validatepatterns(excludepats) spec = format(includepats, excludepats) - repo.svfs.write(FILENAME, spec) + + tr = repo.currenttransaction() + if tr is None: + repo.svfs.write(FILENAME, spec) + else: + # the roundtrip is sometime different + # not taking any chance for now + value = parseconfig(repo.ui, spec) + reporef = weakref.ref(repo) + + def clean_pending(tr): + r = reporef() + if r is not None: + r._pending_narrow_pats = None + + tr.addpostclose(b'narrow-spec', clean_pending) + tr.addabort(b'narrow-spec', clean_pending) + repo._pending_narrow_pats = value + + def write_spec(f): + f.write(spec) + + tr.addfilegenerator( + # XXX think about order at some point + b"narrow-spec", + (FILENAME,), + write_spec, + location=b'store', + ) def copytoworkingcopy(repo):