@@ -165,11 +165,20 @@ def choose_submission(conn, cf_ids):
165165 return commitfest_id , submission_id
166166
167167
168- def update_patchbase_tree (repo_dir ):
169- """Pull changes from PostgreSQL master and return the HEAD commit ID ."""
168+ def checkout_patchbase_branch (repo_dir , branch ):
169+ """Switch patchbase repo to a given branch ."""
170170 subprocess .call (
171- "cd %s && git checkout . -q > /dev/null && git clean -fd > /dev/null && git checkout -q master && git pull -q"
172- % repo_dir ,
171+ "cd %s && git checkout . -q > /dev/null && git clean -fd > /dev/null && git checkout -q %s"
172+ % (repo_dir , branch ),
173+ shell = True ,
174+ )
175+
176+
177+ def update_patchbase_tree (repo_dir , branch ):
178+ """Switch branch and pull changes from tracked remote."""
179+ checkout_patchbase_branch (repo_dir , branch )
180+ subprocess .call (
181+ "cd %s && git pull -q" % (repo_dir , branch ),
173182 shell = True ,
174183 )
175184
@@ -310,6 +319,29 @@ def update_submission(conn, message_id, commit_id, commitfest_id, submission_id)
310319 )
311320
312321
322+ def mirror_branch (branch ):
323+ template_repo_path = patchburner_ctl ("template-repo-path" ).strip ()
324+
325+ # Everything else in this file assumes that
326+ # cfbot_periodic_minutely.py acquired the "big lock" while
327+ # applying patches etc, but this function is reached by cfbot
328+ # workers, and needs interlocking so it does that explicitly here.
329+ with cfbot_util .lock ():
330+ logging .info ("updating branch %s in template repo" , branch )
331+ update_patchbase_tree (template_repo_path , branch )
332+ if cfbot_config .GIT_REMOTE_NAME :
333+ logging .info ("pushing branch %s (automatic mirror)" , branch )
334+ my_env = os .environ .copy ()
335+ my_env ["GIT_SSH_COMMAND" ] = cfbot_config .GIT_SSH_COMMAND
336+ subprocess .check_call (
337+ "cd %s && git push -q -f %s %s"
338+ % (template_repo_path , cfbot_config .GIT_REMOTE_NAME , branch ),
339+ env = my_env ,
340+ shell = True ,
341+ stderr = subprocess .DEVNULL ,
342+ )
343+
344+
313345def reset_repo_to_good_master_commit (conn , repo_path ):
314346 # find the most recent commit ID that succeeded on master
315347 cursor = conn .cursor ()
@@ -324,16 +356,18 @@ def reset_repo_to_good_master_commit(conn, repo_path):
324356 (good_commit_id ,) = result
325357 else :
326358 good_commit_id = "origin/master"
359+ logging .info ("selected master commit %s as base" , good_commit_id )
327360
361+ checkout_patchbase_branch (repo_path , "master" )
328362 commit_id = get_commit_id (repo_path )
329- if commit_id != good_commit_id :
330- logging .info ("updating repo to find last good master commit %s" , good_commit_id )
331- update_patchbase_tree (repo_path )
332363
333- reset_commit_id (repo_path , good_commit_id )
334- commit_id = get_commit_id (repo_path )
335- if good_commit_id != "origin/master" :
336- assert commit_id == good_commit_id
364+ if commit_id != good_commit_id :
365+ logging .info ("updating template repo" )
366+ update_patchbase_tree (repo_path , "master" )
367+ reset_commit_id (repo_path , good_commit_id )
368+ commit_id = get_commit_id (repo_path )
369+ if good_commit_id != "origin/master" :
370+ assert commit_id == good_commit_id
337371
338372 return commit_id
339373
0 commit comments