OLD | NEW |
1 #!/usr/local/bin/python | 1 #!/usr/local/bin/python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
2 import sys | 6 import sys |
3 import re | 7 import re |
4 import optparse | 8 import optparse |
5 | 9 |
6 import subcommand | 10 import subcommand |
7 import subprocess2 | 11 import subprocess2 |
8 | 12 |
9 from git_common import run, stream | 13 from git_common import run, run_stream |
10 | 14 |
11 FREEZE = 'FREEZE' | 15 FREEZE = 'FREEZE' |
12 SECTIONS = { | 16 SECTIONS = { |
13 'indexed': 'soft', | 17 'indexed': 'soft', |
14 'unindexed': 'mixed' | 18 'unindexed': 'mixed' |
15 } | 19 } |
16 MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(SECTIONS))) | 20 MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(SECTIONS))) |
17 | 21 |
18 | 22 |
19 def freeze(): | 23 def freeze(): |
(...skipping 11 matching lines...) Expand all Loading... |
31 took_action = True | 35 took_action = True |
32 except subprocess2.CalledProcessError: | 36 except subprocess2.CalledProcessError: |
33 pass | 37 pass |
34 | 38 |
35 if not took_action: | 39 if not took_action: |
36 return 'Nothing to freeze.' | 40 return 'Nothing to freeze.' |
37 | 41 |
38 | 42 |
39 def thaw(): | 43 def thaw(): |
40 took_action = False | 44 took_action = False |
41 for sha in (s.strip() for s in stream('rev-list', 'HEAD').xreadlines()): | 45 for sha in (s.strip() for s in run_stream('rev-list', 'HEAD').xreadlines()): |
42 msg = run('show', '--format=%f%b', '-s', 'HEAD') | 46 msg = run('show', '--format=%f%b', '-s', 'HEAD') |
43 match = MATCHER.match(msg) | 47 match = MATCHER.match(msg) |
44 if not match: | 48 if not match: |
45 if not took_action: | 49 if not took_action: |
46 return 'Nothing to thaw.' | 50 return 'Nothing to thaw.' |
47 break | 51 break |
48 | 52 |
49 run('reset', '--' + SECTIONS[match.group(1)], sha) | 53 run('reset', '--' + SECTIONS[match.group(1)], sha) |
50 took_action = True | 54 took_action = True |
51 | 55 |
(...skipping 12 matching lines...) Expand all Loading... |
64 | 68 |
65 def main(): # pragma: no cover | 69 def main(): # pragma: no cover |
66 dispatcher = subcommand.CommandDispatcher(__name__) | 70 dispatcher = subcommand.CommandDispatcher(__name__) |
67 ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) | 71 ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) |
68 if ret: | 72 if ret: |
69 print ret | 73 print ret |
70 | 74 |
71 | 75 |
72 if __name__ == '__main__': # pragma: no cover | 76 if __name__ == '__main__': # pragma: no cover |
73 main() | 77 main() |
OLD | NEW |