Commit Graph

30 Commits

Author SHA1 Message Date
Jun Wu
a3b1512f7f linelog: add some text about differences with revlog in README
Summary:
This could help people understand what's different essentially, and make better
decision on what to use.

Test Plan: Seems the vim spell checker is happy.

Reviewers: #sourcecontrol, rmcelroy, stash

Reviewed By: rmcelroy, stash

Subscribers: mjpieters

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

Signature: t1:4203039:1479461745:9cce0239088707bd8b66055ba66c420e97a3bd03
2016-11-18 02:34:06 +00:00
Jun Wu
e2e852370f linelogcli: add new command getalllines
Summary:
Since linelog has the new `getalllines` API, add a corresponding command
to support it.

Test Plan:
```
$ make && ./linelogcli /tmp/lll init annotate 0 replacelines 1 0:0 0:3 \
  replacelines 2 1:2 1:3 getalllines 0:0
init: okay
annotate: run annotate for rev 0
annotate: 0 lines, endoffset 1
replacelines: rev 1, lines 0:0 -> 0:3
replacelines: rev 2, lines 1:2 -> 1:3
getalllines: 5 lines
  0: rev 1, line 0, offset 3
  1: rev 2, line 1, offset 8
  2: rev 2, line 2, offset 9
  3: rev 1, line 1, offset 11
  4: rev 1, line 2, offset 5
```

Reviewers: #mercurial, simonfar, ttung

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3716453:1471265279:a8f625660ef47ca341ca8f5c4c7370b56277cef8
2016-08-15 12:47:14 +01: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
2c9fffd80e linelog: add a new API getalllines
Summary:
The current linelog APIs are designed purely for the "annotate" operation.
It only supports getting lines from one single revisions, which is what
`annotate` does.

However the data structure is also useful to provide lines from different
revisions. Say if you want to know all lines from all revisions for a given
function. Or if you want to confirm if a chunk is "continuous" - nobody
inserts new lines among them. This diff adds the missing API, `getalllines`.

It returns information about all lines the linelog tracks. The caller could
provide an optional interval to limit the lines returned.

Its parameters use low-level raw offsets instead of line numbers, because it
gives the caller more control. The API don't need to handle open or close
interval issues that line numbers may have (see the previous diff about
deletion blocks).

This makes `lineinfo.offset` no longer internal-only - we have exposed the
offset concept to the API parameters. Therefore the comments are updated.

This also requires a clear way to distinguish unconditional jumps from
conditional one. We use `JGE 0` as unconditional jumps. To ensure this,
make `replacelines` reject 0 revision.

Test Plan: `cd linelog && make`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3716439:1471265245:5a4b2f585284cba71ca3907c8e8826b2b00a4b49
2016-08-15 12:31:29 +01:00
Jun Wu
c5819e914f linelog: extract appendline logic from annotate
Summary:
The `appendline` logic is used twice in `annotate`: inside and outside the
`for` loop. It will be used again in the following changes. Therefore make
it an inline function.

Test Plan: `cd linelog && make`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3716438:1471263197:6add9cfc0a9d712258dd2da332aaf306cb1af71a
2016-08-15 12:14:07 +01:00
Jun Wu
b48ea46da6 linelog: be conservative when deleting a chunk from an old revision
Summary:
This is a subtle change. Consider the following case, where revision 1 has 3
lines and revision 2 has 1 line inserted between the second and the third
lines of revision 1:

  0: +---- INSERTED BY REV 1
     |                          --+             --+
  1: |     LINE REV=1 LINENUM=0   | DEL BLOCK A   | DEL BLOCK B
  2: |     LINE REV=1 LINENUM=1   |               |
     |                          --+               |
  3: | +-- INSERTED BY REV 2                      |
  4: | |   LINE REV=2 LINENUM=2                   |
     | +--                                      --+
  5: |     LINE REV=1 LINENUM=2
     +----

Now what if the user has run `annotate(rev=1)` and wants to delete the first 2
lines, by calling `replacelines(a1=0, a2=2, ...)`?

The current code would use "DEL BLOCK B", which is more efficient because
the block contains more instructions, and more simple because it is just a
JGE to the a2 address.

While that works fine for the "appending" case (always edit new revisions),
it deletes future lines between the second and third line (in this case,
"LINE REV=2 LINENUM=2"). This is undesired by some users, namely smartfixup.

Surely we can add a boolean flag to the `replacelines` API to decide whether
A or B will be used. But that is too low-level and `replacelines` already
has too many parameters. Today we don't see other requirements to choose
between them precisely. Therefore, just change the default behavior, when
deleting chunks from old revisions to "DEL BLOCK A".

Test Plan: This change is needed to help pass the future smartfixup tests

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3716435:1471262664:0ae40d95d6389db733a88d9fafe19962d9166e35
2016-08-15 12:08:06 +01:00
Jun Wu
0d3a392454 hgignore: ignore linelog non-source files
Summary: This diff adds an `.hgignore` file for the `linelog` directory.

Test Plan: `make local`, and run `hg status`, make sure no unwanted files are printed.

Reviewers: #mercurial, ttung, akushner

Reviewed By: akushner

Subscribers: mjpieters

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

Signature: t1:3699575:1471151389:7e4de7b75d671d3f0db18337e57c65e9972de059
2016-08-10 22:32:21 +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
47b43030bc linelog: be compatible with gcc 4.4
Summary:
It's "Unnamed unions", a C11 feature.

Although it improves the code readability a bit, gcc 4.4 does not have a
complete for it. Since we have to support gcc 4.4 now, use plain `struct`
instead.

Test Plan: Run `cd linelog && make local` using gcc 4.4

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

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

Signature: t1:3699216:1470862720:85ee1c4f8c63805aeffca1048ff330b91a096222
2016-08-10 22:02:24 +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
ceeb7ccfb8 linelogcli: add code for fuzz testing
Summary:
This diff adds a check: after `linelog_updatelines`, `annotateresult *ar`
should be updated as if we have called a separate `linelog_annotate`.

Test Plan:
Run `afl` for a while and make sure it does not find any crashes:

```
mkdir ./testdir
CC=afl-gcc make
./linelogcli ./testdir/readme init annotate 0 replacelines 10 0:0 0:3 replacelines 20 2:2 1:3 replacelines 30 1:3 1000:1000
afl-fuzz -i testdir -o findingdir ./linelogcli @@ dump annotate 10 replacelines 10 0:0 0:3 replacelines 20 2:2 1:3 replacelines 30 1:3 1000:1000
```

Reviewers: #mercurial, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3650197:1470336333:2f5e6d2e914917b33bddc595344d2a0b98067606
2016-07-30 12:59:48 +01:00
Jun Wu
be85f6a51b linelog: add a boundary check about annotateresult
Summary:
Previously, `replacelines` assume the `annotateresult` user passed has the
property: `linecount < maxlinecount`. But that's not true after
`linelog_annotateresult_clear`, where `linecount = maxlinecount = 0` and
that leads to `SIGSEGV` if both `a1` and `a2` passed to `replacelines` are `0`.

This issue was found by the following `afl` testcase:

  ./linelogcli ./testdir/readme init annotate 0 replacelines 10 0:0 0:3 replacelines 20 2:2 1:3 replacelines 30 1:3 1000:1000
  afl-fuzz -i testdir -o findingdir ./linelogcli @@ dump annotate 10 replacelines 10 0:0 0:3 replacelines 20 2:2 1:3 replacelines 30 1:3 1000:1000

Test Plan:
Run the above `afl` test. Make sure it won't report a crash in a couple
of minutes.

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

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

Signature: t1:3676049:1470661720:e5c4d6f45ac51d58fae856b08f79982bec44b535
2016-08-05 17:55:46 +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
Jun Wu
c1e8b25355 linelogcli: a simple CLI tool for linelog
Summary:
The `linelogcli` tool exposes linelog APIs to command line:

  - `linelogcli file init`: create a linelog file
  - `linelogcli file annotate rev`: run annotate
  - `linelogcli file replacelines rev a1:a2 b1:b2`: replace lines
  - `linelogcli file info`: show maxrev and buffer size
  - `linelogcli file dump`: dump human-readable instructions

It's designed for (fuzz) testing, memory leak checking. It's also
a basic tool for developers to investigate a linelog file.

It's not designed for end users and we will have a separate Python wrapper
implemented in Cython for mercurial integration. Therefore reviewers are
recommended to be less strict for this implementation.

Test Plan:
`make` and test some basic operations:

```
$ ./linelogcli /tmp/foo init annotate 0 replacelines 1 0:0 0:4 annotate - replacelines 2 1:2 10:13 annotate - replacelines 3 2:6 20:22 annotate - replacelines 4 0:4 30:31 annotate - annotate 2 info dump
init: okay
annotate: run annotate for rev 0
annotate: 0 lines, endoffset 1
replacelines: rev 1, lines 0:0 -> 0:4
annotate: 4 lines, endoffset 7
  0: rev 1, ln 0, offset 3
  1: rev 1, ln 1, offset 4
  2: rev 1, ln 2, offset 5
  3: rev 1, ln 3, offset 6
replacelines: rev 2, lines 1:2 -> 10:13
annotate: 6 lines, endoffset 7
  0: rev 1, ln 0, offset 3
  1: rev 2, ln 10, offset 9
  2: rev 2, ln 11, offset 10
  3: rev 2, ln 12, offset 11
  4: rev 1, ln 2, offset 5
  5: rev 1, ln 3, offset 6
replacelines: rev 3, lines 2:6 -> 20:22
annotate: 4 lines, endoffset 7
  0: rev 1, ln 0, offset 3
  1: rev 2, ln 10, offset 9
  2: rev 3, ln 20, offset 16
  3: rev 3, ln 21, offset 17
replacelines: rev 4, lines 0:4 -> 30:31
annotate: 1 lines, endoffset 7
  0: rev 4, ln 30, offset 22
annotate: run annotate for rev 2
annotate: 6 lines, endoffset 7
  0: rev 1, ln 0, offset 24
  1: rev 2, ln 10, offset 9
  2: rev 2, ln 11, offset 19
  3: rev 2, ln 12, offset 11
  4: rev 1, ln 2, offset 5
  5: rev 1, ln 3, offset 6
info: maxrev = 4, size = 208
dump:
       1: J          2
       2: JL       1 7
       3: J          21
       4: J          8
       5: LINE     1 2
       6: LINE     1 3
       7: END
       8: JL       2 12
       9: LINE     2 10
      10: J          15
      11: LINE     2 12
      12: JGE      2 5
      13: LINE     1 1
      14: J          5
      15: JL       3 18
      16: LINE     3 20
      17: LINE     3 21
      18: JGE      3 7
      19: LINE     2 11
      20: J          11
      21: JL       4 23
      22: LINE     4 30
      23: JGE      4 7
      24: LINE     1 0
      25: J          4
```

Also run with `valgrind  --tool=memcheck --leak-check=yes` to make sure there is no memory leak.

Reviewers: #mercurial, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Signature: t1:3645102:1470335856:860a7dbb1781f6fe1e11e235ad163e2fbb6d45b2
2016-07-30 12:59:17 +01:00
Jun Wu
6ec93f77f1 linelog: implement linelog_replacelines
Summary: This is the core API to do writes.

Test Plan: `gcc -Wall -Wextra -Wconversion -c linelog.c`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3641637:1470335236:758df55835ac6c42212783d4cc12302588ce2216
2016-07-29 13:43:55 +01:00
Jun Wu
978c03ef18 linelog: implement linelog_annotate
Summary:
Implement `linelog_annotate`, which is the core algorithm for generating
`linelog_annotateresult`. It is basically walking though and executing
the instructions.

Test Plan: `gcc -Wall -Wextra -Wconversion -c linelog.c`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3629591:1470157936:764bb7c5d1208e73d93d26063a8ad380dbceb495
2016-07-27 19:37:41 +01:00
Jun Wu
28e914db8e linelog: implement trivial APIs
Summary: Implement the trivial APIs declared in D3628681.

Test Plan:
`gcc -Wall -Wextra -Wconversion -c linelog.c` and it only reports
"defined but not used" warnings.

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3629389:1470087604:5b5a536630a6866df52d51fd163ed8f5301c734b
2016-07-27 19:25:31 +01:00
Jun Wu
a84fdfb62a linelog: add a helper function to resize linelog_annotateresult.lines
Summary:
As mentioned in D3628571, the `.c` code manages the memory of
`linelog_annotateresult.lines`. We need a resize function for it.

Test Plan:
`gcc -Wall -Wextra -Wconversion -c linelog.c` and it only reports
"defined but not used" warnings.

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3629350:1470055356:01993a6df2ccd849ed01961eb996c86bb0a17c78
2016-07-27 19:16:03 +01:00
Jun Wu
ac5824243b linelog: add types and helpers for internal linelog instruction structure
Summary:
As described in the README (D3628440), the linelog buffer is an array of
instructions. The `.h` file only declares the plain buffer but not the
internal representation of the instruction. They are intended to be
invisible to users.

This diff declares the instruction structure, related types and helpers in
`linelog.c`. `decode` and `encode` translate between the internal (`.c`,
structured `linelog_inst`) and the external (`.h`, plain `linelog_buf`)
representation. Other macros are to help making code shorter and easier to
understand.

Test Plan: `gcc -Wall -Wextra -Wconversion -c linelog.c`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Signature: t1:3629132:1470157631:4523c53a3af28061828980845d3acfbd82c58361
2016-07-27 19:31:59 +01:00
Jun Wu
f918aa6566 linelog: declare core APIs
Summary:
Declare core APIs for linelog:
- `annotate`, the "read" part
- `replacelines`, the "write" part

As mentioned in D3334518, this is part of a rewrite of D3334518.
These 2 APIs are the only ones involving core logic of the linelog structure.

Test Plan: `gcc -Wall -Wextra -Wconversion linelog.h`

Reviewers: #mercurial, zamsden, ttung, simonfar

Reviewed By: simonfar

Subscribers: akushner, zamsden, simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3628848:1470080022:1f434d998c0bf63a494f70d47bc6a6fc05954446
2016-07-29 00:49:38 +01:00
Jun Wu
d268bb5675 linelog: declare trivial APIs
Summary:
Declare some trivial APIs, which either clear the memory or return a value
without much calculation.

Test Plan: `gcc -Wall -Wextra linelog.h`

Reviewers: #mercurial, simonfar, ttung

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3628681:1469647679:437db1610dec8a21a71b2d94c64d6d085321e1cd
2016-07-27 17:54:07 +01:00
Jun Wu
4f76b602eb linelog: declare data structures
Summary:
Add essential data structures for upcoming APIs.

This is part of a rewrite of D3334518. The new API removes everything about
I/O (aka. `stdio.h`) and makes it the caller's responsibility to prepare
(`malloc` or `mmap`) and resize the memory buffer.

This makes it possible to have a much shorter (thus easier to review) code
more dedicated to core algorithm, as the following are no longer necessary:

- I/O related APIs: `open`, `close`, `flush`, `saveas`
- I/O error handling

The error handling part is also changed that we now can use integer error
numbers instead of a boolean value + an error string.

Test Plan: `gcc -Wall -Wextra linelog.h`

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: durham, simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3628571:1469643667:4fbf4fd7e624820ee6d8409e2067c8bd0e99a829
2016-07-27 17:39:20 +01:00
Jun Wu
68e5a15af7 linelog: add a README explaining the file format
Summary: This should help reviewers.

Test Plan: Run some spell checkers.

Reviewers: #mercurial, simonfar, ttung

Reviewed By: simonfar

Subscribers: mpm, akushner, ikostia, simonfar, mjpieters

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

Tasks: 12416202

Signature: t1:3628440:1469640270:a44f682e22b59615d0d9f12c93417c905b035ab6
2016-07-27 17:12:15 +01:00
Jun Wu
6fa80e5cca linelog: add empty source files
Summary: Add (almost) empty `.c` and `.h` files with uninteresting headers.

Test Plan: Code review

Reviewers: #mercurial, mitrandir, ttung

Reviewed By: mitrandir

Subscribers: mjpieters

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

Tasks: 12416202

Signature: t1:3620623:1469560977:d05a2781499783a2238f602025e6765ad52c6f00
2016-07-26 16:58:19 +01:00