@@ -313,28 +313,16 @@ def stage_payload(request, worktree, account_home):
313313 repo = worktree / "repo"
314314 if repo .is_symlink () or not repo .is_dir ():
315315 raise SupervisorError ("existing task-disk repository is unavailable or redirected" )
316- top = subprocess .run (
317- ["git" , "-C" , str (repo ), "rev-parse" , "--show-toplevel" ],
318- stdin = subprocess .DEVNULL , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
319- timeout = GIT_HEAD_TIMEOUT , check = False ,
320- )
316+ top = git_in (repo , "rev-parse" , "--show-toplevel" , timeout = GIT_HEAD_TIMEOUT )
321317 if top .returncode != 0 or Path (top .stdout .decode ().strip ()).resolve () != repo .resolve ():
322318 raise SupervisorError ("existing task-disk repository is not the exact repository root" )
323- lineage = subprocess .run (
324- [
325- "git" , "-C" , str (repo ), "merge-base" , "--is-ancestor" ,
326- request ["repository_generation" ], "HEAD" ,
327- ],
328- stdin = subprocess .DEVNULL , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
329- timeout = GIT_HEAD_TIMEOUT , check = False ,
319+ lineage = git_in (
320+ repo , "merge-base" , "--is-ancestor" ,
321+ request ["repository_generation" ], "HEAD" , timeout = GIT_HEAD_TIMEOUT ,
330322 )
331323 if lineage .returncode != 0 :
332324 raise SupervisorError ("existing task-disk repository lost its dispatched lineage" )
333- readable = subprocess .run (
334- ["git" , "-C" , str (repo ), "status" , "--porcelain" ],
335- stdin = subprocess .DEVNULL , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
336- timeout = GIT_STATUS_TIMEOUT , check = False ,
337- )
325+ readable = git_in (repo , "status" , "--porcelain" , timeout = GIT_STATUS_TIMEOUT )
338326 if readable .returncode != 0 :
339327 raise SupervisorError ("existing task-disk working tree is unreadable" )
340328 return repo
@@ -368,11 +356,7 @@ def stage_payload(request, worktree, account_home):
368356 clone .stderr .decode ("utf-8" , errors = "replace" )[- 500 :]
369357 )
370358 )
371- head = subprocess .run (
372- ["git" , "-C" , str (repo ), "rev-parse" , "HEAD" ],
373- stdin = subprocess .DEVNULL , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
374- timeout = GIT_HEAD_TIMEOUT , check = False ,
375- )
359+ head = git_in (repo , "rev-parse" , "HEAD" , timeout = GIT_HEAD_TIMEOUT )
376360 if head .returncode != 0 or head .stdout .decode ().strip () != request ["repository_generation" ]:
377361 raise SupervisorError ("staged repository head differs from the bound repository generation" )
378362 if request .get ("worker_role" ) == "no-mistakes" :
@@ -541,11 +525,12 @@ def prepare_no_mistakes_execution(worktree, worktree_root, account_home, brief):
541525 return {}
542526
543527
544- def git_in (repo , * arguments , timeout = BUNDLE_CREATE_TIMEOUT ):
528+ def git_in (repo , * arguments , timeout = BUNDLE_CREATE_TIMEOUT , input_bytes = None , env = None ):
545529 return subprocess .run (
546530 ["git" , "-c" , "safe.directory={}" .format (repo ), "-C" , str (repo ), * arguments ],
547- stdin = subprocess .DEVNULL , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
548- timeout = timeout , check = False ,
531+ input = input_bytes , stdin = subprocess .DEVNULL if input_bytes is None else None ,
532+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = timeout , check = False ,
533+ env = env ,
549534 )
550535
551536
@@ -646,9 +631,9 @@ def _scratch_artifacts(repo):
646631
647632
648633def _hash_blob (repo , body ):
649- result = subprocess . run (
650- [ "git" , "-C" , str ( repo ) , "hash-object" , "-w" , "--stdin" ], input = body ,
651- stdout = subprocess . PIPE , stderr = subprocess . PIPE , timeout = GIT_HEAD_TIMEOUT , check = False ,
634+ result = git_in (
635+ repo , "hash-object" , "-w" , "--stdin" , input_bytes = body ,
636+ timeout = GIT_HEAD_TIMEOUT ,
652637 )
653638 if result .returncode != 0 :
654639 raise SupervisorError ("returned artifact could not be stored in the repository" )
@@ -659,9 +644,8 @@ def _return_commit(repo, base, artifacts, request):
659644 entries = []
660645 for name , body in sorted (artifacts .items ()):
661646 entries .append ("100644 blob {}\t {}\n " .format (_hash_blob (repo , body ), name ))
662- tree = subprocess .run (
663- ["git" , "-C" , str (repo ), "mktree" ], input = "" .join (entries ).encode (),
664- stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = GIT_HEAD_TIMEOUT , check = False ,
647+ tree = git_in (
648+ repo , "mktree" , input_bytes = "" .join (entries ).encode (), timeout = GIT_HEAD_TIMEOUT ,
665649 )
666650 if tree .returncode != 0 :
667651 raise SupervisorError ("returned artifact tree could not be created" )
@@ -674,11 +658,10 @@ def _return_commit(repo, base, artifacts, request):
674658 "GIT_AUTHOR_DATE" : "@0 +0000" ,
675659 "GIT_COMMITTER_DATE" : "@0 +0000" ,
676660 })
677- committed = subprocess .run (
678- ["git" , "-C" , str (repo ), "commit-tree" , tree .stdout .decode ().strip (), "-p" , base ],
679- input = ("Firstmate worker return {}\n " .format (request ["request_digest" ])).encode (),
680- stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = GIT_HEAD_TIMEOUT ,
681- check = False , env = environment ,
661+ committed = git_in (
662+ repo , "commit-tree" , tree .stdout .decode ().strip (), "-p" , base ,
663+ input_bytes = ("Firstmate worker return {}\n " .format (request ["request_digest" ])).encode (),
664+ timeout = GIT_HEAD_TIMEOUT , env = environment ,
682665 )
683666 if committed .returncode != 0 :
684667 raise SupervisorError ("returned artifact commit could not be created" )
0 commit comments