diff options
author | Andras Becsi <andras.becsi@digia.com> | 2014-09-10 19:48:56 +0200 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2014-09-11 12:22:21 +0200 |
commit | d741059422ebeb1613c767bdd318c87228ec2160 (patch) | |
tree | fca80cef23e13d828a65124f652bdfcb1a223535 /tools/scripts/git_submodule.py | |
parent | de2d1a6d8ab61db7e6994c414a08f1a6ba7afb9b (diff) | |
download | qtwebengine-d741059422ebeb1613c767bdd318c87228ec2160.tar.gz |
init-repository: clean up upstream repository checkout even more
Remove unneeded codepaths now that we can trust the git shasums
found in the .DEPS.git file.
No need for parsing and verifying remote branches, we can simply
fetch the specified sha1 from origin.
This patch also unifies the 'shasum' and 'ref' members of the
Submodule python class since the 'ref' member can represent
both chromium's version tag and the sha1s of the submodules,
there is no need for a separate codepath for these.
Change-Id: I1300b5b74f4d2e6984943570963b2f813b1b1679
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
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) |