##// 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:

r41032:6f2510b5 default
r42778:97ada9b8 5.0.2 stable
Show More
test-extension-timing.t
100 lines | 4.1 KiB | text/troff | Tads3Lexer
/ tests / test-extension-timing.t
Boris Feld
extensions: add timing for extensions reposetup...
r39543 Test basic extension support
$ cat > foobar.py <<EOF
> import os
> from mercurial import commands, registrar
> cmdtable = {}
> command = registrar.command(cmdtable)
> configtable = {}
> configitem = registrar.configitem(configtable)
> configitem(b'tests', b'foo', default=b"Foo")
> def uisetup(ui):
> ui.debug(b"uisetup called [debug]\\n")
> ui.write(b"uisetup called\\n")
> ui.status(b"uisetup called [status]\\n")
> ui.flush()
> def reposetup(ui, repo):
> ui.write(b"reposetup called for %s\\n" % os.path.basename(repo.root))
> ui.write(b"ui %s= repo.ui\\n" % (ui == repo.ui and b"=" or b"!"))
> ui.flush()
> @command(b'foo', [], b'hg foo')
> def foo(ui, *args, **kwargs):
> foo = ui.config(b'tests', b'foo')
> ui.write(foo)
> ui.write(b"\\n")
> @command(b'bar', [], b'hg bar', norepo=True)
> def bar(ui, *args, **kwargs):
> ui.write(b"Bar\\n")
> EOF
$ abspath=`pwd`/foobar.py
$ mkdir barfoo
$ cp foobar.py barfoo/__init__.py
$ barfoopath=`pwd`/barfoo
$ hg init a
$ cd a
$ echo foo > file
$ hg add file
$ hg commit -m 'add file'
$ echo '[extensions]' >> $HGRCPATH
$ echo "foobar = $abspath" >> $HGRCPATH
Yuya Nishihara
extensions: use ui.log() interface to provide detailed loading information...
r41032 $ filterlog () {
> sed -e 's!^[0-9/]* [0-9:]* ([0-9]*)>!YYYY/MM/DD HH:MM:SS (PID)>!'
> }
Boris Feld
extensions: add timing for extensions reposetup...
r39543 Test extension setup timings
Yuya Nishihara
extensions: use ui.log() interface to provide detailed loading information...
r41032 $ hg foo --traceback --config devel.debug.extensions=yes --debug 2>&1 | filterlog
YYYY/MM/DD HH:MM:SS (PID)> loading extensions
YYYY/MM/DD HH:MM:SS (PID)> - processing 1 entries
YYYY/MM/DD HH:MM:SS (PID)> - loading extension: foobar
YYYY/MM/DD HH:MM:SS (PID)> > foobar extension loaded in * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - validating extension tables: foobar
YYYY/MM/DD HH:MM:SS (PID)> - invoking registered callbacks: foobar
YYYY/MM/DD HH:MM:SS (PID)> > callbacks completed in * (glob)
YYYY/MM/DD HH:MM:SS (PID)> > loaded 1 extensions, total time * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - loading configtable attributes
YYYY/MM/DD HH:MM:SS (PID)> - executing uisetup hooks
YYYY/MM/DD HH:MM:SS (PID)> - running uisetup for foobar
Boris Feld
extensions: add timing for extensions reposetup...
r39543 uisetup called [debug]
uisetup called
uisetup called [status]
Yuya Nishihara
extensions: use ui.log() interface to provide detailed loading information...
r41032 YYYY/MM/DD HH:MM:SS (PID)> > uisetup for foobar took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> > all uisetup took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - executing extsetup hooks
YYYY/MM/DD HH:MM:SS (PID)> - running extsetup for foobar
YYYY/MM/DD HH:MM:SS (PID)> > extsetup for foobar took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> > all extsetup took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - executing remaining aftercallbacks
YYYY/MM/DD HH:MM:SS (PID)> > remaining aftercallbacks completed in * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - loading extension registration objects
YYYY/MM/DD HH:MM:SS (PID)> > extension registration object loading took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> > extension foobar take a total of * to load (glob)
YYYY/MM/DD HH:MM:SS (PID)> extension loading complete
YYYY/MM/DD HH:MM:SS (PID)> loading additional extensions
YYYY/MM/DD HH:MM:SS (PID)> - processing 1 entries
YYYY/MM/DD HH:MM:SS (PID)> > loaded 0 extensions, total time * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - loading configtable attributes
YYYY/MM/DD HH:MM:SS (PID)> - executing uisetup hooks
YYYY/MM/DD HH:MM:SS (PID)> > all uisetup took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - executing extsetup hooks
YYYY/MM/DD HH:MM:SS (PID)> > all extsetup took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - executing remaining aftercallbacks
YYYY/MM/DD HH:MM:SS (PID)> > remaining aftercallbacks completed in * (glob)
YYYY/MM/DD HH:MM:SS (PID)> - loading extension registration objects
YYYY/MM/DD HH:MM:SS (PID)> > extension registration object loading took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> extension loading complete
YYYY/MM/DD HH:MM:SS (PID)> - executing reposetup hooks
YYYY/MM/DD HH:MM:SS (PID)> - running reposetup for foobar
Boris Feld
extensions: add timing for extensions reposetup...
r39543 reposetup called for a
ui == repo.ui
Yuya Nishihara
extensions: use ui.log() interface to provide detailed loading information...
r41032 YYYY/MM/DD HH:MM:SS (PID)> > reposetup for foobar took * (glob)
YYYY/MM/DD HH:MM:SS (PID)> > all reposetup took * (glob)
Boris Feld
extensions: add timing for extensions reposetup...
r39543 Foo
$ cd ..
$ echo 'foobar = !' >> $HGRCPATH