Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/local/bin/python | |
| 2 import sys | |
| 3 import re | |
| 4 import optparse | |
| 5 | |
| 6 import subcommand | |
| 7 import subprocess2 | |
| 8 | |
| 9 from git_common import run, stream | |
| 10 | |
| 11 FREEZE = 'FREEZE' | |
| 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 | |
|
agable
2014/03/13 00:45:34
two spaces before #
| |
| 54 """Freeze a branch's changes.""" | |
| 55 parser.parse_args(args) | |
| 56 return freeze() | |
| 57 | |
| 58 | |
| 59 def CMDthaw(parser, args): # pragma: no cover | |
| 60 """Returns a frozen branch to the state before it was frozen.""" | |
| 61 parser.parse_args(args) | |
| 62 return thaw() | |
| 63 | |
| 64 | |
| 65 def main(): # pragma: no cover | |
| 66 dispatcher = subcommand.CommandDispatcher(__name__) | |
| 67 ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) | |
| 68 if ret: | |
| 69 print ret | |
| 70 | |
| 71 | |
| 72 if __name__ == '__main__': # pragma: no cover | |
| 73 main() | |
| OLD | NEW |