Chromium Code Reviews| Index: git_freezer.py |
| diff --git a/git_freezer.py b/git_freezer.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..314a7d05d27346c7d0009ab20620e40ad30986a4 |
| --- /dev/null |
| +++ b/git_freezer.py |
| @@ -0,0 +1,56 @@ |
| +#!/usr/local/bin/python |
| +import sys |
| +import re |
| +import optparse |
| + |
| +import subcommand |
| + |
| +from git_common import run, stream |
| + |
| +FREEZE = 'FREEZE' |
| +SECTIONS = { |
| + 'indexed': 'soft', |
| + 'unindexed': 'mixed' |
| +} |
| +MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(SECTIONS))) |
| + |
| + |
| +def CMDfreeze(_parser, _args): |
| + """freeze a branches changes.""" |
|
agable
2014/02/28 19:35:35
possessive
|
| + took_action = False |
| + status = [(line[:2], line[2:]) for line in run('status', '-z').split('\0')] |
| + if status[-1] == ('', ''): |
| + status.pop() |
| + if any(mode[0] != ' ' for mode, _ in status): |
| + run('commit', '-m', FREEZE + '.' + 'indexed') |
|
agable
2014/02/28 19:35:35
+ '.indexed'?
|
| + took_action = True |
| + if any(mode[0] in ' ?' for mode, _ in status): |
| + run('add', '-A') |
| + run('commit', '-m', FREEZE + '.' + 'unindexed') |
| + took_action = True |
| + |
| + if not took_action: |
| + print 'Nothing to freeze.' |
| + |
| + |
| +def CMDthaw(_parser, _args): |
| + """returns a frozen branch to the state before it was frozen.""" |
| + took_action = False |
| + for sha in (s.strip() for s in stream('rev-list', 'HEAD').xreadlines()): |
| + msg = run('show', '--format=%f%b', '-s', 'HEAD') |
| + match = MATCHER.match(msg) |
| + if not match: |
| + if not took_action: |
| + print 'Nothing to thaw.' |
| + break |
| + |
| + run('reset', '--' + SECTIONS[match.group(1)], sha) |
| + took_action = True |
| + |
| + |
| +def main(): |
| + dispatcher = subcommand.CommandDispatcher(__name__) |
| + return dispatcher.execute(optparse.OptionParser(), sys.argv[1:]) |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |