This is useful for large files that are only partly touched.
Details
- Reviewers
quark durin42 - Group Reviewers
Restricted Project hg-reviewers - Commits
- rHG3bb2a9f25fe9: util: add an mmapread method
Will be used and tested in a later patch.
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
mercurial/util.py | ||
---|---|---|
413 | Some consumers may want file like objects. Others may want buffers. Whatever you do, I would rename the function to what it actually does. e.g. `mmapfd or mmapbuffer`. |
mercurial/util.py | ||
---|---|---|
413 | I think we can take both: fd = getattr(fp, 'fileno', lambda: fp)() ... A lot of Python stdlib function accepts both fd and fp. |
Scanning staling patches - I think this patch is good after making fd work with both file object and file descriptor number.
I will fix it in-place if you don't get it on Wednesday.
Either this or D477 needs updating per the comment I made there. I'm just too nervous about the potential for silent mysterious changelog read failures here.
As it stands, mmap.mmap only raises ValueError if the arguments are incorrect or if the file is zero-length. But since that's not guaranteed, I've added a check that the reason for the exception is that the file is zero length before returning the empty string.
As per comment on D477 - do we want this to be raw, or buffer(mmap.mmap(...?