"""
import sys, os, re
+from email.Utils import formatdate
from stgit.utils import *
from stgit.out import *
f.seek(0); f.truncate()
f.writelines(lines)
+# TODO: move this out of the stgit.stack module, it is really for
+# higher level commands to handle the user interaction
def edit_file(series, line, comment, show_patch = True):
fname = '.stgitmsg.txt'
tmpl = templates.get_template('patchdescr.tmpl')
self._set_field('authemail', email or git.author().email)
def get_authdate(self):
- return self._get_field('authdate')
+ date = self._get_field('authdate')
+ if not date:
+ return date
+
+ if re.match('[0-9]+\s+[+-][0-9]+', date):
+ # Unix time (seconds) + time zone
+ secs_tz = date.split()
+ date = formatdate(int(secs_tz[0]))[:-5] + secs_tz[1]
+
+ return date
def set_authdate(self, date):
self._set_field('authdate', date or git.author().date)
return bool(config.get(self.format_version_key()))
+def shortlog(patches):
+ log = ''.join(Run('git-log', '--pretty=short',
+ p.get_top(), '^%s' % p.get_bottom()).raw_output()
+ for p in patches)
+ return Run('git-shortlog').raw_input(log).raw_output()
+
class Series(PatchSet):
"""Class including the operations on series
"""
except GitException:
out.warn('Could not delete branch "%s"' % self.get_name())
- # Cleanup parent informations
- # FIXME: should one day make use of git-config --section-remove,
- # scheduled for 1.5.1
- config.unset('branch.%s.remote' % self.get_name())
- config.unset('branch.%s.merge' % self.get_name())
- config.unset('branch.%s.stgit.parentbranch' % self.get_name())
- config.unset(self.format_version_key())
+ config.remove_section('branch.%s' % self.get_name())
+ config.remove_section('branch.%s.stgit' % self.get_name())
def refresh_patch(self, files = None, message = None, edit = False,
show_patch = False,
elif message:
descr = message
+ # TODO: move this out of the stgit.stack module, it is really
+ # for higher level commands to handle the user interaction
if not message and edit:
descr = edit_file(self, descr.rstrip(), \
'Please edit the description for patch "%s" ' \
if self.patch_exists(name):
raise StackException, 'Patch "%s" already exists' % name
+ # TODO: move this out of the stgit.stack module, it is really
+ # for higher level commands to handle the user interaction
if not message and can_edit:
descr = edit_file(
self, None,
return merged
- def push_patch(self, name, empty = False):
+ def push_empty_patch(self, name):
+ """Pushes an empty patch on the stack
+ """
+ unapplied = self.get_unapplied()
+ assert(name in unapplied)
+
+ patch = self.get_patch(name)
+ head = git.get_head()
+
+ # The top is updated by refresh_patch since we need an empty
+ # commit
+ patch.set_bottom(head, backup = True)
+ patch.set_top(head, backup = True)
+
+ append_string(self.__applied_file, name)
+
+ unapplied.remove(name)
+ write_strings(self.__unapplied_file, unapplied)
+
+ self.refresh_patch(cache_update = False, log = 'push(m)')
+
+ def push_patch(self, name):
"""Pushes a patch on the stack
"""
unapplied = self.get_unapplied()
modified = False
# top != bottom always since we have a commit for each patch
- if empty:
- # just make an empty patch (top = bottom = HEAD). This
- # option is useful to allow undoing already merged
- # patches. The top is updated by refresh_patch since we
- # need an empty commit
- patch.set_bottom(head, backup = True)
- patch.set_top(head, backup = True)
- modified = True
- elif head == bottom:
+ if head == bottom:
# reset the backup information. No need for logging
patch.set_bottom(bottom, backup = True)
patch.set_top(top, backup = True)
write_strings(self.__unapplied_file, unapplied)
# head == bottom case doesn't need to refresh the patch
- if empty or head != bottom:
+ if head != bottom:
if not ex:
# if the merge was OK and no conflicts, just refresh the patch
# The GIT cache was already updated by the merge operation