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

Side by Side Diff: git_number.py

Issue 222103006: git-number cannot commit-tree without user config (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: use -c instead of environment variables Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 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 """Usage: %prog [options] [<commitref>]* 6 """Usage: %prog [options] [<commitref>]*
7 7
8 If no <commitref>'s are supplied, it defaults to HEAD. 8 If no <commitref>'s are supplied, it defaults to HEAD.
9 9
10 Calculates the generation number for one or more commits in a git repo. 10 Calculates the generation number for one or more commits in a git repo.
(...skipping 19 matching lines...) Expand all
30 import sys 30 import sys
31 import tempfile 31 import tempfile
32 32
33 import git_common as git 33 import git_common as git
34 import subprocess2 34 import subprocess2
35 35
36 CHUNK_FMT = '!20sL' 36 CHUNK_FMT = '!20sL'
37 CHUNK_SIZE = struct.calcsize(CHUNK_FMT) 37 CHUNK_SIZE = struct.calcsize(CHUNK_FMT)
38 DIRTY_TREES = collections.defaultdict(int) 38 DIRTY_TREES = collections.defaultdict(int)
39 REF = 'refs/number/commits' 39 REF = 'refs/number/commits'
40 AUTHOR_NAME = 'git-number'
41 AUTHOR_EMAIL = 'chrome-infrastructure-team@google.com'
40 42
41 # Number of bytes to use for the prefix on our internal number structure. 43 # Number of bytes to use for the prefix on our internal number structure.
42 # 0 is slow to deserialize. 2 creates way too much bookeeping overhead (would 44 # 0 is slow to deserialize. 2 creates way too much bookeeping overhead (would
43 # need to reimplement cache data structures to be a bit more sophisticated than 45 # need to reimplement cache data structures to be a bit more sophisticated than
44 # dicts. 1 seems to be just right. 46 # dicts. 1 seems to be just right.
45 PREFIX_LEN = 1 47 PREFIX_LEN = 1
46 48
47 # Set this to 'threads' to gather coverage data while testing. 49 # Set this to 'threads' to gather coverage data while testing.
48 POOL_KIND = 'procs' 50 POOL_KIND = 'procs'
49 51
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 with git.ScopedPool(kind=POOL_KIND) as leaf_pool: 148 with git.ScopedPool(kind=POOL_KIND) as leaf_pool:
147 for item in leaf_pool.imap(leaf_map_fn, prefixes_trees): 149 for item in leaf_pool.imap(leaf_map_fn, prefixes_trees):
148 updater.stdin.write(item) 150 updater.stdin.write(item)
149 inc() 151 inc()
150 152
151 updater.stdin.close() 153 updater.stdin.close()
152 updater.wait() 154 updater.wait()
153 assert updater.returncode == 0 155 assert updater.returncode == 0
154 156
155 tree_id = git.run('write-tree', env=env) 157 tree_id = git.run('write-tree', env=env)
156 commit_cmd = ['commit-tree', '-m', msg, '-p'] + git.hash_multi(REF) 158 commit_cmd = [
159 # Git user.name and/or user.email may not be configured, so specifying
160 # them explicitly. They are not used, but requried by Git.
161 '-c', 'user.name=%s' % AUTHOR_NAME,
162 '-c', 'user.email=%s' % AUTHOR_EMAIL,
163 'commit-tree',
164 '-m', msg,
165 '-p'] + git.hash_multi(REF)
157 for t in targets: 166 for t in targets:
158 commit_cmd.extend(['-p', binascii.hexlify(t)]) 167 commit_cmd.extend(['-p', binascii.hexlify(t)])
159 commit_cmd.append(tree_id) 168 commit_cmd.append(tree_id)
160 commit_hash = git.run(*commit_cmd) 169 commit_hash = git.run(*commit_cmd)
161 git.run('update-ref', REF, commit_hash) 170 git.run('update-ref', REF, commit_hash)
162 DIRTY_TREES.clear() 171 DIRTY_TREES.clear()
163 172
164 173
165 def preload_tree(prefix): 174 def preload_tree(prefix):
166 """Returns the prefix and parsed tree object for the specified prefix.""" 175 """Returns the prefix and parsed tree object for the specified prefix."""
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 finalize(targets) 267 finalize(targets)
259 268
260 print '\n'.join(map(str, map(get_num, targets))) 269 print '\n'.join(map(str, map(get_num, targets)))
261 return 0 270 return 0
262 except KeyboardInterrupt: 271 except KeyboardInterrupt:
263 return 1 272 return 1
264 273
265 274
266 if __name__ == '__main__': # pragma: no cover 275 if __name__ == '__main__': # pragma: no cover
267 sys.exit(main()) 276 sys.exit(main())
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