util: implement `writelines()` on atomictempfile
With typehints on the vfs objects, pytype will flag this:
FAILED: /mnt/c/Users/Matt/hg/.pytype/pyi/mercurial/patch.pyi
/usr/bin/python3.8 -m pytype.single
--imports_info /mnt/c/Users/Matt/hg/.pytype/imports/mercurial.patch.imports
--module-name mercurial.patch -V 3.7
-o /mnt/c/Users/Matt/hg/.pytype/pyi/mercurial/patch.pyi
--analyze-annotated --nofail --quick
/mnt/c/Users/Matt/hg/mercurial/patch.py
File "/mnt/c/Users/Matt/hg/mercurial/patch.py", line 535, in writerej:
No attribute 'writelines' on mercurial.util.atomictempfile [attribute-error]
In Union[
mercurial.util.atomictempfile,
mercurial.vfs.checkambigatclosing,
mercurial.vfs.delayclosedfile,
mercurial.windows.fdproxy,
mercurial.windows.mixedfilemodewrapper
]
It's not a real problem there (atomictempfile is only created by passing
different args), but it's reasonable for this to implement the function and
behave like a normal file. There are other functions missing that can be added
if/when needed.
typing: add basic type hints to localrepo.py
There's a lot more that could be done, but this sticks to the obviously correct
stuff that is either related to existing imports or primitives. Hopefully this
helps smoke out more path related bytes vs str issues in TortoiseHg.
I'm avoiding the interfaces for now, because they seem to confuse pytype and/or
PyCharm. It might be worth typing the return of `makelocalrepository` to
`localrepository`, but that leaks an implementation detail, so that can be
revisited later.
check-code: drop the check for whitespace around named parameters
This check flags py3 annotations of named parameters, because `black` adds
spaces around the assignment in this case. Since the chosen formatter has
opinions (and pylint also wants the space in the case of annotations), drop the
check so we can use py3 annotations.
rhg: add a config option to fall back immediately
This is useful for debugging the behavior of the "default" `hg` in tests
without having to manually substitute the fallback path.
rust-status: query fs traversal metadata lazily
Currently, any time the status algorithm needs to read a directory from the
filesystem (because the stat-only optimization is not available), it also
stats each directory entry eagerly.
Stat'ing the entries is only needed in a few cases (like when checking
the mtime of a directory for caching): this patch creates a wrapper struct
`DirEntry` that only stats the directory entry it represents when needed.
Excerpt of an `strace` before this change on Mozilla Central:
```
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
newfstatat(3, "", {st_mode=S_IFDIR|0755, st_size=3540, ...}, AT_EMPTY_PATH) = 0
getdents64(3, 0x
55dc970bd440 /* 139 entries */, 32768) = 5072
statx(3, ".hg", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFDIR|0755, stx_size=772, ...}) = 0
[... 135 other successful `statx` calls]
getdents64(3, 0x
55dc970bd440 /* 0 entries */, 32768) = 0
close(3) = 0
```
After this change:
```
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
newfstatat(3, "", {st_mode=S_IFDIR|0755, st_size=3540, ...}, AT_EMPTY_PATH) = 0
getdents64(3, 0x
561567c10190 /* 139 entries */, 32768) = 5072
getdents64(3, 0x
561567c10190 /* 0 entries */, 32768) = 0
close(3) = 0
```
rhg: stop shadowing `exit` function
This will be useful for the next patch which needs it.
config: add alias from `hg help rhg` to `hg help rust`
This will make using `rhg` more user-friendly and features more
discoverable.
rhg: add `config.rhg` helptext
This will make using `rhg` more user-friendly and features more
discoverable.
config: fix indentation of some`share-safe` options
This makes the output much more readable.