diff options
Diffstat (limited to 'tools/scripts/git_submodule.py')
-rw-r--r-- | tools/scripts/git_submodule.py | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/tools/scripts/git_submodule.py b/tools/scripts/git_submodule.py index f3508eac9..bc311f97b 100644 --- a/tools/scripts/git_submodule.py +++ b/tools/scripts/git_submodule.py @@ -90,12 +90,9 @@ class DEPSParser: continue if len(rev) == 40: # Length of a git shasum - submodule.shasum = rev + submodule.ref = rev else: - # Try to find out the git branch. - branchMatch = re.search('/branches/((chromium/)?[^/]+)', repo) - if branchMatch: - submodule.ref = 'refs/branch-heads/' + branchMatch.group(1) + sys.exit("Invalid shasum: " + str(rev)) submodules.append(submodule) return submodules @@ -109,12 +106,11 @@ class DEPSParser: return submodules class Submodule: - def __init__(self, path='', url='', shasum='', os=[], ref=''): + def __init__(self, path='', url='', ref='', os=[]): self.path = path self.url = url - self.shasum = shasum + self.ref = ref self.os = os - self.ref = '' def matchesOS(self): if not self.os: @@ -139,35 +135,34 @@ class Submodule: def findShaAndCheckout(self): oldCwd = os.getcwd() os.chdir(self.path) - error = 0 - if self.ref: - # Fetch the ref we parsed from the DEPS file. - error = subprocessCall(['git', 'fetch', 'origin', self.ref]) - if error != 0: - print('ERROR: Could not fetch from upstream branch ' + self.ref) - return error - error = subprocessCall(['git', 'checkout', 'FETCH_HEAD']); + # Fetch the shasum we parsed from the DEPS file. + error = subprocessCall(['git', 'fetch', 'origin', self.ref]) + if error != 0: + print('ERROR: Could not fetch ' + self.ref + ' from upstream origin.') + return error + + error = subprocessCall(['git', 'checkout', 'FETCH_HEAD']); current_shasum = subprocessCheckOutput(['git', 'rev-parse', 'HEAD']).strip() current_tag = subprocessCheckOutput(['git', 'name-rev', '--tags', '--name-only', current_shasum]).strip() if current_tag == resolver.currentVersion(): # We checked out a tagged version of chromium. - self.shasum = current_shasum + self.ref = current_shasum - if not self.shasum: + if not self.ref: # No shasum could be deduced, use the submodule shasum. os.chdir(oldCwd) line = subprocessCheckOutput(['git', 'submodule', 'status', self.path]) os.chdir(self.path) line = line.lstrip(' -') - self.shasum = line.split(' ')[0] + self.ref = line.split(' ')[0] - if not self.shasum.startswith(current_shasum): + if not self.ref.startswith(current_shasum): # In case HEAD differs check out the actual shasum we require. subprocessCall(['git', 'fetch']) - error = subprocessCall(['git', 'checkout', self.shasum]) + error = subprocessCall(['git', 'checkout', self.ref]) os.chdir(oldCwd) return error @@ -207,10 +202,10 @@ class Submodule: subprocessCall(['git', 'submodule', 'init', self.path]) subprocessCall(['git', 'submodule', 'update', self.path]) - if self.findShaAndCheckout() != 0: - sys.exit("!!! initialization failed !!!") - if '3rdparty_upstream' in os.path.abspath(self.path): + if self.findShaAndCheckout() != 0: + sys.exit("!!! initialization failed !!!") + # Add baseline commit for upstream repository to be able to reset. os.chdir(self.path) commit = subprocessCheckOutput(['git', 'rev-list', '--max-count=1', 'HEAD']) @@ -238,8 +233,7 @@ class Submodule: submodules = resolver.readSubmodules() print 'DEPS file provides the following submodules:' for submodule in submodules: - submodule_ref = submodule.shasum - print '{:<80}'.format(submodule.path) + '{:<120}'.format(submodule.url) + submodule_ref + print '{:<80}'.format(submodule.path) + '{:<120}'.format(submodule.url) + submodule.ref else: # Try .gitmodules since no ref has been specified if not os.path.isfile('.gitmodules'): return [] @@ -274,6 +268,5 @@ class Submodule: submodules = self.readSubmodules() for submodule in submodules: submodule.initialize() - if self.ref: - subprocessCall(['git', 'commit', '-a', '--amend', '--no-edit']) + subprocessCall(['git', 'commit', '-a', '--amend', '--no-edit']) os.chdir(oldCwd) |