Skip to content

Commit 6d64f18

Browse files
committed
git-repo: use patch series instead of a cumulative patch
1 parent adf0c0e commit 6d64f18

18 files changed

+871
-886
lines changed

pkgs/gitRepo/00001-add-support-for-repo2nix.patch

Lines changed: 0 additions & 882 deletions
This file was deleted.

pkgs/gitRepo/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ in
1616

1717
nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ rsync git ];
1818

19+
repo2nixPatches = ./patches;
20+
1921
# NOTE: why `git apply` instead of relying on `patches`? For some reason when
2022
# using `patches` the source `rsync`ed into `var/repo` is missing those changes
2123
installPhase = ''
@@ -40,9 +42,7 @@ in
4042
git add -A
4143
git commit -m "Upstream sources"
4244
43-
git apply ${ ./00001-add-support-for-repo2nix.patch }
44-
git add -A
45-
git commit -m "Patch with repo2nix"
45+
git am $repo2nixPatches/*.patch
4646
4747
git log -n 1 --format="%H" > ../../COMMITED_REPO_REV
4848
)
@@ -64,7 +64,7 @@ in
6464
postFixup = ''
6565
wrapProgram "$out/bin/repo" \
6666
--set REPO_URL "file://$out/var/repo" \
67-
--set REPO_REV "$(cat COMMITED_REPO_REV)" \
67+
--set REPO_REV "$(cat ./COMMITED_REPO_REV)" \
6868
--prefix PATH ":" "${ lib.makeBinPath [ git gnupg less openssh ] }"
6969
'';
7070
})
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
From 8fe8a2efaa6bcd404c256a29d1dc5ed4ae241a08 Mon Sep 17 00:00:00 2001
2+
From: ajs124 <git@ajs124.de>
3+
Date: Tue, 26 Feb 2019 04:48:13 +0100
4+
Subject: [PATCH 01/16] add initial (hacky) version of "repo2nix"
5+
6+
now with less impurities
7+
---
8+
project.py | 4 +-
9+
subcmds/nix.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
10+
2 files changed, 102 insertions(+), 2 deletions(-)
11+
create mode 100644 subcmds/nix.py
12+
13+
diff --git a/project.py b/project.py
14+
index 1f5e4c3..c3c3384 100644
15+
--- a/project.py
16+
+++ b/project.py
17+
@@ -2887,8 +2887,8 @@ class Project:
18+
)
19+
20+
def _LsRemote(self, refs):
21+
- cmd = ["ls-remote", self.remote.name, refs]
22+
- p = GitCommand(self, cmd, capture_stdout=True)
23+
+ cmd = ["ls-remote", self.remote.url, refs]
24+
+ p = GitCommand(self, cmd, cwd="/", capture_stdout=True)
25+
if p.Wait() == 0:
26+
return p.stdout
27+
return None
28+
diff --git a/subcmds/nix.py b/subcmds/nix.py
29+
new file mode 100644
30+
index 0000000..f113ede
31+
--- /dev/null
32+
+++ b/subcmds/nix.py
33+
@@ -0,0 +1,100 @@
34+
+#
35+
+# Copyright (C) 2008 The Android Open Source Project
36+
+#
37+
+# Licensed under the Apache License, Version 2.0 (the "License");
38+
+# you may not use this file except in compliance with the License.
39+
+# You may obtain a copy of the License at
40+
+#
41+
+# http://www.apache.org/licenses/LICENSE-2.0
42+
+#
43+
+# Unless required by applicable law or agreed to in writing, software
44+
+# distributed under the License is distributed on an "AS IS" BASIS,
45+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46+
+# See the License for the specific language governing permissions and
47+
+# limitations under the License.
48+
+
49+
+from __future__ import print_function
50+
+
51+
+from pyversion import is_python3
52+
+if is_python3():
53+
+ import http.cookiejar as cookielib
54+
+ import urllib.error
55+
+ import urllib.parse
56+
+ import urllib.request
57+
+ import xmlrpc.client
58+
+else:
59+
+ import imp
60+
+ import urllib2
61+
+ import urlparse
62+
+ import xmlrpclib
63+
+ urllib = imp.new_module('urllib')
64+
+ urllib.error = urllib2
65+
+ urllib.parse = urlparse
66+
+ urllib.request = urllib2
67+
+ xmlrpc = imp.new_module('xmlrpc')
68+
+ xmlrpc.client = xmlrpclib
69+
+
70+
+try:
71+
+ import threading as _threading
72+
+except ImportError:
73+
+ import dummy_threading as _threading
74+
+
75+
+try:
76+
+ import resource
77+
+ def _rlimit_nofile():
78+
+ return resource.getrlimit(resource.RLIMIT_NOFILE)
79+
+except ImportError:
80+
+ def _rlimit_nofile():
81+
+ return (256, 256)
82+
+
83+
+try:
84+
+ import multiprocessing
85+
+except ImportError:
86+
+ multiprocessing = None
87+
+
88+
+from command import Command, MirrorSafeCommand
89+
+
90+
+class Nix(Command, MirrorSafeCommand):
91+
+ common = True
92+
+ helpSummary = "Export nix file with sources"
93+
+ helpUsage = """
94+
+%prog [<project>...]
95+
+"""
96+
+ helpDescription = """
97+
+"""
98+
+
99+
+ def Execute(self, opt, args):
100+
+ all_projects = self.GetProjects(args, missing_ok=True, submodules_ok=False)
101+
+
102+
+ oS = '{\n'
103+
+ oS += "unpackPhase = ''\n" \
104+
+ 'echo "reassembling source tree from git source store paths"\n' \
105+
+ 'mkdir src; cd src\n' \
106+
+ 'for src in $srcs; do\n' \
107+
+ " dest_folder=$(stripHash $src); dest_folder=''${dest_folder//=//}\n" \
108+
+ ' echo "$src -> $dest_folder"\n' \
109+
+ ' mkdir -p "$dest_folder"\n' \
110+
+ ' cp --reflink=auto --no-preserve=ownership --no-dereference --preserve=links --recursive "$src/." "$dest_folder/"\n' \
111+
+ ' chmod -R u+w "$dest_folder"\n' \
112+
+ 'done\n' \
113+
+ 'echo "creating symlinks and copies as specified in repo manifest(s)"\n'
114+
+ for p in all_projects:
115+
+ for f in p.linkfiles:
116+
+ oS += 'ln -s ' + f.src_rel_to_dest + ' ' + f.dest + '\n'
117+
+ for c in p.copyfiles:
118+
+ oS += 'cp --reflink=auto ' + p.relpath + '/' + c.src + ' ' + c.dest + '\n'
119+
+ oS += "'';\n"
120+
+
121+
+ oS += 'sources = [\n'
122+
+ for p in all_projects:
123+
+ oS += ' (builtins.fetchGit {\n'
124+
+ oS += ' url = "' + p.remote.url + '";\n'
125+
+ if 'refs/heads' in p.revisionExpr:
126+
+ oS += ' ref = "' + p.revisionExpr.split('/')[-1] + '";\n'
127+
+ else:
128+
+ oS += ' ref = "' + p.revisionExpr + '";\n'
129+
+ oS += ' rev = "' + p._LsRemote(p.revisionExpr).split('\t')[0] + '";\n'
130+
+ oS += ' name = "' + p.relpath.replace('/', '=') + '";\n'
131+
+ oS += ' })\n'
132+
+ oS += '];\n}'
133+
+ print(oS)
134+
\ No newline at end of file
135+
--
136+
2.44.0
137+
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
From 4550efa07636b497bfca0b8379c0656ed09770cb Mon Sep 17 00:00:00 2001
2+
From: Daniel Fullmer <danielrf12@gmail.com>
3+
Date: Mon, 15 Jul 2019 14:43:17 -0400
4+
Subject: [PATCH 02/16] repo2nix: output just json--do more processing in nix
5+
6+
---
7+
subcmds/dumpjson.py | 92 +++++++++++++++++++++++++++++++++++++++++++++
8+
1 file changed, 92 insertions(+)
9+
create mode 100644 subcmds/dumpjson.py
10+
11+
diff --git a/subcmds/dumpjson.py b/subcmds/dumpjson.py
12+
new file mode 100644
13+
index 0000000..a09885d
14+
--- /dev/null
15+
+++ b/subcmds/dumpjson.py
16+
@@ -0,0 +1,92 @@
17+
+#
18+
+# Copyright (C) 2008 The Android Open Source Project
19+
+#
20+
+# Licensed under the Apache License, Version 2.0 (the "License");
21+
+# you may not use this file except in compliance with the License.
22+
+# You may obtain a copy of the License at
23+
+#
24+
+# http://www.apache.org/licenses/LICENSE-2.0
25+
+#
26+
+# Unless required by applicable law or agreed to in writing, software
27+
+# distributed under the License is distributed on an "AS IS" BASIS,
28+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
+# See the License for the specific language governing permissions and
30+
+# limitations under the License.
31+
+
32+
+from __future__ import print_function
33+
+
34+
+from pyversion import is_python3
35+
+if is_python3():
36+
+ import http.cookiejar as cookielib
37+
+ import urllib.error
38+
+ import urllib.parse
39+
+ import urllib.request
40+
+ import xmlrpc.client
41+
+else:
42+
+ import imp
43+
+ import urllib2
44+
+ import urlparse
45+
+ import xmlrpclib
46+
+ urllib = imp.new_module('urllib')
47+
+ urllib.error = urllib2
48+
+ urllib.parse = urlparse
49+
+ urllib.request = urllib2
50+
+ xmlrpc = imp.new_module('xmlrpc')
51+
+ xmlrpc.client = xmlrpclib
52+
+
53+
+try:
54+
+ import threading as _threading
55+
+except ImportError:
56+
+ import dummy_threading as _threading
57+
+
58+
+try:
59+
+ import resource
60+
+ def _rlimit_nofile():
61+
+ return resource.getrlimit(resource.RLIMIT_NOFILE)
62+
+except ImportError:
63+
+ def _rlimit_nofile():
64+
+ return (256, 256)
65+
+
66+
+try:
67+
+ import multiprocessing
68+
+except ImportError:
69+
+ multiprocessing = None
70+
+
71+
+from command import Command, MirrorSafeCommand
72+
+
73+
+class Dumpjson(Command, MirrorSafeCommand):
74+
+ common = True
75+
+ helpSummary = "Export json file with sources"
76+
+ helpUsage = """
77+
+%prog [<project>...]
78+
+"""
79+
+ helpDescription = """
80+
+"""
81+
+
82+
+ def Execute(self, opt, args):
83+
+ all_projects = self.GetProjects(args, missing_ok=True, submodules_ok=False)
84+
+
85+
+ import json
86+
+ data = {
87+
+ p.name: {
88+
+ "url": p.remote.url,
89+
+ "relpath": p.relpath,
90+
+ "groups": p.groups,
91+
+ "revisionExpr": p.revisionExpr,
92+
+ "rev": p._LsRemote(p.revisionExpr).split('\t')[0],
93+
+ "linkfiles": [
94+
+ { "src_rel_to_dest": l.src_rel_to_dest,
95+
+ "dest": l.dest,
96+
+ }
97+
+ for l in p.linkfiles
98+
+ ],
99+
+ "copyfiles": [
100+
+ { "src": c.src,
101+
+ "dest": c.dest,
102+
+ }
103+
+ for c in p.copyfiles
104+
+ ],
105+
+ }
106+
+ for p in all_projects
107+
+ };
108+
+ print(json.dumps(data))
109+
--
110+
2.44.0
111+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 333fc9d324640adb94e2ec7b51ab24268a3084d4 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Janne=20He=C3=9F?= <janne@hess.ooo>
3+
Date: Sun, 27 Oct 2019 11:31:40 +0100
4+
Subject: [PATCH 03/16] nix: Retry 20 times if the http request fails
5+
6+
---
7+
subcmds/nix.py | 9 +++++++--
8+
1 file changed, 7 insertions(+), 2 deletions(-)
9+
10+
diff --git a/subcmds/nix.py b/subcmds/nix.py
11+
index f113ede..fd7c188 100644
12+
--- a/subcmds/nix.py
13+
+++ b/subcmds/nix.py
14+
@@ -53,6 +53,7 @@ except ImportError:
15+
multiprocessing = None
16+
17+
from command import Command, MirrorSafeCommand
18+
+from itertools import repeat
19+
20+
class Nix(Command, MirrorSafeCommand):
21+
common = True
22+
@@ -93,8 +94,12 @@ class Nix(Command, MirrorSafeCommand):
23+
oS += ' ref = "' + p.revisionExpr.split('/')[-1] + '";\n'
24+
else:
25+
oS += ' ref = "' + p.revisionExpr + '";\n'
26+
- oS += ' rev = "' + p._LsRemote(p.revisionExpr).split('\t')[0] + '";\n'
27+
+ while repeat(None, 20):
28+
+ raw_rev = p._LsRemote(p.revisionExpr)
29+
+ if raw_rev != None:
30+
+ break
31+
+ oS += ' rev = "' + raw_rev.split('\t')[0] + '";\n'
32+
oS += ' name = "' + p.relpath.replace('/', '=') + '";\n'
33+
oS += ' })\n'
34+
oS += '];\n}'
35+
- print(oS)
36+
\ No newline at end of file
37+
+ print(oS)
38+
--
39+
2.44.0
40+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 991502c597e3d3c9d5b25fcf08ecd216fdba107b Mon Sep 17 00:00:00 2001
2+
From: ajs124 <git@ajs124.de>
3+
Date: Tue, 3 Dec 2019 20:23:01 +0100
4+
Subject: [PATCH 04/16] fml
5+
6+
---
7+
subcmds/nix.py | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/subcmds/nix.py b/subcmds/nix.py
11+
index fd7c188..ad1f19f 100644
12+
--- a/subcmds/nix.py
13+
+++ b/subcmds/nix.py
14+
@@ -98,7 +98,7 @@ class Nix(Command, MirrorSafeCommand):
15+
raw_rev = p._LsRemote(p.revisionExpr)
16+
if raw_rev != None:
17+
break
18+
- oS += ' rev = "' + raw_rev.split('\t')[0] + '";\n'
19+
+ # oS += ' rev = "' + raw_rev.split('\t')[0] + '";\n'
20+
oS += ' name = "' + p.relpath.replace('/', '=') + '";\n'
21+
oS += ' })\n'
22+
oS += '];\n}'
23+
--
24+
2.44.0
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
From 07d83a29279874566234b2a3aed6fc270e5f9b8b Mon Sep 17 00:00:00 2001
2+
From: Daniel Fullmer <danielrf12@gmail.com>
3+
Date: Tue, 3 Dec 2019 16:56:27 -0500
4+
Subject: [PATCH 05/16] dumpjson: Sort json output by keys for reproducibility
5+
6+
---
7+
subcmds/dumpjson.py | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/subcmds/dumpjson.py b/subcmds/dumpjson.py
11+
index a09885d..8997c27 100644
12+
--- a/subcmds/dumpjson.py
13+
+++ b/subcmds/dumpjson.py
14+
@@ -89,4 +89,4 @@ class Dumpjson(Command, MirrorSafeCommand):
15+
}
16+
for p in all_projects
17+
};
18+
- print(json.dumps(data))
19+
+ print(json.dumps(data, sort_keys=True))
20+
--
21+
2.44.0
22+

0 commit comments

Comments
 (0)