@@ -79,27 +79,20 @@ def extract_deps(deps_file):
7979 continue
8080
8181 dep_split = dep .rsplit ('@' , 1 )
82- ancestor_result = get_common_ancestor ([dep_split [0 ], dep_split [1 ]],
83- deps_list )
82+ ancestor_result = get_common_ancestor ([dep_split [0 ], dep_split [1 ]], deps_list )
8483 if ancestor_result :
8584 filtered_osv_deps .append ({
8685 'package' : {'name' : ancestor_result [1 ], 'commit' : ancestor_result [0 ]}
8786 })
8887
8988 try :
9089 # Clean up cloned upstream dependency directory.
91- shutil .rmtree (
92- DEP_CLONE_DIR
93- ) # Use shutil.rmtree since dir could be non-empty.
90+ shutil .rmtree (DEP_CLONE_DIR ) # Use shutil.rmtree since dir could be non-empty.
9491 except OSError as clone_dir_error :
95- print (
96- 'Error cleaning up clone directory: %s : %s' %
97- (DEP_CLONE_DIR , clone_dir_error .strerror )
98- )
92+ print ('Error cleaning up clone directory: %s : %s' % (DEP_CLONE_DIR , clone_dir_error .strerror ))
9993
10094 osv_result = {
101- 'packageSource' : {'path' : deps_file , 'type' : 'lockfile' },
102- 'packages' : filtered_osv_deps
95+ 'packageSource' : {'path' : deps_file , 'type' : 'lockfile' }, 'packages' : filtered_osv_deps
10396 }
10497 return osv_result
10598
@@ -150,19 +143,12 @@ def get_common_ancestor(dep, deps_list):
150143 upstream = deps_list .get (UPSTREAM_PREFIX + dep_name )
151144 temp_dep_dir = DEP_CLONE_DIR + '/' + dep_name
152145 # Clone dependency from mirror.
153- subprocess .check_output (['git' , 'clone' , '--quiet' , '--' , dep [0 ], dep_name ],
154- cwd = DEP_CLONE_DIR )
146+ subprocess .check_output (['git' , 'clone' , '--quiet' , '--' , dep [0 ], dep_name ], cwd = DEP_CLONE_DIR )
155147
156148 # Create branch that will track the upstream dep.
157- print (
158- 'attempting to add upstream remote from: {upstream}' .format (
159- upstream = upstream
160- )
161- )
162- subprocess .check_output (['git' , 'remote' , 'add' , 'upstream' , upstream ],
163- cwd = temp_dep_dir )
164- subprocess .check_output (['git' , 'fetch' , '--quiet' , 'upstream' ],
165- cwd = temp_dep_dir )
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 )
166152 # Get name of the default branch for upstream (e.g. main/master/etc.).
167153 default_branch = subprocess .check_output (
168154 'git remote show upstream ' + "| sed -n \' /HEAD branch/s/.*: //p\' " ,
@@ -174,14 +160,12 @@ def get_common_ancestor(dep, deps_list):
174160
175161 # Make upstream branch track the upstream dep.
176162 subprocess .check_output ([
177- 'git' , 'checkout' , '--force' , '-b' , 'upstream' , '--track' ,
178- 'upstream/' + default_branch
163+ 'git' , 'checkout' , '--force' , '-b' , 'upstream' , '--track' , 'upstream/' + default_branch
179164 ],
180165 cwd = temp_dep_dir )
181166 # Get the most recent commit from default branch of upstream.
182167 commit = subprocess .check_output (
183- 'git for-each-ref ' +
184- "--format=\' %(objectname:short)\' refs/heads/upstream" ,
168+ 'git for-each-ref ' + "--format=\' %(objectname:short)\' refs/heads/upstream" ,
185169 cwd = temp_dep_dir ,
186170 shell = True
187171 )
@@ -211,9 +195,7 @@ def get_common_ancestor(dep, deps_list):
211195
212196def parse_args (args ):
213197 args = args [1 :]
214- parser = argparse .ArgumentParser (
215- description = 'A script to find common ancestor commit SHAs'
216- )
198+ parser = argparse .ArgumentParser (description = 'A script to find common ancestor commit SHAs' )
217199
218200 parser .add_argument (
219201 '--deps' ,
0 commit comments