Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 This in particular saves the trees referred to by DIRTY_TREES. | 127 This in particular saves the trees referred to by DIRTY_TREES. |
| 128 """ | 128 """ |
| 129 if not DIRTY_TREES: | 129 if not DIRTY_TREES: |
| 130 return | 130 return |
| 131 | 131 |
| 132 msg = 'git-number Added %s numbers' % sum(DIRTY_TREES.itervalues()) | 132 msg = 'git-number Added %s numbers' % sum(DIRTY_TREES.itervalues()) |
| 133 | 133 |
| 134 idx = os.path.join(git.run('rev-parse', '--git-dir'), 'number.idx') | 134 idx = os.path.join(git.run('rev-parse', '--git-dir'), 'number.idx') |
| 135 env = os.environ.copy() | 135 env = os.environ.copy() |
| 136 env['GIT_INDEX_FILE'] = idx | 136 env['GIT_INDEX_FILE'] = idx |
| 137 # Git user.name and/or user.email may not be configured, so specifying them | |
|
agable
2014/04/02 23:29:47
Nonono. These environment variables, if present, o
| |
| 138 # explicitly. They are not used, but requried by Git. | |
| 139 env['GIT_AUTHOR_NAME'] = 'git-number' | |
| 140 env['GIT_AUTHOR_EMAIL'] = 'chrome-infrastructure-team@google.com' | |
| 141 env['GIT_COMMITTER_NAME'] = env['GIT_AUTHOR_NAME'] | |
| 142 env['GIT_COMMITTER_EMAIL'] = env['GIT_AUTHOR_EMAIL'] | |
| 137 | 143 |
| 138 progress_message = 'Finalizing: (%%(count)d/%d)' % len(DIRTY_TREES) | 144 progress_message = 'Finalizing: (%%(count)d/%d)' % len(DIRTY_TREES) |
| 139 with git.ProgressPrinter(progress_message) as inc: | 145 with git.ProgressPrinter(progress_message) as inc: |
| 140 git.run('read-tree', REF, env=env) | 146 git.run('read-tree', REF, env=env) |
| 141 | 147 |
| 142 prefixes_trees = ((p, get_number_tree(p)) for p in sorted(DIRTY_TREES)) | 148 prefixes_trees = ((p, get_number_tree(p)) for p in sorted(DIRTY_TREES)) |
| 143 updater = subprocess2.Popen(['git', 'update-index', '-z', '--index-info'], | 149 updater = subprocess2.Popen(['git', 'update-index', '-z', '--index-info'], |
| 144 stdin=subprocess2.PIPE, env=env) | 150 stdin=subprocess2.PIPE, env=env) |
| 145 | 151 |
| 146 with git.ScopedPool(kind=POOL_KIND) as leaf_pool: | 152 with git.ScopedPool(kind=POOL_KIND) as leaf_pool: |
| 147 for item in leaf_pool.imap(leaf_map_fn, prefixes_trees): | 153 for item in leaf_pool.imap(leaf_map_fn, prefixes_trees): |
| 148 updater.stdin.write(item) | 154 updater.stdin.write(item) |
| 149 inc() | 155 inc() |
| 150 | 156 |
| 151 updater.stdin.close() | 157 updater.stdin.close() |
| 152 updater.wait() | 158 updater.wait() |
| 153 assert updater.returncode == 0 | 159 assert updater.returncode == 0 |
| 154 | 160 |
| 155 tree_id = git.run('write-tree', env=env) | 161 tree_id = git.run('write-tree', env=env) |
| 156 commit_cmd = ['commit-tree', '-m', msg, '-p'] + git.hash_multi(REF) | 162 commit_cmd = ['commit-tree', '-m', msg, '-p'] + git.hash_multi(REF) |
| 157 for t in targets: | 163 for t in targets: |
| 158 commit_cmd.extend(['-p', binascii.hexlify(t)]) | 164 commit_cmd.extend(['-p', binascii.hexlify(t)]) |
| 159 commit_cmd.append(tree_id) | 165 commit_cmd.append(tree_id) |
| 160 commit_hash = git.run(*commit_cmd) | 166 commit_hash = git.run(*commit_cmd, env=env) |
| 161 git.run('update-ref', REF, commit_hash) | 167 git.run('update-ref', REF, commit_hash) |
| 162 DIRTY_TREES.clear() | 168 DIRTY_TREES.clear() |
| 163 | 169 |
| 164 | 170 |
| 165 def preload_tree(prefix): | 171 def preload_tree(prefix): |
| 166 """Returns the prefix and parsed tree object for the specified prefix.""" | 172 """Returns the prefix and parsed tree object for the specified prefix.""" |
| 167 return prefix, get_number_tree(prefix) | 173 return prefix, get_number_tree(prefix) |
| 168 | 174 |
| 169 | 175 |
| 170 def all_prefixes(depth=PREFIX_LEN): | 176 def all_prefixes(depth=PREFIX_LEN): |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 finalize(targets) | 264 finalize(targets) |
| 259 | 265 |
| 260 print '\n'.join(map(str, map(get_num, targets))) | 266 print '\n'.join(map(str, map(get_num, targets))) |
| 261 return 0 | 267 return 0 |
| 262 except KeyboardInterrupt: | 268 except KeyboardInterrupt: |
| 263 return 1 | 269 return 1 |
| 264 | 270 |
| 265 | 271 |
| 266 if __name__ == '__main__': # pragma: no cover | 272 if __name__ == '__main__': # pragma: no cover |
| 267 sys.exit(main()) | 273 sys.exit(main()) |
| OLD | NEW |