This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite.py
More file actions
281 lines (232 loc) · 8.4 KB
/
rewrite.py
File metadata and controls
281 lines (232 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
from __future__ import annotations
import contextlib
import os.path
import re
import shlex
import subprocess
import sys
from collections.abc import Generator
GIT_FILTER_REPO = os.path.abspath('venv/bin/git-filter-repo')
def run(*cmd: str) -> None:
print(f'+ {shlex.join(cmd)}', flush=True, file=sys.stderr)
subprocess.check_call(cmd)
def runo(*cmd: str) -> str:
print(f'+ {shlex.join(cmd)} # captured', flush=True, file=sys.stderr)
return subprocess.check_output(cmd, text=True)
@contextlib.contextmanager
def cd(d: str) -> Generator[None]:
print(f'pushd {d}', flush=True, file=sys.stderr)
with contextlib.chdir(d):
yield
print('popd', flush=True, file=sys.stderr)
def commit_by_msg(msg: str) -> str:
out = runo('git', 'log', '--grep', f'^{re.escape(msg)}$', '--format=%H')
assert len(out.splitlines()) == 1, out
return out.strip()
def _delete_other_refs() -> None:
run('git', 'remote', 'rm', 'origin')
tags = runo('git', 'tag', '--list').splitlines()
run('git', 'tag', '-d', *tags)
@contextlib.contextmanager
def _branch(cid: str, name: str) -> Generator[tuple[str, ...]]:
orig = runo('git', 'rev-parse', cid).strip()
run('git', 'checkout', orig, '-b', name)
yield (GIT_FILTER_REPO, '--force', '--refs', 'HEAD')
run('git', 'checkout', 'main')
run('git', 'replace', orig, name)
run(GIT_FILTER_REPO, '--proceed')
run('git', 'branch', '-D', name)
def _rename_mtllm() -> None:
c = commit_by_msg('pulling it together')
with _branch(f'{c}^', 'jac-mtllm-rewrite') as rewrite:
run(*rewrite, '--to-subdirectory-filter=jac-mtllm')
def _rename_jac_cloud() -> None:
c = commit_by_msg('big move')
with _branch(f'{c}^', 'jac-cloud-rewrite') as rewrite:
run(*rewrite, '--to-subdirectory-filter=jac-cloud')
def _rename_jaseci_v1() -> None:
c = commit_by_msg('Jaseci-wide repo reorg')
with _branch(f'{c}^', 'jaseci-v1-rewrite') as rewrite:
# remove later-deleted things
run(
*rewrite,
'--path=experiments/config.py',
'--path=.github',
'--invert-paths',
)
run(*rewrite, '--to-subdirectory-filter=jaseci_v1')
def _trailing_rewrites() -> None:
removals = '''\
# v1 files
.github/ISSUE_TEMPLATE/bug_report.md
.github/ISSUE_TEMPLATE/feature_request.md
.github/workflows/black.yml
.github/workflows/build-and-release-studio.yml
.github/workflows/build-and-release.yml
.github/workflows/jac-extension-test.yml
.github/workflows/jac-misc-test.yml
.github/workflows/jac-nlp-test.yml
.github/workflows/jac-speech-test.yml
.github/workflows/jac-vision-test.yml
.github/workflows/jaseci-core-test.yml
.github/workflows/jaseci-serv-test.yml
.github/workflows/jaseci-studio-test.yml
_v1
# large things
docs/book_html
docs/docs/assets/playground_demo.gif
docs/docs/assets/playground_demo.mp4
docs/docs/assets/photo.jpg
docs/docs/assets/byLLM_name_logo.png
docs/docs/assets/byLLM Logo.png
docs/docs/learn/examples/littleX/images
docs/docs/examples/littleX/images
jac/support/jac-lang.org/docs/examples/littleX/images
jac/support/jac-lang.org/docs/learn/littleX/images
docs/docs/assets/p2_arch.png
docs/docs/assets/runtime.gif
docs/docs/assets/vsce/jaclang-extension-2025.7.17.vsix
docs/docs/learn/examples/mtp_examples/assets/rpg_demo.gif
docs/docs/learn/examples/mtp_examples/assets/rpg_demo.mp4
jac/support/jac-lang.org/docs/assets/mtllm demo.mp4
support/vscode_ext/jac/jac-0.0.1.vsix
jac-byllm/poetry.lock
# pngs in trenchcoats
jac-scale/assets/jac-scale-architecture.svg
jac_client/docs/assets
jac-client/jac_client/docs/assets
# trash
docs/book/book.synctex(busy)
.github/archived_workflows
# removed
jac-cloud
jac-splice-orc
# compiled playground removed
docs/docs/playground/assets
docs/docs/playground/favicon.ico
docs/docs/playground/index.html
docs/docs/playground/jac_examples.json
docs/docs/playground/jaseci.png
docs/docs/playground/language-configuration.json
docs/docs/playground/language-reference.json
docs/docs/playground/onigasm.wasm
docs/docs/playground/python
docs/docs/playground/robots.txt
jac/support/jac-lang.org/docs/playground/assets
# codedoc (removed!)
jac-byllm/docs/.codedoc
jac-byllm/docs/docs/assets
'''
run(
GIT_FILTER_REPO,
'--path-rename=jaclang:jac',
'--path-rename=jaseci_v1:_v1',
'--path-rename=jac-mtllm:jac-byllm',
*(
f'--path={p}'
for p in removals.splitlines()
if not p.startswith('#')
),
# this funny file has control characters in its name
'--path-glob=t.replace*',
'--path-glob=*/clinical_medicine.pdf',
'--path-glob=jac/examples/rpg_game/Diagrams/Jac_impl*.png',
'--path-glob=*/rag_chatbot/images/*.png',
'--path-glob=*/rag_chatbot_need_fixing/images/*.png',
'--invert-paths',
)
def _squash_prs() -> None:
callback = '''\
if (
commit.message.startswith(b"Merge pull request ") and
len(commit.parents) == 2
):
del commit.parents[1]
'''
run(GIT_FILTER_REPO, '--commit-callback', callback)
def _rename_jaclang() -> None:
c = commit_by_msg('bringing jaclang over')
with _branch(f'{c}^', 'jaclang-rewrite') as rewrite:
run(*rewrite, '--to-subdirectory-filter=jac')
run(
*rewrite,
'--path-rename=jac/.github:.github',
'--path-rename=jac/jac:jac/jaclang',
)
PRESERVE_COMMITTER = (
'-c', 'rebase.instructionFormat=%s%nexec GIT_COMMITTER_DATE="%cD" GIT_COMMITTER_NAME="%cn" GIT_COMMITTER_EMAIL="%ce" git commit --amend --no-edit --allow-empty', # noqa: E501
)
def _typeshed_was_always_a_submodule() -> None:
c = commit_by_msg('Merge pull request #2160 from jaseci-labs/type_01')
env = {**os.environ, 'GIT_EDITOR': 'sed -i "0,/pick/s//edit/"'}
cmd = ('git', *PRESERVE_COMMITTER, 'rebase', '-i', f'{c}^')
print(f'+ {shlex.join(cmd)}')
subprocess.check_call(cmd, env=env)
run('git', 'rm', '-r', 'jac/jaclang/vendor/typeshed')
run(
'git', 'submodule', 'add',
'https://github.com/python/typeshed', 'jac/jaclang/vendor/typeshed',
)
run(
'git', '-C', 'jac/jaclang/vendor/typeshed',
'checkout', 'df3b5f3cdd7736079ad3124db244e4553625590c',
)
run('git', 'add', 'jac/jaclang/vendor/typeshed')
run('git', 'commit', '--amend', '--no-edit')
# should fail with conflict!
assert subprocess.call(
('git', *PRESERVE_COMMITTER, 'rebase', '--continue'),
)
# make sure we're resolving the correct one
out = runo('git', 'status', '--porcelain', '--', 'jac')
assert out == 'AA jac/jaclang/vendor/typeshed\n', out
run(
'git', '-C', 'jac/jaclang/vendor/typeshed',
'checkout', 'bbbf7530a987e59c8458127351cacad2e57f04bf',
)
run('git', 'add', 'jac/jaclang/vendor/typeshed')
run('git', 'commit', '--no-edit')
run('git', *PRESERVE_COMMITTER, 'rebase', '--continue')
def _more_deletions() -> None:
run(
GIT_FILTER_REPO,
'--path=jac/support/vscode_ext',
'--path=jac/jaclang/vendor/bin',
'--path=jac/jaclang/vendor/mypyc',
'--path=jac/jaclang/vendor/mypy',
'--path-glob=jac/jaclang/vendor/mypy-*.dist-info',
'--path=jac/examples/rpg_game/Diagrams',
'--path=jac/jaclang/compiler/larkparse',
'--path=jac/support/jac-lang.org/docs/learn/tutorial/images',
'--path-glob=jac/examples/rpg_game/jac_impl/RPG Space*.png',
'--path-glob=jac/examples/rpg_game/*/img/*.png',
'--invert-paths',
)
def _one_git_root() -> None:
c = commit_by_msg("Merge branch 'mtllm' into repo_reorg")
with _branch(f'{c}^2', 'rebase-mtllm'):
run(
'git', *PRESERVE_COMMITTER, 'rebase',
'--rebase-merges=rebase-cousins', f'{c}^1',
)
def main() -> int:
run('rm', '-rf', 'jaseci')
run('cp', '-r', 'original', 'jaseci')
with cd('jaseci'):
_delete_other_refs()
_rename_mtllm()
_rename_jac_cloud()
_rename_jaseci_v1()
_trailing_rewrites()
_squash_prs()
# idk why this has to be at the end? haunted?
_rename_jaclang()
_typeshed_was_always_a_submodule()
_more_deletions()
_one_git_root()
run('du', '--exclude', 'modules', '-hs', 'original/.git', 'jaseci/.git')
run('git', '-C', 'original', 'rev-list', '--count', '--all')
run('git', '-C', 'jaseci', 'rev-list', '--count', '--all')
return 0
if __name__ == '__main__':
raise SystemExit(main())