Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: git_footers.py

Issue 552403003: Expand git-footers to read the svn position for any trunk path in any repo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import re 7 import re
8 import sys 8 import sys
9 9
10 from collections import defaultdict 10 from collections import defaultdict
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 key = normalize_name(key) 50 key = normalize_name(key)
51 values = footers[key] 51 values = footers[key]
52 assert len(values) <= 1, 'Multiple %s footers' % key 52 assert len(values) <= 1, 'Multiple %s footers' % key
53 if values: 53 if values:
54 return values[0] 54 return values[0]
55 else: 55 else:
56 return None 56 return None
57 57
58 58
59 def get_position(footers): 59 def get_position(footers):
60 """Get the chrome commit position from a footer multimap using a heuristic. 60 """Get the commit position from the footers multimap using a heuristic.
61 61
62 Returns: 62 Returns:
63 A tuple of the branch and the position on that branch. For example, 63 A tuple of the branch and the position on that branch. For example,
64 64
65 Cr-Commit-Position: refs/heads/master@{#292272} 65 Cr-Commit-Position: refs/heads/master@{#292272}
66 66
67 would give the return value ('refs/heads/master', 292272). If 67 would give the return value ('refs/heads/master', 292272). If
68 Cr-Commit-Position is not defined, we try to infer the ref and position 68 Cr-Commit-Position is not defined, we try to infer the ref and position
69 from git-svn-id. The position number can be None if it was not inferrable. 69 from git-svn-id. The position number can be None if it was not inferrable.
70 """ 70 """
71 71
72 position = get_unique(footers, 'Cr-Commit-Position') 72 position = get_unique(footers, 'Cr-Commit-Position')
73 if position: 73 if position:
74 match = CHROME_COMMIT_POSITION_PATTERN.match(position) 74 match = CHROME_COMMIT_POSITION_PATTERN.match(position)
75 assert match, 'Invalid Cr-Commit-Position value: %s' % position 75 assert match, 'Invalid Cr-Commit-Position value: %s' % position
76 return (match.group(1), match.group(2)) 76 return (match.group(1), match.group(2))
77 77
78 svn_commit = get_unique(footers, 'git-svn-id') 78 svn_commit = get_unique(footers, 'git-svn-id')
79 if svn_commit: 79 if svn_commit:
80 match = GIT_SVN_ID_PATTERN.match(svn_commit) 80 match = GIT_SVN_ID_PATTERN.match(svn_commit)
81 assert match, 'Invalid git-svn-id value: %s' % svn_commit 81 assert match, 'Invalid git-svn-id value: %s' % svn_commit
82 if re.match('.*/chrome/trunk/src$', match.group(1)): 82 # Assume that any trunk svn revision will match the commit-position
83 # semantics.
84 if re.match('.*/trunk/.*$', match.group(1)):
83 return ('refs/heads/master', match.group(2)) 85 return ('refs/heads/master', match.group(2))
86
87 # But for now only support faking branch-heads for chrome.
84 branch_match = re.match('.*/chrome/branches/([\w/-]+)/src$', match.group(1)) 88 branch_match = re.match('.*/chrome/branches/([\w/-]+)/src$', match.group(1))
85 if branch_match: 89 if branch_match:
86 # svn commit numbers do not map to branches. 90 # svn commit numbers do not map to branches.
87 return ('refs/branch-heads/%s' % branch_match.group(1), None) 91 return ('refs/branch-heads/%s' % branch_match.group(1), None)
88 92
89 raise ValueError('Unable to infer commit position from footers') 93 raise ValueError('Unable to infer commit position from footers')
90 94
91 95
92 def main(args): 96 def main(args):
93 parser = argparse.ArgumentParser( 97 parser = argparse.ArgumentParser(
(...skipping 28 matching lines...) Expand all
122 assert pos[1], 'No valid position for commit' 126 assert pos[1], 'No valid position for commit'
123 print pos[1] 127 print pos[1]
124 else: 128 else:
125 for k in footers.keys(): 129 for k in footers.keys():
126 for v in footers[k]: 130 for v in footers[k]:
127 print '%s: %s' % (k, v) 131 print '%s: %s' % (k, v)
128 132
129 133
130 if __name__ == '__main__': 134 if __name__ == '__main__':
131 sys.exit(main(sys.argv[1:])) 135 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698