##// END OF EJS Templates
posix: always seek to EOF when opening a file in append mode...
posix: always seek to EOF when opening a file in append mode Python 3 already does this, so skip it there. Consider the program: #include <stdio.h> int main() { FILE *f = fopen("narf", "w"); fprintf(f, "narf\n"); fclose(f); f = fopen("narf", "a"); printf("%ld\n", ftell(f)); fprintf(f, "troz\n"); printf("%ld\n", ftell(f)); return 0; } on macOS, FreeBSD, and Linux with glibc, this program prints 5 10 but on musl libc (Alpine Linux and probably others) this prints 0 10 By my reading of https://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html this is technically correct, specifically: > Opening a file with append mode (a as the first character in the > mode argument) shall cause all subsequent writes to the file to be > forced to the then current end-of-file, regardless of intervening > calls to fseek(). in other words, the file position doesn't really matter in append-mode files, and we can't depend on it being at all meaningful unless we perform a seek() before tell() after open(..., 'a'). Experimentally after a .write() we can do a .tell() and it'll always be reasonable, but I'm unclear from reading the specification if that's a smart thing to rely on. This matches what we do on Windows and what Python 3 does for free, so let's just be consistent. Thanks to Yuya for the idea.

File last commit:

r41272:44a51c1c default
r42778:97ada9b8 5.0.2 stable
Show More
test-narrow-expanddirstate.t
159 lines | 4.9 KiB | text/troff | Tads3Lexer
/ tests / test-narrow-expanddirstate.t
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 $ . "$TESTDIR/narrow-library.sh"
$ hg init master
$ cd master
$ mkdir inside
$ echo inside > inside/f1
$ mkdir outside
$ echo outside > outside/f2
$ mkdir patchdir
$ echo patch_this > patchdir/f3
$ hg ci -Aqm 'initial'
$ cd ..
$ hg clone --narrow ssh://user@dummy/master narrow --include inside
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
new changesets dff6a2a6d433
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd narrow
$ mkdir outside
$ echo other_contents > outside/f2
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg tracked | grep outside
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg files | grep outside
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
$ hg status
`hg status` did not add outside.
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg tracked | grep outside
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg files | grep outside
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Unfortunately this is not really a candidate for adding to narrowhg proper,
since it depends on some other source for providing the manifests (when using
treemanifests) and file contents. Something like a virtual filesystem and/or
remotefilelog. We want to be useful when not using those systems, so we do not
have this method available in narrowhg proper at the moment.
$ cat > "$TESTTMP/expand_extension.py" <<EOF
> import os
> import sys
>
Augie Fackler
tests: port extension in test-narrow-expanddirstate.t to Python 3...
r36365 > from mercurial import encoding
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > from mercurial import extensions
> from mercurial import localrepo
> from mercurial import match as matchmod
Gregory Szorc
narrowspec: move module into core...
r36178 > from mercurial import narrowspec
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > from mercurial import patch
> from mercurial import util as hgutil
>
Martin von Zweigbergk
tests: update narrowspec when narrowspec, not dirstate, is accessed...
r41069 > narrowspecexpanded = False
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > def expandnarrowspec(ui, repo, newincludes=None):
> if not newincludes:
> return
Martin von Zweigbergk
tests: update narrowspec when narrowspec, not dirstate, is accessed...
r41069 > if getattr(repo, '_narrowspecexpanded', False):
> return
> repo._narrowspecexpanded = True
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > import sys
> newincludes = set([newincludes])
> includes, excludes = repo.narrowpats
Gregory Szorc
narrowspec: move module into core...
r36178 > currentmatcher = narrowspec.match(repo.root, includes, excludes)
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > includes = includes | newincludes
> if not repo.currenttransaction():
Augie Fackler
tests: port extension in test-narrow-expanddirstate.t to Python 3...
r36365 > ui.develwarn(b'expandnarrowspec called outside of transaction!')
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > repo.setnarrowpats(includes, excludes)
Martin von Zweigbergk
narrow: move copytonarrowspec() out of setnarrowpats()...
r41272 > narrowspec.copytoworkingcopy(repo)
Gregory Szorc
narrowspec: move module into core...
r36178 > newmatcher = narrowspec.match(repo.root, includes, excludes)
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > added = matchmod.differencematcher(newmatcher, currentmatcher)
Augie Fackler
tests: port extension in test-narrow-expanddirstate.t to Python 3...
r36365 > for f in repo[b'.'].manifest().walk(added):
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > repo.dirstate.normallookup(f)
>
Martin von Zweigbergk
tests: update narrowspec when narrowspec, not dirstate, is accessed...
r41069 > def reposetup(ui, repo):
> class expandingrepo(repo.__class__):
> def narrowmatch(self, *args, **kwargs):
Kyle Lippincott
narrow: only wrap dirstate functions once, instead of per-reposetup...
r38142 > with repo.wlock(), repo.lock(), repo.transaction(
> b'expandnarrowspec'):
> expandnarrowspec(ui, repo,
> encoding.environ.get(b'DIRSTATEINCLUDES'))
Martin von Zweigbergk
tests: update narrowspec when narrowspec, not dirstate, is accessed...
r41069 > return super(expandingrepo, self).narrowmatch(*args, **kwargs)
Kyle Lippincott
narrow: only wrap dirstate functions once, instead of per-reposetup...
r38142 > repo.__class__ = expandingrepo
>
> def extsetup(unused_ui):
> def overridepatch(orig, ui, repo, *args, **kwargs):
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > with repo.wlock():
Augie Fackler
tests: port extension in test-narrow-expanddirstate.t to Python 3...
r36365 > expandnarrowspec(ui, repo, encoding.environ.get(b'PATCHINCLUDES'))
Kyle Lippincott
narrow: only wrap dirstate functions once, instead of per-reposetup...
r38142 > return orig(ui, repo, *args, **kwargs)
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 >
Augie Fackler
tests: port extension in test-narrow-expanddirstate.t to Python 3...
r36365 > extensions.wrapfunction(patch, b'patch', overridepatch)
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 > EOF
$ cat >> ".hg/hgrc" <<EOF
> [extensions]
> expand_extension = $TESTTMP/expand_extension.py
> EOF
Since we do not have the ability to rely on a virtual filesystem or
remotefilelog in the test, we just fake it by copying the data from the 'master'
repo.
$ cp -a ../master/.hg/store/data/* .hg/store/data
Do that for patchdir as well.
$ cp -a ../master/patchdir .
`hg status` will now add outside, but not patchdir.
$ DIRSTATEINCLUDES=path:outside hg status
M outside/f2
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg tracked | grep outside
I path:outside
$ hg files | grep outside > /dev/null
$ hg tracked | grep patchdir
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg files | grep patchdir
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Get rid of the modification to outside/f2.
$ hg update -C .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
This patch will not apply cleanly at the moment, so `hg import` will break
$ cat > "$TESTTMP/foo.patch" <<EOF
> --- patchdir/f3
> +++ patchdir/f3
> @@ -1,1 +1,1 @@
> -this should be "patch_this", but its not, so patch fails
> +this text is irrelevant
> EOF
$ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m ignored
applying $TESTTMP/foo.patch
patching file patchdir/f3
Hunk #1 FAILED at 0
1 out of 1 hunks FAILED -- saving rejects to file patchdir/f3.rej
abort: patch failed to apply
[255]
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg tracked | grep patchdir
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg files | grep patchdir > /dev/null
Augie Fackler
narrow: import experimental extension from narrowhg revision cb51d673e9c5...
r36096 [1]
Let's make it apply cleanly and see that it *did* expand properly
$ cat > "$TESTTMP/foo.patch" <<EOF
> --- patchdir/f3
> +++ patchdir/f3
> @@ -1,1 +1,1 @@
> -patch_this
> +patched_this
> EOF
$ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m message
applying $TESTTMP/foo.patch
$ cat patchdir/f3
patched_this
Martin von Zweigbergk
tests: avoid unnecessarily looking inside .hg/ in test-narrow*...
r38873 $ hg tracked | grep patchdir
I path:patchdir
$ hg files | grep patchdir > /dev/null