Commit Graph

4 Commits

Author SHA1 Message Date
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
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
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
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