Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Multiple fixes and enhancements #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
*.pyc
.stashed_register
*.patch
54 changes: 30 additions & 24 deletions svn-stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
from datetime import datetime
from svn_stash_register import svn_stash_register,svn_stash,HOME_DIR,CURRENT_DIR,SVN_STASH_DIR,COMMAND_DEFAULT,TARGET_FILE_DEFAULT

def execute_stash_push(target_file,filename_list):
if len(filename_list)>0:
def execute_stash_push(target_file,info):
if len(info['files'])>0:
#save the svn status into a stash
stash = svn_stash()
stash.push(target_file,filename_list)
stash.push(target_file,info)
register = svn_stash_register()
register.register_stash(stash)
register.write()
else:
print "nothing to stash in this directory."

def execute_stash_pop(target_file,filename_list):
def execute_stash_pop(target_file,info):
#obtain last stash pop
register = svn_stash_register()
stash = register.obtain_last_stash()
Expand All @@ -39,13 +39,13 @@ def execute_stash_pop(target_file,filename_list):
else:
print "there are not previous stashes."

def execute_stash_list(target_file,filename_list):
def execute_stash_list(target_file,info):
#obtain the list of stashes.
register = svn_stash_register()
for stash_id in register.stashes:
print stash_id

def execute_stash_clear(target_file,filename_list):
def execute_stash_clear(target_file,info):
#delete all stashes.
register = svn_stash_register()
marked_stashes = list(register.stashes)
Expand All @@ -54,15 +54,15 @@ def execute_stash_clear(target_file,filename_list):
current_stash.load(stash)
register.delete_stash(current_stash)

def execute_stash_show(target_file,filename_list):
def execute_stash_show(target_file,info):
#view all diffs of all stashes.
register = svn_stash_register()
for stash_id in register.stashes:
current_stash = svn_stash()
current_stash.load(stash_id)
print current_stash

def execute_stash_help(target_file,filename_list):
def execute_stash_help(target_file,info):
b = "\033[1m"
end_b = "\033[0m"
help_content = "SVN STASH\n"
Expand All @@ -76,52 +76,58 @@ def execute_stash_help(target_file,filename_list):
help_content += "\tsvn stash clear\n"
help_content += "\tsvn stash help\n"
help_content += "\n" + b + "DESCRIPTION" + end_b +"\n"
help_content += "\tSvn-stash permits you to hide the changes that you don't want to commit just now. this can be more useful in some circunstances.\n"
help_content += "\tsvn-stash permits you to hide the changes that you don't want to commit just now. this can be more useful in some circumstances.\n"
print help_content


#Parser order and file of the command
def execute_svn_stash(command,target_file,filename_list):
def execute_svn_stash(command,target_file,info):
#print command+","+target_file
if command == "push":
execute_stash_push(target_file,filename_list)
execute_stash_push(target_file,info)
elif command == "pop":
execute_stash_pop(target_file,filename_list)
execute_stash_pop(target_file,info)
elif command == "list":
execute_stash_list(target_file,filename_list)
execute_stash_list(target_file,info)
elif command == "clear":
execute_stash_clear(target_file,filename_list)
execute_stash_clear(target_file,info)
elif command == "show":
execute_stash_show(target_file,filename_list)
execute_stash_show(target_file,info)
elif command == "help":
execute_stash_help(target_file,filename_list)
execute_stash_help(target_file,info)

#obtain the svn status files
def obtain_svn_status_files():
def obtain_svn_status_files(dir):
status_files = []
status_list = os.popen('svn st').read()
flags = {}
if dir == TARGET_FILE_DEFAULT:
dir = "."
status_list = os.popen('svn st "' + '" "'.join(dir) +'"').read()
status_list = status_list.split("\n")
for line in status_list:
words = line.split()
if len(words) > 1:
elements = line.split()
status = elements[0]
filename = elements[1]
if status == "M":
if os.path.isdir(filename) and filename[:-1] != '/':
filename = filename + "/"
if status == "M" or status == "A" or status == "D":
flags[filename] = status
status_files.append(filename)
return status_files
return {'files': status_files, 'flags': flags}

def main(args):
command = COMMAND_DEFAULT
if len(args)>1:
command = args[1]

target_file = TARGET_FILE_DEFAULT
files = ["."]
if len(args)>2:
target_file = args[2]
files = args[2:]

filename_list = obtain_svn_status_files()
execute_svn_stash(command,target_file,filename_list)
info = obtain_svn_status_files(files)
execute_svn_stash(command,TARGET_FILE_DEFAULT,info)


if __name__ == '__main__':
Expand Down
Loading