1 #! /usr/bin/env python3
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 assert __name__
!= "__main__"
9 Any time we vendor[1] from an external git repo, we want to keep a record of the csets
12 This script leaves a record of the merge-base reference tip and cherry-picks that we pull
13 into Gecko. (such as gfx/angle/cherry_picks.txt)
28 def run_checked(*args
, **kwargs
):
31 return subprocess
.run(args
, check
=True, **kwargs
)
37 def record_cherry_picks(dir_in_gecko
, merge_base_origin
):
38 # merge_base_origin is not always 'origin'!
39 base_merge_base_from
= Path(dir_in_gecko
, "MERGE_BASE").read_text().split("\n")[0]
40 merge_base_from
= merge_base_origin
+ "/" + base_merge_base_from
42 assert "/" in merge_base_from
, "Please specify a reference tip from a remote."
43 log_path
= Path(dir_in_gecko
, "cherry_picks.txt")
44 print_now("Logging cherry picks to {}.".format(log_path
))
48 "git", "merge-base", "HEAD", merge_base_from
, stdout
=subprocess
.PIPE
53 merge_base_readable
= (
58 "--format=commit %H %cd",
60 stdout
=subprocess
.PIPE
,
66 mb_info
= run_checked(
72 "{}~1..{}".format(merge_base
, merge_base
),
73 stdout
=subprocess
.PIPE
,
75 cherries
= run_checked(
82 stdout
=subprocess
.PIPE
,
85 with
open(log_path
, "wb") as f
:
87 f
.write(b
"\nAbove: cherries picked")
88 f
.write(b
"\n" + (b
"=" * 80))
89 f
.write(b
"\nBelow: merge base from: " + merge_base_from
.encode())
93 # The below supports only a single commit-alert task. If/when we add another task, this
94 # will need to be improved.
95 print_now("Updating moz.yaml")
96 moz_yaml_file
= Path(dir_in_gecko
, "moz.yaml")
97 with
open(moz_yaml_file
, "r") as f
:
98 moz_yaml_contents
= f
.readlines()
99 with
open(moz_yaml_file
, "wb") as f
:
100 for line
in moz_yaml_contents
:
103 return line
[0 : line
.index(": ") + 2].encode()
105 if "branch: " in line
:
106 f
.write(prefix() + base_merge_base_from
.encode() + b
"\n")
107 elif "release: " in line
:
108 f
.write(prefix() + merge_base_readable
.encode() + b
"\n")
109 elif "revision: " in line
:
110 f
.write(prefix() + merge_base
.encode() + b
"\n")
112 f
.write(line
.encode())