chiark
/
gitweb
/
~mdw
/
stgit
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only print the progress message if on a TTY
[stgit]
/
stgit
/
stack.py
diff --git
a/stgit/stack.py
b/stgit/stack.py
index 93a3d4ec68d4f3f771020886cc6b9a3f780ab2de..8fa384641a4e4375f7e998fc386b67bf37f6d3d9 100644
(file)
--- a/
stgit/stack.py
+++ b/
stgit/stack.py
@@
-332,6
+332,11
@@
class Series:
for patch in self.get_applied() + self.get_unapplied():
self.get_patch(patch).update_top_ref()
for patch in self.get_applied() + self.get_unapplied():
self.get_patch(patch).update_top_ref()
+ # trash directory
+ self.__trash_dir = os.path.join(self.__series_dir, 'trash')
+ if self.is_initialised() and not os.path.isdir(self.__trash_dir):
+ os.makedirs(self.__trash_dir)
+
def get_branch(self):
"""Return the branch name for the Series object
"""
def get_branch(self):
"""Return the branch name for the Series object
"""
@@
-350,9
+355,17
@@
class Series:
"""
return Patch(name, self.__patch_dir, self.__refs_dir)
"""
return Patch(name, self.__patch_dir, self.__refs_dir)
+ def get_current_patch(self):
+ """Return a Patch object representing the topmost patch, or
+ None if there is no such patch."""
+ crt = self.get_current()
+ if not crt:
+ return None
+ return Patch(crt, self.__patch_dir, self.__refs_dir)
+
def get_current(self):
def get_current(self):
- """Return
a Patch object representing the topmost patch
- """
+ """Return
the name of the topmost patch, or None if there is
+
no such patch.
"""
if os.path.isfile(self.__current_file):
name = read_string(self.__current_file)
else:
if os.path.isfile(self.__current_file):
name = read_string(self.__current_file)
else:
@@
-404,16
+417,21
@@
class Series:
def __patch_is_current(self, patch):
return patch.get_name() == read_string(self.__current_file)
def __patch_is_current(self, patch):
return patch.get_name() == read_string(self.__current_file)
- def
__
patch_applied(self, name):
+ def patch_applied(self, name):
"""Return true if the patch exists in the applied list
"""
return name in self.get_applied()
"""Return true if the patch exists in the applied list
"""
return name in self.get_applied()
- def
__
patch_unapplied(self, name):
+ def patch_unapplied(self, name):
"""Return true if the patch exists in the unapplied list
"""
return name in self.get_unapplied()
"""Return true if the patch exists in the unapplied list
"""
return name in self.get_unapplied()
+ def patch_exists(self, name):
+ """Return true if there is a patch with the given name, false
+ otherwise."""
+ return self.patch_applied(name) or self.patch_unapplied(name)
+
def __begin_stack_check(self):
"""Save the current HEAD into .git/refs/heads/base if the stack
is empty
def __begin_stack_check(self):
"""Save the current HEAD into .git/refs/heads/base if the stack
is empty
@@
-433,12
+451,11
@@
class Series:
def head_top_equal(self):
"""Return true if the head and the top are the same
"""
def head_top_equal(self):
"""Return true if the head and the top are the same
"""
- crt = self.get_current()
+ crt = self.get_current
_patch
()
if not crt:
# we don't care, no patches applied
return True
if not crt:
# we don't care, no patches applied
return True
- return git.get_head() == Patch(crt, self.__patch_dir,
- self.__refs_dir).get_top()
+ return git.get_head() == crt.get_top()
def is_initialised(self):
"""Checks if series is already initialised
def is_initialised(self):
"""Checks if series is already initialised
@@
-568,6
+585,11
@@
class Series:
for p in patches:
Patch(p, self.__patch_dir, self.__refs_dir).delete()
for p in patches:
Patch(p, self.__patch_dir, self.__refs_dir).delete()
+ # remove the trash directory
+ for fname in os.listdir(self.__trash_dir):
+ os.remove(fname)
+ os.rmdir(self.__trash_dir)
+
if os.path.exists(self.__applied_file):
os.remove(self.__applied_file)
if os.path.exists(self.__unapplied_file):
if os.path.exists(self.__applied_file):
os.remove(self.__applied_file)
if os.path.exists(self.__unapplied_file):
@@
-688,10
+710,10
@@
class Series:
top = None, bottom = None,
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None,
top = None, bottom = None,
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None,
- before_existing = False):
+ before_existing = False
, refresh = True
):
"""Creates a new patch
"""
"""Creates a new patch
"""
- if self.
__patch_applied(name) or self.__
patch_unapplied(name):
+ if self.
patch_applied(name) or self.
patch_unapplied(name):
raise StackException, 'Patch "%s" already exists' % name
if not message and can_edit:
raise StackException, 'Patch "%s" already exists' % name
if not message and can_edit:
@@
-741,8
+763,8
@@
class Series:
else:
append_string(self.__applied_file, patch.get_name())
self.__set_current(name)
else:
append_string(self.__applied_file, patch.get_name())
self.__set_current(name)
-
- self.refresh_patch(cache_update = False, log = 'new')
+ if refresh:
+
self.refresh_patch(cache_update = False, log = 'new')
def delete_patch(self, name):
"""Deletes a patch
def delete_patch(self, name):
"""Deletes a patch
@@
-751,12
+773,15
@@
class Series:
if self.__patch_is_current(patch):
self.pop_patch(name)
if self.__patch_is_current(patch):
self.pop_patch(name)
- elif self.
__
patch_applied(name):
+ elif self.patch_applied(name):
raise StackException, 'Cannot remove an applied patch, "%s", ' \
'which is not current' % name
elif not name in self.get_unapplied():
raise StackException, 'Unknown patch "%s"' % name
raise StackException, 'Cannot remove an applied patch, "%s", ' \
'which is not current' % name
elif not name in self.get_unapplied():
raise StackException, 'Unknown patch "%s"' % name
+ # save the commit id to a trash file
+ write_string(os.path.join(self.__trash_dir, name), patch.get_top())
+
patch.delete()
unapplied = self.get_unapplied()
patch.delete()
unapplied = self.get_unapplied()