@@ -18,6 +18,11 @@ import (
1818// outputs the source directory with the checkout.
1919var 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+
2126type 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+
3145func 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+
79108var repoMu sync.Mutex
80109
81110func UseLinuxRepo (ctx * aflow.Context , fn func (string , vcs.Repo ) error ) error {
0 commit comments