• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

Revision8b60dc0d6200a93008d69c118732d46bdc7a72d3 (tree)
Time2024-04-25 10:34:53
AuthorCorbin <cds@corb...>
CommiterCorbin

Log Message

Get 2to3.py to build a v3 hive.

I haven't verified that the contents of the hive are correct, and
git-fsck is (unsurprisingly) very unhappy with me. I used a monkey patch
on dulwich to allow creation of refs with question marks in their names,
because I know it's legal on Linux and I don't care about other kernels.

Change Summary

Incremental Difference

--- a/2to3.py
+++ b/2to3.py
@@ -1,21 +1,45 @@
11 import json
2+import os
23 import sys
4+import time
35
4-import dulwich
6+from dulwich.repo import Repo
7+from dulwich.objects import Blob, Commit, Tree
58
6-with open(sys.argv[-1]) as handle: d = json.load(handle)
9+# Monkey patch: Allow ? in ref names.
10+from dulwich import refs
11+refs.BAD_REF_CHARS = set(b"\177 ~^:*[")
12+
13+with open(sys.argv[-2]) as handle: d = json.load(handle)
14+repoPath = sys.argv[-1]
15+if os.path.exists(repoPath): repo = Repo(repoPath)
16+else: repo = Repo.init(repoPath, mkdir=True)
17+
18+# XXX implement following four functions, all should return object hash :str
719
820 def insertBlob(s):
9- return "blob"
21+ blob = Blob.from_string(s.encode("utf-8"))
22+ repo.object_store.add_object(blob)
23+ return blob.id
1024
1125 def insertTree(d):
12- return "tree"
26+ tree = Tree()
27+ for k, v in d.items():
28+ tree.add(k.encode("utf-8"), 0o100644, v)
29+ repo.object_store.add_object(tree)
30+ return tree.id
1331
32+author = b"Corbin <cds@corbinsimpson.com>"
1433 def insertCommit(tree, message):
15- return "commit"
16-
17-def addTag(t, obj):
18- return "tag"
34+ commit = Commit()
35+ commit.author = commit.committer = author
36+ commit.author_time = commit.commit_time = int(time.time())
37+ commit.author_timezone = commit.commit_timezone = 0
38+ commit.encoding = b"UTF-8"
39+ commit.message = message.encode("utf-8")
40+ commit.tree = tree
41+ repo.object_store.add_object(commit)
42+ return commit.id
1943
2044 heap = []
2145 for row in d["heap"]:
@@ -25,10 +49,14 @@ for row in d["heap"]:
2549 tree = dict((("_%d" % i, heap[j]) for i, j in enumerate(row[1:])))
2650 tree["_con"] = insertBlob(row[0])
2751 heap.append(insertTree(tree))
52+ if not (len(heap) % 100): print("h", end="", flush=True)
53+print()
2854
29-print("Heap is processed! Total expressions:", len(heap))
30-
55+exprCount = 0
3156 def insertExpr(expr):
57+ global exprCount
58+ exprCount += 1
59+ if not (exprCount % 100): print("e", end="", flush=True)
3260 if isinstance(expr, str): return insertBlob(expr)
3361 elif isinstance(expr, int): return insertBlob("_%d" % expr)
3462 else:
@@ -36,18 +64,21 @@ def insertExpr(expr):
3664 tree = dict(("_%d" % i, j) for i, j in enumerate(exprs))
3765 return insertTree(tree)
3866
39-for name, expr in d["jets"].items(): addTag("jets/" + name, insertExpr(expr))
67+def refName(ns, s): return (("refs/%s/%s" % (ns, s)).encode("utf-8"))
4068
41-print("Jets are processed! Total jets:", len(d["jets"]))
69+for name, expr in d["jets"].items():
70+ repo.refs[refName("jets", name)] = insertExpr(expr)
4271
4372 for name, row in d["symbols"].items():
4473 pointer, trail = row
45- addTag("local/" + name, insertCommit(heap[pointer], trail))
46-
47-print("Symbols are processed! Total names:", len(d["symbols"]))
74+ repo.refs[refName("local", name)] = insertCommit(heap[pointer], trail)
4875
4976 for name, row in d["templates"].items():
5077 expr, trail = row
51- addTag("local/" + name, insertCommit(insertExpr(expr), trail))
78+ repo.refs[refName("local", name)] = insertCommit(insertExpr(expr), trail)
5279
80+print()
81+print("Heap is processed! Total expressions:", len(heap))
5382 print("Templates are processed! Total names:", len(d["templates"]))
83+print("Jets are processed! Total jets:", len(d["jets"]))
84+print("Symbols are processed! Total names:", len(d["symbols"]))