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 | |
4 import optparse | 7 import optparse |
5 | 8 |
6 import subcommand | 9 import subcommand |
7 import subprocess2 | |
8 | 10 |
9 from git_common import run, stream | 11 from git_common import freeze, thaw |
10 | 12 |
11 FREEZE = 'FREEZE' | 13 def CMDfreeze(parser, args): |
12 SECTIONS = { | |
13 'indexed': 'soft', | |
14 'unindexed': 'mixed' | |
15 } | |
16 MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(SECTIONS))) | |
17 | |
18 | |
19 def freeze(): | |
20 took_action = False | |
21 | |
22 try: | |
23 run('commit', '-m', FREEZE + '.indexed') | |
24 took_action = True | |
25 except subprocess2.CalledProcessError: | |
26 pass | |
27 | |
28 try: | |
29 run('add', '-A') | |
30 run('commit', '-m', FREEZE + '.unindexed') | |
31 took_action = True | |
32 except subprocess2.CalledProcessError: | |
33 pass | |
34 | |
35 if not took_action: | |
36 return 'Nothing to freeze.' | |
37 | |
38 | |
39 def thaw(): | |
40 took_action = False | |
41 for sha in (s.strip() for s in stream('rev-list', 'HEAD').xreadlines()): | |
42 msg = run('show', '--format=%f%b', '-s', 'HEAD') | |
43 match = MATCHER.match(msg) | |
44 if not match: | |
45 if not took_action: | |
46 return 'Nothing to thaw.' | |
47 break | |
48 | |
49 run('reset', '--' + SECTIONS[match.group(1)], sha) | |
50 took_action = True | |
51 | |
52 | |
53 def CMDfreeze(parser, args): # pragma: no cover | |
54 """Freeze a branch's changes.""" | 14 """Freeze a branch's changes.""" |
55 parser.parse_args(args) | 15 parser.parse_args(args) |
56 return freeze() | 16 return freeze() |
57 | 17 |
58 | 18 |
59 def CMDthaw(parser, args): # pragma: no cover | 19 def CMDthaw(parser, args): |
60 """Returns a frozen branch to the state before it was frozen.""" | 20 """Returns a frozen branch to the state before it was frozen.""" |
61 parser.parse_args(args) | 21 parser.parse_args(args) |
62 return thaw() | 22 return thaw() |
63 | 23 |
64 | 24 |
65 def main(): # pragma: no cover | 25 def main(): |
66 dispatcher = subcommand.CommandDispatcher(__name__) | 26 dispatcher = subcommand.CommandDispatcher(__name__) |
67 ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) | 27 ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) |
68 if ret: | 28 if ret: |
69 print ret | 29 print ret |
70 | 30 |
71 | 31 |
72 if __name__ == '__main__': # pragma: no cover | 32 if __name__ == '__main__': |
73 main() | 33 main() |
OLD | NEW |