def commit(self):
return self.__stack.repository.refs.get(self.__ref)
@property
+ def old_commit(self):
+ """Return the previous commit for this patch."""
+ fn = os.path.join(self.__compat_dir, 'top.old')
+ if not os.path.isfile(fn):
+ return None
+ return self.__stack.repository.get_commit(utils.read_string(fn))
+ @property
def __compat_dir(self):
return os.path.join(self.__stack.directory, 'patches', self.__name)
def __write_compat_files(self, new_commit, msg):
write('authdate', d.author.date)
write('commname', d.committer.name)
write('commemail', d.committer.email)
- write('description', d.message)
+ write('description', d.message, multiline = True)
write('log', write_patchlog().sha1)
write('top', new_commit.sha1)
write('bottom', d.parent.sha1)
for f in os.listdir(self.__compat_dir):
os.remove(os.path.join(self.__compat_dir, f))
os.rmdir(self.__compat_dir)
- self.__stack.repository.refs.delete(self.__log_ref)
+ try:
+ # this compatibility log ref might not exist
+ self.__stack.repository.refs.delete(self.__log_ref)
+ except KeyError:
+ pass
def set_commit(self, commit, msg):
self.__write_compat_files(commit, msg)
self.__stack.repository.refs.set(self.__ref, commit, msg)
return self.name in self.__stack.patchorder.applied
def is_empty(self):
return self.commit.data.is_nochange()
+ def files(self):
+ """Return the set of files this patch touches."""
+ fs = set()
+ for (_, _, _, _, _, oldname, newname
+ ) in self.__stack.repository.diff_tree_files(
+ self.commit.data.tree, self.commit.data.parent.data.tree):
+ fs.add(oldname)
+ fs.add(newname)
+ return fs
class PatchOrder(object):
"""Keeps track of patch order, and which patches are applied.
).commit.data.parent
else:
return self.head
+ @property
+ def top(self):
+ """Commit of the topmost patch, or the stack base if no patches are
+ applied."""
+ if self.patchorder.applied:
+ return self.patches.get(self.patchorder.applied[-1]).commit
+ else:
+ # When no patches are applied, base == head.
+ return self.head
def head_top_equal(self):
if not self.patchorder.applied:
return True