break up stash subcommand handlers into their own functions

This commit is contained in:
Josh Holtrop 2013-02-12 16:30:24 -05:00
parent 9ffbd09477
commit f9c474a53f

48
jsvn
View File

@ -1225,15 +1225,7 @@ def revert_h(argv, svn, out, config):
break break
return RET_OK if did_something else RET_REEXEC return RET_OK if did_something else RET_REEXEC
def stash_h(argv, svn, out, config): def stash_save_h(argv, svn, out, config):
argv = argv[1:] # strip 'stash' command
action = 'save'
if len(argv) >= 1:
if not argv[0].startswith('-'):
action = argv[0]
argv = argv[1:]
# now argv only contains options/arguments to the stash subcommand itself
if action == 'save':
keep_wc = False keep_wc = False
options, args = getopt.getopt(argv, 'k') options, args = getopt.getopt(argv, 'k')
for opt, val in options: for opt, val in options:
@ -1321,7 +1313,9 @@ def stash_h(argv, svn, out, config):
fh.close() fh.close()
out.write('Created stash %d\n' % stash_idx) out.write('Created stash %d\n' % stash_idx)
os.chdir(owd) os.chdir(owd)
elif action == 'list': return RET_OK
def stash_list_h(argv, svn, out, config):
stash_ids = get_stash_ids(svn) stash_ids = get_stash_ids(svn)
for si in reversed(stash_ids): for si in reversed(stash_ids):
ins_text = '' ins_text = ''
@ -1376,7 +1370,9 @@ def stash_h(argv, svn, out, config):
ansi_reset(out) ansi_reset(out)
out.write(')') out.write(')')
out.write('\n') out.write('\n')
elif action == 'pop': return RET_OK
def stash_pop_h(argv, svn, out, config):
keep = False keep = False
options, args = getopt.getopt(argv, 'k') options, args = getopt.getopt(argv, 'k')
for opt, val in options: for opt, val in options:
@ -1403,7 +1399,9 @@ def stash_h(argv, svn, out, config):
else: else:
out.write('No stashes to pop\n') out.write('No stashes to pop\n')
os.chdir(owd) os.chdir(owd)
elif action == 'show': return RET_OK
def stash_show_h(argv, svn, out, config):
stash_ids = get_stash_ids(svn) stash_ids = get_stash_ids(svn)
if len(stash_ids) > 0: if len(stash_ids) > 0:
stash_id = stash_ids[-1] stash_id = stash_ids[-1]
@ -1420,7 +1418,9 @@ def stash_h(argv, svn, out, config):
out.write('Invalid stash ID\n') out.write('Invalid stash ID\n')
else: else:
out.write('No stashes to show\n') out.write('No stashes to show\n')
elif action == 'drop': return RET_OK
def stash_drop_h(argv, svn, out, config):
stash_ids = get_stash_ids(svn) stash_ids = get_stash_ids(svn)
if len(stash_ids) > 0: if len(stash_ids) > 0:
stash_id = stash_ids[-1] stash_id = stash_ids[-1]
@ -1431,10 +1431,28 @@ def stash_h(argv, svn, out, config):
out.write('Dropped stash %d\n' % stash_id) out.write('Dropped stash %d\n' % stash_id)
else: else:
out.write('No stashes to drop\n') out.write('No stashes to drop\n')
else:
out.write('Unknown action "%s"\n' % action)
return RET_OK return RET_OK
def stash_h(argv, svn, out, config):
argv = argv[1:] # strip 'stash' command
action = 'save'
if len(argv) >= 1:
if not argv[0].startswith('-'):
action = argv[0]
argv = argv[1:]
# now argv only contains options/arguments to the stash subcommand itself
actions = {
'save': stash_save_h,
'list': stash_list_h,
'pop': stash_pop_h,
'show': stash_show_h,
'drop': stash_drop_h
}
if action in actions:
return actions[action](argv, svn, out, config)
sys.stderr.write('Unknown action "%s"\n' % action)
return RET_ERR
def root_h(argv, svn, out, config): def root_h(argv, svn, out, config):
out.write(get_svn_root_url(svn) + '\n') out.write(get_svn_root_url(svn) + '\n')
return RET_OK return RET_OK