122 """
123 Given an input of a mirrored dep,
124 compare to the mapping of deps to their upstream
125 in DEPS and find a common ancestor
126 commit SHA value.
127
128 This is done by first cloning the mirrored dep,
129 then a branch which tracks the upstream.
130 From there, git merge-base operates using the HEAD
131 commit SHA of the upstream branch and the pinned
132 SHA value of the mirrored branch
133 """
134
135
136
137 dep_name = dep[0].split('/')[-1].split('.')[0]
138 if UPSTREAM_PREFIX + dep_name not in deps_list:
139 print(
'did not find dep: ' + dep_name)
140 return None
141 try:
142
143 upstream = deps_list.get(UPSTREAM_PREFIX + dep_name)
144 temp_dep_dir = DEP_CLONE_DIR + '/' + dep_name
145
146 subprocess.check_output(['git', 'clone', '--quiet', '--', dep[0], dep_name], cwd=DEP_CLONE_DIR)
147
148
149 print(
'attempting to add upstream remote from: {upstream}'.
format(upstream=upstream))
150 subprocess.check_output(['git', 'remote', 'add', 'upstream', upstream], cwd=temp_dep_dir)
151 subprocess.check_output(['git', 'fetch', '--quiet', 'upstream'], cwd=temp_dep_dir)
152
153 default_branch = subprocess.check_output(
154 'git remote show upstream ' + "| sed -n \'/HEAD branch/s/.*: //p\'",
155 cwd=temp_dep_dir,
156 shell=True
157 )
159 default_branch = default_branch.strip()
160
161
162 subprocess.check_output([
163 'git', 'checkout', '--force', '-b', 'upstream', '--track', 'upstream/' + default_branch
164 ],
165 cwd=temp_dep_dir)
166
167 commit = subprocess.check_output(
168 'git for-each-ref ' + "--format=\'%(objectname:short)\' refs/heads/upstream",
169 cwd=temp_dep_dir,
170 shell=True
171 )
173 commit = commit.strip()
174
175
176 ancestor_commit = subprocess.check_output(
177 'git merge-base {commit} {depUrl}'.
format(commit=commit, depUrl=dep[1]),
178 cwd=temp_dep_dir,
179 shell=True
180 )
182 ancestor_commit = ancestor_commit.strip()
183 print(
'Ancestor commit: ' + ancestor_commit)
184 return ancestor_commit, upstream
185 except subprocess.CalledProcessError as error:
187 "Subprocess command '{0}' failed with exit code: {1}.".
format(
188 error.cmd, str(error.returncode)
189 )
190 )
191 if error.output:
192 print(
"Subprocess error output: '{0}'".
format(error.output))
193 return None
194
195
uint32_t uint32_t * format
def byte_str_decode(str_or_bytes)