Mercurial > hg
annotate mercurial/cffi/mpatchbuild.py @ 52164:e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
This mirrors the Python `InnerRevlog` and will be used in a future patch
to replace said Python implementation. This allows us to start doing more
things in pure Rust, in particular reading and writing operations.
A lot of changes have to be introduced all at once, it wouldn't be very
useful to separate this patch IMO since all of them are either interlocked
or only useful with the rest.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 10 Oct 2024 10:34:51 +0200 |
parents | f4733654f144 |
children |
rev | line source |
---|---|
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
1 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
2 |
29871
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
3 import cffi |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
4 import os |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
5 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
6 ffi = cffi.FFI() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
7 mpatch_c = os.path.join( |
43668
53607fd3ec6c
cffi: fix build on Python 3
Manuel Jacob <me@manueljacob.de>
parents:
43077
diff
changeset
|
8 os.path.join(os.path.dirname(__file__), '..', 'mpatch.c') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
9 ) |
36948
0585337ea787
cleanup: fix some latent open(path).read() et al calls we previously missed
Augie Fackler <augie@google.com>
parents:
32506
diff
changeset
|
10 with open(mpatch_c) as f: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
11 ffi.set_source( |
43668
53607fd3ec6c
cffi: fix build on Python 3
Manuel Jacob <me@manueljacob.de>
parents:
43077
diff
changeset
|
12 "mercurial.cffi._mpatch", f.read(), include_dirs=["mercurial"] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
13 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
14 ffi.cdef( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
15 """ |
29871
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
16 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
17 struct mpatch_frag { |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
18 int start, end, len; |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
19 const char *data; |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
20 }; |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
21 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
22 struct mpatch_flist { |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
23 struct mpatch_frag *base, *head, *tail; |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
24 }; |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
25 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
26 extern "Python" struct mpatch_flist* cffi_get_next_item(void*, ssize_t); |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
27 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
28 int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist** res); |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
29 ssize_t mpatch_calcsize(size_t len, struct mpatch_flist *l); |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
30 void mpatch_lfree(struct mpatch_flist *a); |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
31 static int mpatch_apply(char *buf, const char *orig, size_t len, |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
32 struct mpatch_flist *l); |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
33 struct mpatch_flist *mpatch_fold(void *bins, |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
34 struct mpatch_flist* (*get_next_item)(void*, ssize_t), |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
35 ssize_t start, ssize_t end); |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
36 """ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36948
diff
changeset
|
37 ) |
29871
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
38 |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
39 if __name__ == '__main__': |
90af59b40d8a
mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff
changeset
|
40 ffi.compile() |