stash: write info to stash files, not displaying in "list" yet
This commit is contained in:
parent
28fb4fa1e1
commit
2198f91b41
33
jsvn
33
jsvn
@ -114,6 +114,7 @@ import re
|
||||
import time
|
||||
from subprocess import *
|
||||
import traceback
|
||||
import datetime
|
||||
|
||||
STATUS_LINE_REGEX = r'[ACDIMRX?!~ ][CM ][L ][+ ][SX ][KOTB ]..(.+)'
|
||||
|
||||
@ -815,24 +816,32 @@ def stash(argv, svn, out):
|
||||
proc = Popen([svn, 'diff'], stdout=PIPE)
|
||||
wrote_something = False
|
||||
found_binary_file = False
|
||||
n_insertions = 0
|
||||
n_deletions = 0
|
||||
for line in iter(proc.stdout.readline, ''):
|
||||
if re.match(r'Cannot.display..file.marked.as.a.binary.type',
|
||||
line, flags=re.I):
|
||||
found_binary_file = True
|
||||
if line.startswith('-') and not line.startswith('---'):
|
||||
n_deletions += 1
|
||||
if line.startswith('+') and not line.startswith('+++'):
|
||||
n_insertions += 1
|
||||
fh.write(line)
|
||||
wrote_something = True
|
||||
proc.wait()
|
||||
fh.close()
|
||||
if found_binary_file:
|
||||
out.write('Error: cannot stash with changes to binary files\n')
|
||||
fh.close()
|
||||
os.unlink(stash_fname)
|
||||
elif not wrote_something:
|
||||
out.write('Error: no changes to stash!\n')
|
||||
fh.close()
|
||||
os.unlink(stash_fname)
|
||||
else:
|
||||
# the stash is good, now revert the working copy changes
|
||||
status_lines = Popen([svn, 'status', '--ignore-externals'],
|
||||
stdout=PIPE).communicate()[0].split('\n')
|
||||
files_changed = {}
|
||||
for line in reversed(status_lines):
|
||||
m = re.match(STATUS_LINE_REGEX, line)
|
||||
if m is not None:
|
||||
@ -841,6 +850,10 @@ def stash(argv, svn, out):
|
||||
prop_action = line[1]
|
||||
if (action in ('A', 'M', 'D')
|
||||
or prop_action == 'M'):
|
||||
if action != ' ':
|
||||
files_changed[target] = action
|
||||
else:
|
||||
files_changed[target] = prop_action
|
||||
Popen([svn, 'revert', target], stdout=PIPE).wait()
|
||||
if action == 'A':
|
||||
# a file was added, so to stash it we must remove
|
||||
@ -852,6 +865,24 @@ def stash(argv, svn, out):
|
||||
os.rmdir(target)
|
||||
else:
|
||||
raise ValueError('unhandled target type')
|
||||
# write stash info
|
||||
if len(files_changed) == 1:
|
||||
fname = files_changed.keys()[0]
|
||||
fh.write('#info: %s: %s\n' % (files_changed[fname], fname))
|
||||
else:
|
||||
num_actions = {'A': 0, 'M': 0, 'D': 0}
|
||||
for k in files_changed:
|
||||
if files_changed[k] in num_actions:
|
||||
num_actions[files_changed[k]] += 1
|
||||
for a in num_actions:
|
||||
if num_actions[a] > 0:
|
||||
fh.write('#info: %s: %d\n' % (a, num_actions[a]))
|
||||
fh.write('#info: -%d\n' % n_deletions)
|
||||
fh.write('#info: +%d\n' % n_insertions)
|
||||
now = datetime.datetime.now()
|
||||
fh.write('#info: @%04d-%02d-%02d %02d:%02d\n' %
|
||||
(now.year, now.month, now.day, now.hour, now.minute))
|
||||
fh.close()
|
||||
out.write('Created stash %d\n' % stash_idx)
|
||||
os.chdir(owd)
|
||||
elif action == 'list':
|
||||
|
Loading…
x
Reference in New Issue
Block a user