Commit Graph

11 Commits

Author SHA1 Message Date
Jun Wu
e0896400f5 linelog: make linelog build on Windows
Summary:
This diff disables or rewrites problematic parts in linelog code on Windows -
`mmap`, `ftruncate`, `sysconf`, `htonl` so the linelog module could be built
without on-disk linelog support. That means `absorb` can work. `fastannotate`
needs extra effort.

Test Plan:
`python setup.py install` and check in Python shell:

```
>>> import linelog
>>> linelog.linelog()
<open linelog (in-memory) at 0x3ab07bb5c8>
```

Also check the test pass:

```
fb-hgext\linelog\pyext>%PYTHONHOME%\python test-random-edits.py
```

Reviewers: #mercurial, ikostia

Reviewed By: ikostia

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5093192

Signature: t1:5093192:1495161776:06e05544cff808b03546f753a553ecc66fafc79f
2017-05-18 21:12:26 -07:00
Jun Wu
d8d7af1727 linelog.pyx: add wrappers for the new API getallines
Summary:
Add `getoffset`, `getallines` to make the new C API `linelog_getalllines`
usable.

Test Plan: This helps the future smartfixup extension to pass its tests

Reviewers: #mercurial, ttung, mitrandir

Reviewed By: mitrandir

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3716447

Signature: t1:3716447:1471262262:2ad8a547bf956c01e39be3383dc1a50751729c85
2016-08-15 12:45:58 +01:00
Jun Wu
b30c3ad0e5 linelog.pyx: fix copyfrom
Summary:
`copyfrom` does not work because `rhs.buf` is invisible to `self`. Adding
a `readonly` keyword fixes it. Also add some sanity checks and remove an
unnecessary `;`.

Test Plan: `make local` and confirm `copyfrom` works.

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3716444

Signature: t1:3716444:1471264420:1e58798222e1515ae6d5328ad6f2727cfe41cdb5
2016-08-15 12:43:44 +01:00
Jun Wu
3258b8586d linelog.pyx: run clear and annotate an empty linelog automatically
Summary:
A newly created empty `linelog` object is not usable (i.e.  calling
`annotate` or `replacelines` will raise an error) until `clear` is called.
And `replacelines` won't work until `annotate` is called. Therefore if we
know it's an empty linelog, just call `clear` and `annotate(0)` in
`__init__` to make it more friendly to use.

Test Plan:
`make local`, and confirm
`__import__('linelog').linelog().replacelines(1, 0, 0, 0, 1)` works.

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3716442

Signature: t1:3716442:1471262694:96370f5d3074bc0941e8ee780181c6b688cff79c
2016-08-15 12:41:13 +01:00
Jun Wu
8813967d50 linelog: add a test editing lines randomly
Summary:
The test will call "replacelines" with random arguments, keeps track of the
content of "lines" on its own. Then it compares its own "lines" with linelog's
annotateresult - should be the same. After that, it verifies the content of
old revisions can be retrieved by using "annotate" correctly.

Test Plan: Run this test

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3709431

Signature: t1:3709431:1471012434:68ca06c0b3b2705740375c32acac8012ded404a5
2016-08-12 15:22:16 +01:00
Jun Wu
e4089b5388 linelog: resolve compiler warnings
Summary:
This diff resolves some warnings when building on CentOS 6:

```
linelog/pyext/../linelog.c: In function 'replacelines':
linelog/pyext/../linelog.c:290: warning: unused variable 'result'
....
linelog/pyext/linelog.c: In function '__pyx_f_7linelog_11_filebuffer_resize':
linelog/pyext/linelog.c:3253: warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result
```

Test Plan:
Run `make local` with the linelog `setup.py` patch applied and make sure
there are no warnings.

Reviewers: #mercurial, rmcelroy, ttung

Reviewed By: rmcelroy

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3699378

Signature: t1:3699378:1470863807:10dc21033ab7301cb3d56e04de1c96f4d0287b6e
2016-08-10 22:18:59 +01:00
Jun Wu
9bc284757e linelog.pyx: implement the main linelog class
Summary:
Finally! This is the linelog class for CPython users. It has all linelog APIs
exposed but hides low-level details about `linelog_buf` and `annotateresult`.

It could use either `_memorybuffer` or `_filebuffer` as the underlying
`linelog_buf`. With `copyfrom`, it has the flexibility to exchange data
between disk and memory.

Test Plan: `cython linelog.pyx`

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3662882

Signature: t1:3662882:1470403425:c17bf2595edc88bc24e328524607f4ede6bbd2a5
2016-08-10 21:17:21 +01:00
Jun Wu
c14c36aa26 linelog.pyx: implement file buffer
Summary: The file buffer uses `mmap` for `linelog_buf::data`.

Test Plan: `cython2 linelog.pyx`

Reviewers: #mercurial, rmcelroy, ttung

Reviewed By: rmcelroy

Subscribers: rmcelroy, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3662790

Signature: t1:3662790:1470860125:b68fc5e3ed14d56fbebe8a7de81ad7f67a622875
2016-08-10 21:15:43 +01:00
Jun Wu
97079280bf linelog.pyx: implement memory buffer
Summary:
The memory buffer implements `_buffer.resize` using `realloc`,
making linelog useful for in-memory modifications. For example,
the `smartfixup` extension (D3264203) would use an in-memory
linelog to avoid expensive merge operations and possible merge
conflicts.

Test Plan: `cython2 linelog.pyx`

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3655491

Tasks: 11291522

Signature: t1:3655491:1470402602:891fade362c8e0f6a3af64f1fbdfa0fbf556e68b
2016-08-10 18:54:55 +01:00
Jun Wu
a4dd17d71c linelog.pyx: add a thin wrapper around linelog_buf
Summary:
The thin wrapper defines common APIs like `resize` `flush`, `close`, and
`copyfrom`. Some of them are used in sub-classes. It also handles
`LINELOG_RESULT_ENEEDRESIZE` and raise `LinelogError` for other errors.

Test Plan: `cython2 linelog.pyx`

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3655463

Tasks: 11291522

Signature: t1:3655463:1470402560:75e552ed3d6205ae45812d1cdfe7bc14cfb1eec3
2016-08-02 13:40:27 +01:00
Jun Wu
ce97ea9aaf linelog.pyx: declare linelog functions
Summary:
`linelog.pyx` is meant to be the CPython wrapper for linelog.

This diff declares types and functions in `linelog.h`.

According to http://docs.cython.org/en/latest/src/userguide/external_C_code.html,
we have to duplicate them as Cython cannot parse `.h` files.

Test Plan: `cython2 linelog.pyx`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3655437

Tasks: 11291522

Signature: t1:3655437:1470336663:802ede2b82790a6c901ba0cc76c4f39fcac1e6ac
2016-08-02 13:21:08 +01:00