Skip to content

Commit f790098

Browse files
committed
pkg/aflow/action/kernel: add CheckoutScratch action
The action checks out a temp dir for code edits and patch testing.
1 parent 1aa9227 commit f790098

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

pkg/aflow/action/kernel/checkout.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
// outputs the source directory with the checkout.
1919
var Checkout = aflow.NewFuncAction("kernel-checkouter", checkout)
2020

21+
// Checkout action checks out the Linux kernel on the given commit
22+
// in a private temp dir that lives only for the duration of the workflow.
23+
// It's supposed to be used for code edits.
24+
var CheckoutScratch = aflow.NewFuncAction("kernel-scratch-checkouter", checkoutScratch)
25+
2126
type checkoutArgs struct {
2227
KernelRepo string
2328
KernelCommit string
@@ -28,6 +33,15 @@ type checkoutResult struct {
2833
KernelSrc string
2934
}
3035

36+
type checkoutScratchArgs struct {
37+
KernelSrc string
38+
}
39+
40+
type checkoutScratchResult struct {
41+
// Temp dir with the checked out sources.
42+
KernelScratchSrc string
43+
}
44+
3145
func checkout(ctx *aflow.Context, args checkoutArgs) (checkoutResult, error) {
3246
var res checkoutResult
3347
err := UseLinuxRepo(ctx, func(kernelRepoDir string, repo vcs.Repo) error {
@@ -58,24 +72,39 @@ func checkout(ctx *aflow.Context, args checkoutArgs) (checkoutResult, error) {
5872
}
5973
}
6074
}
61-
if _, err := osutil.RunCmd(time.Hour, dir, "git", "init"); err != nil {
62-
return err
63-
}
64-
if _, err := osutil.RunCmd(time.Hour, dir, "git", "remote", "add", "origin", kernelRepoDir); err != nil {
65-
return err
66-
}
67-
if _, err := osutil.RunCmd(time.Hour, dir, "git", "pull", "origin", "HEAD", "--depth=1",
68-
"--allow-unrelated-histories"); err != nil {
69-
return err
70-
}
71-
return nil
75+
return shallowGitClone(dir, kernelRepoDir)
7276
})
7377
res.KernelSrc = dir
7478
return err
7579
})
7680
return res, err
7781
}
7882

83+
func checkoutScratch(ctx *aflow.Context, args checkoutScratchArgs) (checkoutScratchResult, error) {
84+
dir, err := ctx.TempDir()
85+
if err != nil {
86+
return checkoutScratchResult{}, err
87+
}
88+
if err := shallowGitClone(dir, args.KernelSrc); err != nil {
89+
return checkoutScratchResult{}, err
90+
}
91+
return checkoutScratchResult{dir}, nil
92+
}
93+
94+
func shallowGitClone(dir, remoteDir string) error {
95+
if _, err := osutil.RunCmd(time.Hour, dir, "git", "init"); err != nil {
96+
return err
97+
}
98+
if _, err := osutil.RunCmd(time.Hour, dir, "git", "remote", "add", "origin", remoteDir); err != nil {
99+
return err
100+
}
101+
if _, err := osutil.RunCmd(time.Hour, dir, "git", "pull", "origin", "HEAD", "--depth=1",
102+
"--allow-unrelated-histories"); err != nil {
103+
return err
104+
}
105+
return nil
106+
}
107+
79108
var repoMu sync.Mutex
80109

81110
func UseLinuxRepo(ctx *aflow.Context, fn func(string, vcs.Repo) error) error {

pkg/aflow/flow/patching/patching.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Inputs struct {
3636
type Outputs struct {
3737
PatchDescription string
3838
PatchDiff string
39+
KernelScratchSrc string // it's unused for now, but should be used by codeeditor tool later
3940
}
4041

4142
func init() {
@@ -61,6 +62,7 @@ func init() {
6162
Prompt: debuggingPrompt,
6263
Tools: tools,
6364
},
65+
kernel.CheckoutScratch,
6466
&aflow.LLMAgent{
6567
Name: "diff-generator",
6668
Model: aflow.BestExpensiveModel,

0 commit comments

Comments
 (0)