simple-rcs 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. simple_rcs-0.1.0/LICENSE +201 -0
  2. simple_rcs-0.1.0/MANIFEST.in +8 -0
  3. simple_rcs-0.1.0/PKG-INFO +261 -0
  4. simple_rcs-0.1.0/README.md +238 -0
  5. simple_rcs-0.1.0/pyproject.toml +98 -0
  6. simple_rcs-0.1.0/setup.cfg +4 -0
  7. simple_rcs-0.1.0/setup.py +49 -0
  8. simple_rcs-0.1.0/simple_rcs/__init__.py +10 -0
  9. simple_rcs-0.1.0/simple_rcs/_myersdiff_dmp.pyx +235 -0
  10. simple_rcs-0.1.0/simple_rcs/_myersdiff_ses.pyx +255 -0
  11. simple_rcs-0.1.0/simple_rcs/adapters.py +76 -0
  12. simple_rcs-0.1.0/simple_rcs/codec.py +85 -0
  13. simple_rcs-0.1.0/simple_rcs/matchers.py +148 -0
  14. simple_rcs-0.1.0/simple_rcs/myersdiff.py +460 -0
  15. simple_rcs-0.1.0/simple_rcs/myersdiff_dmp.py +259 -0
  16. simple_rcs-0.1.0/simple_rcs/myersdiff_ses.py +510 -0
  17. simple_rcs-0.1.0/simple_rcs/pybsdiff.py +411 -0
  18. simple_rcs-0.1.0/simple_rcs/pydifflib.py +1108 -0
  19. simple_rcs-0.1.0/simple_rcs/simple_rcs.py +1849 -0
  20. simple_rcs-0.1.0/simple_rcs/simple_rcs_gpg.py +210 -0
  21. simple_rcs-0.1.0/simple_rcs.egg-info/PKG-INFO +261 -0
  22. simple_rcs-0.1.0/simple_rcs.egg-info/SOURCES.txt +34 -0
  23. simple_rcs-0.1.0/simple_rcs.egg-info/dependency_links.txt +1 -0
  24. simple_rcs-0.1.0/simple_rcs.egg-info/top_level.txt +1 -0
  25. simple_rcs-0.1.0/tests/unit_tests/test_adapters.py +124 -0
  26. simple_rcs-0.1.0/tests/unit_tests/test_binary_roundtrip.py +338 -0
  27. simple_rcs-0.1.0/tests/unit_tests/test_matchers.py +135 -0
  28. simple_rcs-0.1.0/tests/unit_tests/test_metadata_only.py +498 -0
  29. simple_rcs-0.1.0/tests/unit_tests/test_pybsdiff.py +59 -0
  30. simple_rcs-0.1.0/tests/unit_tests/test_pybsdiff_compat.py +148 -0
  31. simple_rcs-0.1.0/tests/unit_tests/test_pybsdiff_realistic.py +185 -0
  32. simple_rcs-0.1.0/tests/unit_tests/test_pybsdiff_simple_compat.py +101 -0
  33. simple_rcs-0.1.0/tests/unit_tests/test_pydifflib.py +184 -0
  34. simple_rcs-0.1.0/tests/unit_tests/test_pydifflib_benchmark.py +147 -0
  35. simple_rcs-0.1.0/tests/unit_tests/test_simple_rcs.py +257 -0
  36. simple_rcs-0.1.0/tests/unit_tests/test_v1_format.py +97 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ # Cython sources ship; the .c files it generates do not. They are build
2
+ # byproducts, present only in a working tree that has already built once, so
3
+ # including them would make the sdist differ between a local build and a clean
4
+ # CI checkout -- and a stale .c silently shadowing an edited .pyx is worse.
5
+ global-exclude *.c
6
+ global-exclude *.so
7
+
8
+ recursive-include tests *.py
@@ -0,0 +1,261 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple_rcs
3
+ Version: 0.1.0
4
+ Summary: Dependency-free reverse-delta version control for single files, with an RCS-inspired plain-text format, a hash chain, and optional GPG signatures
5
+ Author-email: Won-Kyu Park <wkpark@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/wkpark/SimpleRCS
8
+ Project-URL: Documentation, https://github.com/wkpark/SimpleRCS/wiki
9
+ Project-URL: Issues, https://github.com/wkpark/SimpleRCS/issues
10
+ Keywords: rcs,version-control,delta,diff,bsdiff,revision,history
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Version Control
18
+ Classifier: Topic :: System :: Archiving
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # SimpleRCS
25
+
26
+ **SimpleRCS** is a custom-designed, stream-based version control system for
27
+ ultra-lightweight management of a single document. It borrows the reverse-delta
28
+ storage idea from classic RCS and rebuilds it around modern performance
29
+ considerations — stream-centric I/O, O(1) HEAD access, backward-scanning
30
+ history traversal — for cases where Git's object model is overkill, or where
31
+ direct file-system/database blob integration is preferred.
32
+
33
+ It operates on a file-like object (`BinaryIO`): an on-disk path, an in-memory
34
+ `BytesIO`, or an externally-owned handle all work the same way.
35
+
36
+ ## Key Features
37
+
38
+ - **Reverse delta storage.** The latest version (HEAD) is always stored as
39
+ full text at the end of the stream; every older version is a reverse delta
40
+ (instructions to turn version *N+1* back into version *N*). HEAD reads are
41
+ O(1); historical reads are O(k), where k is the distance from HEAD.
42
+ - **Append-dominant writes.** Committing overwrites only the previous HEAD
43
+ block (full text → delta) and appends the new HEAD. No full-history
44
+ rewrite, ever.
45
+ - **Backward-scanning, stream-centric I/O.** History is located by scanning
46
+ from the end of the stream, without loading the whole file into memory —
47
+ scalable to long histories.
48
+ - **Text and binary content, uniformly.** Text uses an RCS-style (`diff -n`)
49
+ line delta; binary content uses a BSDIFF40-compatible patch format
50
+ (interoperable with the native `bsdiff`/`bspatch` tools). `commit()` accepts
51
+ `str`, `bytes`, or `BinaryIO` directly.
52
+ - **v2 hash chain & signatures.** Each block carries a hash of its logical
53
+ content plus the previous block's hash, making tampering with any past
54
+ version detectable. Optional GPG-based multi-signer signing/verification is
55
+ built in (`simple_rcs_gpg`).
56
+ - **Intermediate snapshots.** `commit(..., snapshot=True)` stores the previous
57
+ HEAD as full text instead of a delta, breaking the delta chain at that point
58
+ for faster retrieval of that region of history.
59
+ - **`log()` metadata-only path.** History listing parses block metadata
60
+ directly off the stream without decoding delta/binary payloads.
61
+
62
+ ## Architecture
63
+
64
+ ```
65
+ [V1 Delta] [V2 Delta] ... [Vn-1 Delta] [Vn Full Text]
66
+ ^^^^^^^^^^^^^
67
+ HEAD (always full text)
68
+ ```
69
+
70
+ Committing a new version:
71
+
72
+ 1. Read the current HEAD (full text).
73
+ 2. Compute a reverse delta (New → Old HEAD).
74
+ 3. Overwrite the on-disk HEAD block with that delta.
75
+ 4. Append the new content as the new HEAD block (full text).
76
+
77
+ Checking out an old version walks backward from HEAD, applying each block's
78
+ reverse delta (or jumping directly to a snapshot's full text) until the
79
+ target version is reached.
80
+
81
+ ## Comparison
82
+
83
+ Updated from the original design comparison (see [PR #2](https://github.com/wkpark/SimpleRCS/pull/2)) to reflect the current implementation:
84
+
85
+ | Feature | SimpleRCS | RCS (Original) | Git | DB (Simple Snapshot) |
86
+ | :--- | :--- | :--- | :--- | :--- |
87
+ | Storage unit | Single file (stream) | Single file (`*,v`) | Object DB (`.git`) + working tree | DB row |
88
+ | Delta direction | Reverse delta (HEAD = full text) | Reverse delta (HEAD = full text) | Snapshot (delta generated at pack time) | Full copy (no delta) |
89
+ | Storage pattern | Append-dominant (tail rewrite + append) | Header update + insert | Content-addressable storage | Insert new row |
90
+ | I/O pattern | Efficient tail write; single-pass backward scan (no re-read) for HEAD lookup | Random write (header/body) | Many small files / packfiles | DB transaction |
91
+ | Content types | Text (RCS diff) **and** binary (BSDIFF40-compatible), same file format | Text only (binary needs external encoding) | Any (blob-based) | Any (column type) |
92
+ | Integrity | v2: per-block hash chain + optional multi-signer GPG signatures | None | Content-addressable (SHA-1/256 of objects) | Depends on DB |
93
+ | Intermediate snapshots | Optional, per-commit (`snapshot=True`) | Not supported | N/A (every commit is already a full snapshot object) | N/A |
94
+ | HEAD lookup | **O(1)**, single-pass (read from end) | O(1) (read from start) | O(1) (ref → commit → tree) | O(1) (select by ID) |
95
+ | History lookup | **O(k)**, backward scan (k = distance from HEAD) | O(N) forward scan | O(log N) DAG traversal | O(1) (select with limit) |
96
+ | Diff engine | Greedy hash-matching (`StreamSequenceMatcher`, O(N)); Cython-accelerated Myers SES/DMP available for benchmarking | Standard `diff` | `xdiff` (Myers-based) | N/A |
97
+ | Complexity | Low (single class, no object graph) | Medium (custom grammar) | High (complex object model) | Low (SQL) |
98
+
99
+ **Note on the diff engine:** `commit()` picks its text-diff backend at import
100
+ time. When the Cython Myers matchers were compiled — which happens
101
+ automatically on install if a C toolchain is available — they are used, giving
102
+ a shortest edit script. Otherwise it falls back to `StreamSequenceMatcher`, a
103
+ greedy O(N) hash-matching algorithm that favors speed over minimal edit
104
+ distance. Either way the install succeeds and histories stay compatible: block
105
+ hashes cover logical content, not the stored delta bytes.
106
+
107
+ Set `SIMPLE_RCS_MATCHER` to force a specific backend — `dmp_cython`,
108
+ `ses_cython`, `stream`, `dmp_py`, `ses_py`. The names match the ids
109
+ `tools/bench_diff.py` prints, so you can benchmark and then pin the winner.
110
+ The `*_py` backends are first-cut reference implementations kept for
111
+ comparison; they hit an O(ND) worst case on dissimilar inputs and are never
112
+ chosen by fallback.
113
+
114
+ ## Usage
115
+
116
+ ```python
117
+ from simple_rcs.simple_rcs import SimpleRCS
118
+
119
+ # In-memory, or pass a file path to persist to disk
120
+ rcs = SimpleRCS("my_document.srcs")
121
+
122
+ v1 = rcs.commit("Hello\nWorld\n", author="alice", log="initial")
123
+ v2 = rcs.commit("Hello\nSimpleRCS\n", author="bob", log="tweak line 2")
124
+
125
+ rcs.checkout(v1) # -> "Hello\nWorld\n"
126
+ rcs.checkout() # HEAD, i.e. v2
127
+
128
+ rcs.log() # [{'ver': '1.1', 'author': 'bob', ...}, {'ver': '1.0', ...}]
129
+ rcs.diff(v1, v2) # unified diff between two versions
130
+ rcs.blame() # per-line author/version attribution for HEAD
131
+ rcs.verify() # walks the v2 hash chain, returns True/False
132
+
133
+ # Binary content works the same way
134
+ rcs.commit(open("image.png", "rb").read(), author="alice")
135
+ ```
136
+
137
+ Command-line helpers live in `tools/`: `srcs_log.py` (history/signature
138
+ listing), `srcs_diff.py` (unified diff between versions or engines),
139
+ `srcs_sign_head.py` (GPG-sign the current HEAD), and `bench_diff.py`
140
+ (diff-engine benchmark harness).
141
+
142
+ ## Testing
143
+
144
+ ```
145
+ uv run pytest tests/unit_tests/ -q
146
+ ```
147
+
148
+ 61 tests covering text/binary round-trips, hash-chain verification, snapshot
149
+ handling, and `log()`'s metadata-only parsing path.
150
+
151
+ ## License
152
+
153
+ Apache License 2.0 — see [LICENSE](LICENSE).
154
+
155
+ ---
156
+
157
+ # SimpleRCS (한글)
158
+
159
+ **SimpleRCS**는 단일 문서를 초경량으로 관리하기 위해 새로 설계한 스트림 기반
160
+ 버전 관리 시스템이다. 전통적인 RCS의 역방향 델타 저장 방식을 차용하되, 스트림
161
+ 중심 I/O, O(1) HEAD 접근, 백워드 스캔 기반 히스토리 순회 등 현대적인 성능
162
+ 고려사항으로 다시 설계했다. Git의 객체 모델이 과할 때, 혹은 파일시스템/DB
163
+ 블롭에 직접 통합하고 싶을 때 적합하다.
164
+
165
+ 파일과 유사한 객체(`BinaryIO`) 위에서 동작한다 — 디스크 경로, 인메모리
166
+ `BytesIO`, 외부에서 넘겨받은 핸들 모두 동일하게 동작한다.
167
+
168
+ ## 핵심 특징
169
+
170
+ - **역방향 델타 저장.** 최신 버전(HEAD)은 항상 스트림 끝에 전체 텍스트로
171
+ 저장되고, 이전 버전들은 역방향 델타(버전 N+1을 N으로 되돌리는 명령)로
172
+ 저장된다. HEAD 읽기는 O(1), 과거 버전 읽기는 O(k)(k = HEAD로부터의 거리).
173
+ - **Append 위주 쓰기.** 커밋 시 기존 HEAD 블록만 덮어쓰고(전체 텍스트→델타),
174
+ 새 HEAD는 끝에 추가(append)된다. 전체 히스토리를 다시 쓰는 일은 없다.
175
+ - **백워드 스캔, 스트림 중심 I/O.** 히스토리는 스트림 끝에서부터 스캔해서
176
+ 찾으며, 전체 파일을 메모리에 올리지 않는다 — 긴 히스토리에도 확장 가능.
177
+ - **텍스트/바이너리 콘텐츠를 동일한 인터페이스로.** 텍스트는 RCS 스타일
178
+ (`diff -n`) 라인 델타, 바이너리는 BSDIFF40 호환 패치 포맷(네이티브
179
+ `bsdiff`/`bspatch`와 상호운용 가능)을 사용한다. `commit()`은 `str`,
180
+ `bytes`, `BinaryIO`를 그대로 받는다.
181
+ - **v2 해시 체인 & 서명.** 각 블록은 논리적 콘텐츠의 해시와 이전 블록의
182
+ 해시를 함께 가지므로, 과거 어느 버전이든 변조하면 감지된다. GPG 기반
183
+ 다중 서명자 서명/검증도 내장(`simple_rcs_gpg`).
184
+ - **중간 스냅샷.** `commit(..., snapshot=True)`로 커밋하면 직전 HEAD를
185
+ 델타 대신 전체 텍스트로 저장해, 그 지점에서 델타 체인을 끊고 해당 구간의
186
+ 과거 버전 조회를 빠르게 만든다.
187
+ - **`log()` 메타데이터 전용 경로.** 히스토리 목록 조회 시 델타/바이너리
188
+ 본문을 디코딩하지 않고 스트림에서 메타데이터만 직접 파싱한다.
189
+
190
+ ## 비교 분석
191
+
192
+ [PR #2](https://github.com/wkpark/SimpleRCS/pull/2)의 최초 비교표를 현재
193
+ 구현 기준으로 갱신했다:
194
+
195
+ | 항목 | SimpleRCS | RCS (원본) | Git | DB (단순 스냅샷) |
196
+ | :--- | :--- | :--- | :--- | :--- |
197
+ | 저장 단위 | 단일 파일(스트림) | 단일 파일(`*,v`) | 객체 DB(`.git`) + 작업 트리 | DB 레코드(Row) |
198
+ | 델타 방향 | 역방향 델타(Head=전체 텍스트) | 역방향 델타(Head=전체 텍스트) | 스냅샷(패킹 시 델타 생성) | 전체 복사(델타 없음) |
199
+ | 저장 구조 | Append 위주(꼬리 덮어쓰기 + append) | 헤더 갱신 + 삽입 | 콘텐츠 주소 기반 저장소 | 새 행 삽입 |
200
+ | I/O 패턴 | 효율적인 꼬리 쓰기, HEAD 조회는 재읽기 없는 단일 패스 백워드 스캔 | 랜덤 쓰기(헤더/본문) | 많은 작은 파일 / packfile | DB 트랜잭션 |
201
+ | 콘텐츠 종류 | 텍스트(RCS diff)와 바이너리(BSDIFF40 호환)를 같은 파일 포맷으로 지원 | 텍스트 전용(바이너리는 별도 인코딩 필요) | 모든 타입(blob 기반) | 모든 타입(컬럼 타입) |
202
+ | 무결성 | v2: 블록별 해시 체인 + 선택적 다중 서명자 GPG 서명 | 없음 | 콘텐츠 주소 기반(객체 SHA-1/256) | DB에 따라 다름 |
203
+ | 중간 스냅샷 | 커밋별 선택 가능(`snapshot=True`) | 미지원 | 해당 없음(모든 커밋이 이미 완전한 스냅샷 객체) | 해당 없음 |
204
+ | HEAD 조회 | **O(1)**, 단일 패스(끝에서부터 읽기) | O(1)(처음부터 읽기) | O(1)(ref → commit → tree) | O(1)(ID로 select) |
205
+ | 히스토리 조회 | **O(k)**, 백워드 스캔(k = HEAD로부터의 거리) | O(N) 순방향 스캔 | O(log N) DAG 순회 | O(1)(limit으로 select) |
206
+ | Diff 엔진 | 그리디 해시 매칭(`StreamSequenceMatcher`, O(N)); Cython 가속 Myers SES/DMP는 벤치마크용으로 별도 제공 | 표준 `diff` | `xdiff`(Myers 기반) | 해당 없음 |
207
+ | 복잡도 | 낮음(단일 클래스, 객체 그래프 없음) | 중간(전용 문법) | 높음(복잡한 객체 모델) | 낮음(SQL) |
208
+
209
+ **Diff 엔진 관련 참고:** `commit()`은 import 시점에 텍스트 diff
210
+ 백엔드를 결정한다. Cython Myers 매처가 컴파일된 경우 — C 툴체인이
211
+ 있는 환경에서는 설치 시 자동으로 빌드된다 — 그걸 사용해 최단 편집
212
+ 스크립트를 얻고, 없으면 `StreamSequenceMatcher`(최소 편집 거리보다 속도를
213
+ 우선하는 그리디 O(N) 해시 매칭)로 폴백한다. 어느 쪽이든 설치는 성공하고
214
+ 기존 이력도 그대로 읽힌다 — 블록 해시는 저장된 델타 바이트가 아니라
215
+ 논리적 내용을 덮기 때문이다.
216
+
217
+ `SIMPLE_RCS_MATCHER`로 백엔드를 직접 지정할 수 있다 — `dmp_cython`,
218
+ `ses_cython`, `stream`, `dmp_py`, `ses_py`. 이름은 `tools/bench_diff.py`가
219
+ 출력하는 id와 같아서, 벤치를 돌린 뒤 승자를 그대로 고정하면 된다.
220
+ `*_py` 백엔드는 초기 구현 레퍼런스로 비교용으로만 남겨둔 것이고,
221
+ 비유사 입력에서 O(ND) 최악을 밟아 폴백 대상이 되지는 않는다.
222
+
223
+ ## 사용법
224
+
225
+ ```python
226
+ from simple_rcs.simple_rcs import SimpleRCS
227
+
228
+ # 인메모리로 쓰거나, 경로를 넘기면 디스크에 저장됨
229
+ rcs = SimpleRCS("my_document.srcs")
230
+
231
+ v1 = rcs.commit("Hello\nWorld\n", author="alice", log="initial")
232
+ v2 = rcs.commit("Hello\nSimpleRCS\n", author="bob", log="tweak line 2")
233
+
234
+ rcs.checkout(v1) # -> "Hello\nWorld\n"
235
+ rcs.checkout() # HEAD, 즉 v2
236
+
237
+ rcs.log() # [{'ver': '1.1', 'author': 'bob', ...}, {'ver': '1.0', ...}]
238
+ rcs.diff(v1, v2) # 두 버전 간 unified diff
239
+ rcs.blame() # HEAD의 라인별 저자/버전 귀속
240
+ rcs.verify() # v2 해시 체인 검증, True/False 반환
241
+
242
+ # 바이너리 콘텐츠도 동일하게 동작
243
+ rcs.commit(open("image.png", "rb").read(), author="alice")
244
+ ```
245
+
246
+ 명령줄 도구는 `tools/`에 있다: `srcs_log.py`(히스토리/서명 목록),
247
+ `srcs_diff.py`(버전/엔진 간 unified diff), `srcs_sign_head.py`(현재
248
+ HEAD를 GPG로 서명), `bench_diff.py`(diff 엔진 벤치마크).
249
+
250
+ ## 테스트
251
+
252
+ ```
253
+ uv run pytest tests/unit_tests/ -q
254
+ ```
255
+
256
+ 텍스트/바이너리 라운드트립, 해시 체인 검증, 스냅샷 처리, `log()`의 메타데이터
257
+ 전용 파싱 경로까지 총 61개 테스트로 커버한다.
258
+
259
+ ## 라이선스
260
+
261
+ Apache License 2.0 — [LICENSE](LICENSE) 참고.