Skip to content

Commit 3263f8e

Browse files
taidaiimeta-codesync[bot]
authored andcommitted
grepo: get grepo projects as submodules in python
Summary: Plug into exisiting python submodule infrastructure for grepo projects, since grepo project is a similar concept that can benefit from implementations like `workingparentnode()`. Once `parsesubmodules()` returns grepo submodules, the existing pipeline handles the rest: `submodulestatus()` compares manifest nodes against working copy nodes, and `workingfilectx.data()` generates `Subproject commit HASH` content. Reviewed By: quark-zju Differential Revision: D102908297 fbshipit-source-id: c738a0826b30588ae5114aee6a56bc143abdf207
1 parent 65bde93 commit 3263f8e

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

eden/scm/sapling/git.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ def parsesubmodules(ctx):
884884
repo.ui.note(_("submodules are disabled via git.submodules\n"))
885885
return {}
886886
if ".gitmodules" not in ctx:
887+
from . import grepo
888+
889+
if grepo.GREPO_REQUIREMENT in repo.requirements:
890+
return grepo.getgreposubmodules(ctx, repo)
887891
return {}
888892

889893
data = ctx[".gitmodules"].data()
@@ -1198,9 +1202,12 @@ def workingparentnode(self):
11981202
repopath = self.parentrepo.wvfs.join(self.path)
11991203
dotgit_path = os.path.join(repopath, ".git")
12001204

1201-
if DOTGIT_REQUIREMENT in self.parentrepo.requirements and os.path.exists(
1202-
dotgit_path
1203-
):
1205+
from .grepo import GREPO_REQUIREMENT
1206+
1207+
if (
1208+
DOTGIT_REQUIREMENT in self.parentrepo.requirements
1209+
or GREPO_REQUIREMENT in self.parentrepo.requirements
1210+
) and os.path.exists(dotgit_path):
12041211
# dotgit repo, .git/sl not yet initialized.
12051212
# read git HEAD directly.
12061213
git = bindings.gitcompat.BareGit(dotgit_path, self.parentrepo.ui._rcfg)

eden/scm/sapling/grepo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,29 @@
1212
https://gerrit.googlesource.com/git-repo
1313
"""
1414

15+
import weakref
16+
from typing import List
17+
18+
from .git import Submodule
19+
1520
# Whether to be compatible with `.repo/`.
1621
GREPO_REQUIREMENT = "grepo"
22+
23+
24+
def getgreposubmodules(ctx, repo) -> List[Submodule]:
25+
"""Synthesize Submodule objects from the parent manifest for Grepo repos.
26+
27+
Conceptually, grepo projects are very similar to Git submodules. Rust tree
28+
resolver synthesizes them into tree manifest as GitSubmodule (flag "m" in Python).
29+
This method synthesizes them into Python Submodule objects to plug into
30+
existing infrastructure.
31+
"""
32+
parent = ctx.p1() if ctx.node() is None else ctx
33+
mf = parent.manifest()
34+
submodules = []
35+
for path in mf:
36+
if mf.flags(path) == "m":
37+
submodules.append(
38+
Submodule(path, "", path, True, weakref.proxy(repo)),
39+
)
40+
return submodules

eden/scm/tests/test-dotrepo.t

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ modified outer project is reported by status
111111
Diff shows subproject commit change for the outer project:
112112

113113
$ sl diff
114-
abort: Is a directory: $TESTTMP/repodir/vendor/a
115-
[255]
114+
diff -r * vendor/a (glob)
115+
--- a/vendor/a * (glob)
116+
+++ b/vendor/a * (glob)
117+
@@ -1,1 +1,1 @@
118+
-Subproject commit ac4ea71567e4779db728eebfc962382b53064bdb
119+
+Subproject commit 8b78e5ec15214e009eb98624ee4dda34520d9720
116120

117121
Modified nested (overlapping) project is reported by status:
118122

@@ -127,8 +131,12 @@ Modified nested (overlapping) project is reported by status:
127131
Exact-path diff also works for the nested overlapping project:
128132

129133
$ sl diff vendor/a/sub/c
130-
abort: Is a directory: $TESTTMP/repodir/vendor/a/sub/c
131-
[255]
134+
diff -r * vendor/a/sub/c (glob)
135+
--- a/vendor/a/sub/c * (glob)
136+
+++ b/vendor/a/sub/c * (glob)
137+
@@ -1,1 +1,1 @@
138+
-Subproject commit 30c3ba4e8b4dced473cce4f5d10ced2eecbd2515
139+
+Subproject commit 9f2c189e3840b5857f220136620130d40f5e71ce
132140

133141
Modified non-overlapping project is reported by status:
134142

@@ -144,5 +152,9 @@ Modified non-overlapping project is reported by status:
144152
Exact-path diff also works for the non-overlapping project:
145153

146154
$ sl diff frameworks/b
147-
abort: Is a directory: $TESTTMP/repodir/frameworks/b
148-
[255]
155+
diff -r * frameworks/b (glob)
156+
--- a/frameworks/b * (glob)
157+
+++ b/frameworks/b * (glob)
158+
@@ -1,1 +1,1 @@
159+
-Subproject commit 6a9d13442cc0deb7f2b531a00ac679f62d09edf3
160+
+Subproject commit 96287d65976c48a2d3046495e3089baeb388a671

0 commit comments

Comments
 (0)