Commits

Anonymous committed e8ceef3

some cleanup

Comments (0)

Files changed (1)

 
 from mercurial.i18n import _
 from mercurial.node import nullid, nullrev, hex, short
-from mercurial import util, commands, localrepo, repair, extensions, hg, cmdutil, url, error, patch
+from mercurial import util, commands, localrepo, repair, extensions, hg
+from mercurial import cmdutil, url, error, patch
 import os, time, shutil, errno
 
-
 def prettynode(ui, repo, node):
     if not node: return ''
     hexfn = ui.debugflag and hex or short
-    return "%d:%s" % (repo.changelog.rev(node), hexfn(node))
+    return '%d:%s' % (repo.changelog.rev(node), hexfn(node))
 
 def prettynodelist(ui, repo, nodes):
     return '[ ' + ', '.join([prettynode(ui, repo, n) for n in nodes]) + ' ]'
     f = repo.opener('tasks/tasks', 'w+')
     for tname, tinfo in tasks.iteritems():
         # taskname,parentnode,startnode,endnode,state
-        line = "%s,%s,%s,%s,%d\n" % (tname, hex(tinfo['parent']),
+        line = '%s,%s,%s,%s,%d\n' % (tname, hex(tinfo['parent']),
                 tinfo['start'] and hex(tinfo['start']) or '',
                 tinfo['end'] and hex(tinfo['end']) or '',
                 tinfo['state'])
     # do not update if the task we update to is completed
     if (task and task in tasks and tasks[task]['state'] == 2):
         return
-
     # do not update if we do update to a rev equal to the current task
     if (task and task not in tasks and
-        current(repo) and tasknode(repo, tasks[current(repo)]) == repo.changectx('.').node()):
+        current(repo) and tasknode(repo, tasks[current(repo)]) ==
+        repo.changectx('.').node()):
         return
-
     # we are clearing it here
     if task not in tasks:
         task = ''
     else:
-        if msg: ui.status("current task: %s\n" % task)
+        if msg: ui.status('current task: %s\n' % task)
     file = repo.opener('tasks/current', 'w+')
     file.write(task)
     file.close()
 def trackingcurrent(repo):
     tasks = parse(repo)
     currenttask = current(repo)
-    return currenttask and repo.changectx('.').node() == tasknode(repo, tasks[currenttask])
+    return currenttask and \
+            repo.changectx('.').node() == tasknode(repo, tasks[currenttask])
 
 def tasknode(repo, tinfo):
     '''returns the task 'tip', used for updating and display'''
     else:
         return repo.changelog.nodesbetween([tinfo['start']], [tinfo['end']])[0]
 
-def task(ui, repo, task=None, rev=None, force=False, delete=False, info=None, all=False, \
-        complete=None, resume=None, delete_all=False, delete_complete=False, \
-        rename=None, trim=None, append=None, purge_stash=False ):
+def task(ui, repo, task=None, rev=None, force=False, delete=False, info=None,
+        all=False, complete=None, resume=None, delete_all=False,
+        delete_complete=False, rename=None, trim=None, append=None,
+        purge_stash=False):
     '''mercurial tasks
 
     Tasks are collections of contiguous changesets.  A task can be short or long
     task as current.  When a task is set as current, all subsequent commits will
     be assoticated with the task.
 
-    Use 'hg log [TASK]' to view a log of all changesets associated with the given
+    Use 'hg log [TASK]' to view a log of all changesets associated with the
+    given task.
+
+    Use 'hg export [TASK]' to export all changesets associated with the given
     task.
 
-    Use 'hg export [TASK]' to export all changesets associated with the given task.
-
     Use 'hg email -t [TASK]' to create a patchbomb containing all changesets
     associated with the given task.
 
     Use 'hg transplant -t [TASK]' to transplant all associated changsets in a
     task.
 
-    If the auto.track.new config option is True, newly created tasks will automatically
-    be set as current.
+    If the auto.track.new config option is True, newly created tasks will
+    automatically be set as current.
 
     If the auto.stash config option is True, your working copy will
     automatically be stashed when you update away from the current task.  When
     tasks = parse(repo)
 
     # all these options need a valid task name
-    if delete or info or complete or resume or trim or append or (purge_stash and not all):
+    if delete or info or complete or resume or trim or append \
+        or (purge_stash and not all):
         if task == None:
-            raise util.Abort(_("task name required"))
+            raise util.Abort(_('task name required'))
         if task not in tasks:
-            raise util.Abort(_("a task of this name does not exist"))
+            raise util.Abort(_('a task of this name does not exist'))
 
     # all these options don't want a task
     if delete_all or delete_complete or (purge_stash and all):
         if task:
-            raise util.Abort(_("no task name required for this option"))
-
-
+            raise util.Abort(_('no task name required for this option'))
 
     # check for force when deleting tasks with stash
     if delete_all or delete_complete or delete:
             stashedtasks = [ t for t in deltasks if hasstash(repo, t) ]
             if len(stashedtasks):
                 if delete:
-                    raise util.Abort(_("task has stash info, use -f to lose stash"))
+                    raise util.Abort(
+                        _('task has stash info, use -f to lose stash'))
                 else:
-                    raise util.Abort(_("deleting tasks with stash info, use -f to lose stashes\ntasks with stash info: %s"
-                        % ' '.join(stashedtasks)))
+                    raise util.Abort(_('deleting tasks with stash info, use -f'
+                        ' to lose stashes\ntasks with stash info: %s' %
+                        ' '.join(stashedtasks)))
 
     # delete all
     if delete_all:
     # rename a task
     if rename:
         if rename not in tasks:
-            raise util.Abort(_("a task of this name does not exist"))
+            raise util.Abort(_('a task of this name does not exist'))
         if task in tasks and not force:
-            raise util.Abort(_("a task of the same name already exists"))
+            raise util.Abort(_('a task of the same name already exists'))
         if task is None:
-            raise util.Abort(_("new task name required"))
+            raise util.Abort(_('new task name required'))
         oldstash = stashfiles(repo, rename)
         newstash = stashfiles(repo, task)
         for i in range(len(oldstash)):
     # complete a task
     if complete:
         if tasks[task]['state'] == 2:
-            raise util.Abort(_("task is already completed"))
+            raise util.Abort(_('task is already completed'))
         if tasks[task]['state'] == 0:
-            raise util.Abort(_("no changesets in task"))
+            raise util.Abort(_('no changesets in task'))
         if not force and hasstash(repo, task):
-            raise util.Abort(_("task has stash, use -f to lose stash"))
+            raise util.Abort(_('task has stash, use -f to lose stash'))
         # when checking for working copy changes here, we are bit more lax and
         # not worried about unknown files...
-        if not force and task == current(repo) and trackingcurrent(repo) and bool(filter(None, repo.status())):
-            raise util.Abort(_("uncommited changes in current task, use -f to complete anyway"))
+        if not force and task == current(repo) and trackingcurrent(repo) \
+            and bool(filter(None, repo.status())):
+            raise util.Abort(_('uncommited changes in current task, use -f to '
+                'complete anyway'))
+
         tasks[task]['state'] = 2
         if task == current(repo):
             setcurrent(ui, repo, None)
     # resume a task  (should we set to current and update to it???)
     if resume:
         if not tasks[task]['state'] == 2:
-            raise util.Abort(_("task is not completed"))
+            raise util.Abort(_('task is not completed'))
         tasks[task]['state'] = 1
         write(ui, repo, tasks)
         return
     # show info on a given task
     if info:
         tinfo = tasks[task]
-        ui.write("task:            %s\n" % task)
-        ui.write("parent:          %s\n" % prettynode(ui, repo, tinfo['parent']))
+        ui.write('task:            %s\n' % task)
+        ui.write('parent:          %s\n' % prettynode(ui, repo,
+            tinfo['parent']))
 
         if task == current(repo) and trackingcurrent(repo):
-            stashstr = bool(filter(None, repo.status())) and " + changes" or ""
+            stashstr = bool(filter(None, repo.status())) and ' + changes' or ''
         else:
-            stashstr = hasstash(repo, task) and " + stash" or ""
+            stashstr = hasstash(repo, task) and ' + stash' or ''
 
         if tinfo['state'] == 0: state = 'new'
         if tinfo['state'] == 1: state = 'active'
         if tinfo['state'] == 2: state = 'completed'
-        ui.write("state:           %s%s\n" % (state, stashstr))
+        ui.write('state:           %s%s\n' % (state, stashstr))
         if tinfo['state'] != 0:
             nodes = tasknodes(repo, tinfo)
             nodes.reverse()
-            changesets = "changesets (%d):" % len(nodes)
-            ui.write("%-16s %s\n" % (changesets, prettynode(ui, repo, nodes[0])))
+            changesets = 'changesets (%d):' % len(nodes)
+            ui.write('%-16s %s\n' % (changesets, prettynode(ui, repo,
+                nodes[0])))
             for n in nodes[1:]:
-                ui.write("                 %s\n" % prettynode(ui, repo, n))
+                ui.write('                 %s\n' % prettynode(ui, repo, n))
         return
 
     # trim a task
     if trim:
         if not rev:
-            raise util.Abort(_("revision required"))
+            raise util.Abort(_('revision required'))
         else:
             trimnode = repo.lookup(rev)
             tnodes = tasknodes(repo, tasks[task])
             if trimnode not in tnodes:
-                raise util.Abort(_("revision not in task"))
+                raise util.Abort(_('revision not in task'))
             if trimnode == tasks[task]['start']:
                 tasks[task]['start'] = None
                 tasks[task]['end'] = None
     # append to task
     if append:
         if not rev:
-            raise util.Abort(_("revision required"))
+            raise util.Abort(_('revision required'))
         anode = repo.lookup(rev)
         nodes = repo.changelog.nodesbetween([tasknode(repo, tasks[task])], [anode])[0]
         if len(nodes) < 2:
-            raise util.Abort(_("no new revs to add"))
+            raise util.Abort(_('no new revs to add'))
         if len ([n for n in nodes if repo.changelog.parents(n)[1] != nullid]):
-            raise util.Abort(_("tasks cannot include merged nodes (nodes with two parents)"))
+            raise util.Abort(
+                _('tasks cannot include merged nodes (nodes with two parents)'))
 
         # now actually append
         if tasks[task]['state'] == 0: # new
 
     # create a task
     if task != None:
-        if "\n" in task:
-            raise util.Abort(_("task name cannot contain newlines"))
-        if "," in task:
-            raise util.Abort(_("task name cannot contain commas"))
+        if '\n' in task or ' ' in task or ',' in task:
+            raise util.Abort(
+                _('task name cannot contain newlines, spaces, or commas'))
         task = task.strip()
         if task in tasks and not force:
-            raise util.Abort(_("a task of the same name already exists"))
-        if ((task in repo.branchtags() or task == repo.dirstate.branch()) and not force):
-            raise util.Abort(_("a task cannot have the name of an existing branch"))
+            raise util.Abort(_('a task of the same name already exists'))
+        if ((task in repo.branchtags() or task == repo.dirstate.branch()) and
+                not force):
+            raise util.Abort(
+                _('a task cannot have the name of an existing branch'))
         if (task in repo.tags() and not force):
-            raise util.Abort(_("a tag of the same name already exists"))
+            raise util.Abort(_('a tag of the same name already exists'))
         if rev:
             nodes = [ repo.lookup(r) for r in cmdutil.revrange(repo, [rev]) ]
             parentnode = nodes[0]
             startnode = None
             state = 0
             if len(nodes) > 1:
-                if len ([n for n in nodes[1:] if repo.changelog.parents(n)[1] != nullid]):
-                    raise util.Abort(_("tasks cannot include merged nodes (nodes with two parents)"))
+                if len ([n for n in nodes[1:]
+                    if repo.changelog.parents(n)[1] != nullid]):
+                    raise util.Abort(_('tasks cannot include merged nodes '
+                        '(nodes with two parents)'))
                 startnode = nodes[1]
                 state = 1
             if len(nodes) > 2:
                 endnode = nodes[-1]
-            tasks[task] = {'parent': parentnode, 'start': startnode, 'end': endnode, 'state': state }
+            tasks[task] = {'parent': parentnode, 'start': startnode, 'end':
+                    endnode, 'state': state }
         else:
-            tasks[task] = {'parent': repo.changectx('.').node(), 'start': None, 'end': None, 'state': 0 }
-
+            tasks[task] = {'parent': repo.changectx('.').node(), 'start': None,
+                    'end': None, 'state': 0 }
         write(ui, repo, tasks)
 
         if not rev and ui.configbool('tasks', 'auto.track.new'):
             setcurrent(ui, repo, task, True)
         return
 
-
     # list tasks
     if task == None:
         if rev:
-            raise util.Abort(_("task name required"))
+            raise util.Abort(_('task name required'))
         if len(tasks) == 0:
-            ui.status("no tasks set\n")
+            ui.status('no tasks set\n')
         else:
             for t, tinfo in tasks.iteritems():
                 if tinfo['state'] == 2 and not all: continue
                         ncsets = len(tasknodes(repo, tinfo))
                     else:
                         ncsets = 1
-                    csets = " (%d cset%s%s)" % (ncsets, (ncsets != 1) and 's' or '', complete)
+                    csets = ' (%d cset%s%s)' % \
+                        (ncsets, (ncsets != 1) and 's' or '', complete)
                 else:
                     nodeprefix = '>'
                     csets = ''
-                ui.write(" %s %-12s %s%s%s%s\n" % (prefix, t, nodeprefix, prettynode(ui, repo, tnode), stashstr, csets))
-
+                ui.write(' %s %-12s %s%s%s%s\n' % (prefix, t, nodeprefix,
+                    prettynode(ui, repo, tnode), stashstr, csets))
 
 def nodeexists(repo, node):
     ''' Determine if this node exists in the repo. '''
     else:
         return True
 
-def strip(orig, ui, repo, node, backup="all"):
+def strip(orig, ui, repo, node, backup='all'):
     '''Strip tasks if revisions are stripped using the mercurial.strip method.
     This usually happens during qpush and qpop.  If all task nodes are removed
     completely the task will be deleted.  If it is only partially stripped, it
         write(ui, repo, tasks)
     return res
 
-
 def hasstash(repo, task):
     for f in stashfiles(repo, task):
         if os.path.exists(repo.join(f)):
             return True
     return False
 
-
 def stashfiles(repo, task):
     stashhex = util.sha1(task).hexdigest()
-    return ( "tasks/%s.stash" % stashhex, "tasks/%s.dirstate" % stashhex )
-
+    return ( 'tasks/%s.stash' % stashhex, 'tasks/%s.dirstate' % stashhex )
 
 def removestashfiles(repo, task):
     for f in stashfiles(repo, task):
             except OSError, inst:
                 ui.warn(_('error removing stash file: %s\n') % str(inst))
 
-
 def unstash(ui, repo, task):
-    """Unstashes a working copy.  Returns True if a stash was found and applied,
-    False if no stash exists."""
+    '''Unstashes a working copy.  Returns True if a stash was found and applied,
+    False if no stash exists.'''
     if not hasstash(repo, task):
         return False
 
-    ui.write("unstashing task: %s\n" % task)
-    ui.debug("unstashing %s from stash file: %s\n" % (task, stashfiles(repo, task)[0]))
+    ui.write('unstashing task: %s\n' % task)
+    ui.debug('unstashing %s from stash file: %s\n'
+            % (task, stashfiles(repo, task)[0]))
 
     patchfile = repo.join(stashfiles(repo, task)[0])
     dirstatefile = repo.join(stashfiles(repo, task)[1])
 
-
     files = {}
     if os.path.exists(patchfile):
         try:
         except Exception, inst:
             ui.note(str(inst) + '\n')
             ui.warn('patch failed, unable to continue\n')
-            ui.warn("see %s for stash patch\n" % patchfile)
+            ui.warn('see %s for stash patch\n' % patchfile)
             return False
 
         if files:
             patch.updatedir(ui, repo, files)
 
     if os.path.exists(dirstatefile):
-        shutil.copyfile(dirstatefile, repo.join("dirstate"))
+        shutil.copyfile(dirstatefile, repo.join('dirstate'))
 
     removestashfiles(repo, task)
     return True
 
-
 def getdiff(ui, repo):
     m = cmdutil.match(repo)
     o = patch.diffopts(ui, {'git': True})
     return patch.diff(repo, match = m, opts = o)
 
-
 def stash(ui, repo, task):
-    """Performs a stash if the working copy is dirty.  Returns True if a stash
-    was performed otherwise False."""
+    '''Performs a stash if the working copy is dirty.  Returns True if a stash
+    was performed otherwise False.'''
 
     st = repo.status()
     if not bool(filter(None, st)):
         return False # no stashing necessary
 
-    ui.write("stashing task: %s\n" % task)
+    ui.write('stashing task: %s\n' % task)
 
     # stash dirstate
-    shutil.copyfile(repo.join("dirstate"), repo.join(stashfiles(repo, task)[1]))
+    shutil.copyfile(repo.join('dirstate'), repo.join(stashfiles(repo, task)[1]))
 
-    ui.debug("stashing %s to stash file: %s\n" % (task, stashfiles(repo, task)[0]))
+    ui.debug('stashing %s to stash file: %s\n' %
+        (task, stashfiles(repo, task)[0]))
+
     p = repo.opener(stashfiles(repo, task)[0], 'w')
-    p.write("# stash of task %s\n" % task)
-    p.write("# created %s\n#-\n" % time.strftime("%m/%d/%y %H:%M:%S", time.localtime()))
+    p.write('# stash of task %s\n' % task)
+    p.write('# created %s\n#-\n' %
+        time.strftime('%m/%d/%y %H:%M:%S', time.localtime()))
     for i in repo.status():
         for j in i:
-            p.write("# %s %s\n" % (j, filesha(repo, j)))
-    p.write("#-\n")
+            p.write('# %s %s\n' % (j, filesha(repo, j)))
+    p.write('#-\n')
 
     # remove all missing files before getting diff, dirstate is already stashed
     repo.remove(st[3])
     p.close()
     return True
 
-
 def filesha(repo, file):
+    '''returns a sha1 of file contents'''
     f = util.pathto(repo.root, None, file)
     if os.path.exists(f):
         contents = open(f).read()
         contents = '';
     return util.sha1(contents).hexdigest()
 
-
 def cleanup(repo):
     '''removes all changes from the working copy and makes it so
     there isn't a patch applied; copied from attic'''
     node = repo.dirstate.parents()[0]
     hg.clean(repo, node, False)
 
-
 def reposetup(ui, repo):
     if not isinstance(repo, localrepo.localrepository):
         return
     class task_repo(repo.__class__):
         def rollback(self):
             if os.path.exists(self.join('tasks/undo.tasks')):
-                util.rename(self.join('tasks/undo.tasks'), self.join('tasks/tasks'))
+                util.rename(self.join('tasks/undo.tasks'),
+                    self.join('tasks/tasks'))
             return super(task_repo, self).rollback()
 
         def lookup(self, key):
                 if tasknode(self, tinfo) in parents:
                     if len(parents) > 1:
                         if tinfo['state'] == 1:
-                            ui.write("completing task %s\n" % tname)
+                            ui.write('completing task %s\n' % tname)
                             if hasstash(self, task):
-                                ui.write("warning: task stash still present\nupdate to task to retrieve stash")
+                                ui.write('warning: task stash still present\n'
+                                    ' update to task to retrieve stash')
                             tinfo['state'] = 2
                             if tname == currenttask:
                                 setcurrent(ui, repo, None)
                 write(ui, repo, tasks)
             return node
 
-        def push(self, remote, force=False, revs=None, completed_tasks=False, all_tasks=False):
+        def push(self, remote, force=False, revs=None, completed_tasks=False,
+                all_tasks=False):
             if all_tasks:
                 return super(task_repo, self).push(remote, force, revs)
 
             if completed_tasks and all_tasks:
-                raise util.Abort(_("cannot specify both --all-tasks and --completed-tasks"))
+                raise util.Abort(_('cannot specify both --all-tasks and '
+                    '--completed-tasks'))
 
             # suppress output of this since it unfortunately gets called again
             ui.pushbuffer()
             if not itasknodes:
                 return super(task_repo, self).push(remote, force, revs)
 
-            # check to see if we have any outgoing nodes that are in incompleted tasks
+            # check to see if we have any outgoing nodes that are in incompleted
+            # tasks
             havebadnode = False
             for onode in outnodes:
                 if onode in itasknodes:
                 return super(task_repo, self).push(remote, force, revs)
 
             if not completed_tasks:
-                raise util.Abort(_("pushing incomplete tasks\n(use --all-tasks to force or --completed-tasks to prune)"))
+                raise util.Abort(_('pushing incomplete tasks\n'
+                    '(use --all-tasks to force or --completed-tasks to prune)'))
 
             # ok now we prune
-            # there is definitely a slicker way to do this
-            ui.status("searching for completed tasks\n")
+            ui.status('searching for completed tasks\n')
             nodestoremove = []
             for onode in outnodes:
                 for tname, tinfo in tasks.iteritems():
                     if tinfo['state'] == 1:
                         if onode in tasknodes(repo, tinfo):
-                            # we have to remove all nodes between this node and the
-                            # end node for this task
-                            for n in self.changelog.nodesbetween([ onode ], None)[0]:
+                            # we have to remove all nodes between this node and
+                            # the end node for this task
+                            for n in self.changelog.nodesbetween([ onode ],
+                                    None)[0]:
                                 nodestoremove.append(n)
             newoutnodes = [ n for n in outnodes if n not in nodestoremove ]
             return super(task_repo, self).push(remote, force, newoutnodes)
 
 
 def uisetup(ui):
-    extensions.wrapfunction(repair, "strip", strip)
+    extensions.wrapfunction(repair, 'strip', strip)
     extensions.wrapcommand(commands.table, 'update', tasksupdate)
     extensions.wrapcommand(commands.table, 'log', taskslog)
     extensions.wrapcommand(commands.table, 'export', tasksexport)
     entry = extensions.wrapcommand(commands.table, 'push', taskspush)
-    entry[1].append(('', 'completed-tasks', None, _("push all heads that have completed tasks only")))
-    entry[1].append(('', 'all-tasks', None, _("push all heads including those with incomplete tasks")))
+    entry[1].append(('', 'completed-tasks', None,
+        _('push all heads that have completed tasks only')))
+    entry[1].append(('', 'all-tasks', None,
+        _('push all heads including those with incomplete tasks')))
 
     try:
         transplant = extensions.find('transplant')
         if transplant:
-            entry = extensions.wrapcommand(transplant.cmdtable, 'transplant', taskstransplant)
-            entry[1].append(('t', 'task', '', _("transplant all changesets in task TASK")))
+            entry = extensions.wrapcommand(transplant.cmdtable, 'transplant',
+                taskstransplant)
+            entry[1].append(('t', 'task', '',
+                _('transplant all changesets in task TASK')))
     except:
         pass
-
     try:
         patchbomb = extensions.find('patchbomb')
         if patchbomb:
-            entry = extensions.wrapcommand(patchbomb.cmdtable, 'email', tasksemail)
-            entry[1].append(('t', 'task', '', _("email all changesets in task TASK")))
+            entry = extensions.wrapcommand(patchbomb.cmdtable, 'email',
+                tasksemail)
+            entry[1].append(('t', 'task', '',
+                _('email all changesets in task TASK')))
     except:
         pass
 
-
 def tasksemail(orig, ui, repo, *revs, **opts):
     if opts['task']:
         if revs or opts['rev']:
-            raise util.Abort(_("cannot specify rev and task"))
+            raise util.Abort(_('cannot specify rev and task'))
         tasks = parse(repo)
         if opts['task'] not in tasks:
-            raise util.Abort(_("invalid task name"))
+            raise util.Abort(_('invalid task name'))
 
         if tasks[opts['task']]['state'] == 0:
-            raise util.Abort(_("task has no changesets"))
+            raise util.Abort(_('task has no changesets'))
 
         tnodes = tasknodes(repo, tasks[opts['task']])
-        opts['rev'] = ["%d:%d" % (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1]))]
-        ui.write("this is the rev i'm sending... %s\n" % opts['rev'])
+        opts['rev'] = ['%d:%d' %
+            (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1]))]
     return orig(ui, repo, *revs, **opts)
 
 def tasksexport(orig, ui, repo, *revs, **opts):
         tasks = parse(repo)
         if revs[0] in tasks:
             if tasks[revs[0]]['state'] == 0:
-                raise util.Abort(_("no changesets in task %s" % revs[0]))
+                raise util.Abort(_('no changesets in task %s' % revs[0]))
             tnodes = tasknodes(repo, tasks[revs[0]])
-            revs = [ "%d:%d" % (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1])) ]
+            revs = [ '%d:%d' %
+                (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1]))]
     return orig(ui, repo, *revs, **opts)
 
-
 def taskstransplant(orig, ui, repo, *revs, **opts):
     if not opts['task']:
         return orig(ui, repo, *revs, **opts)
 
-    if revs: raise util.Abort(_("cannot specify revs and task"))
-    if opts['branch']: raise util.Abort(_("cannot specify branch and task"))
-    if opts['source']: raise util.Abort(_("cannot specify source and task"))
+    if revs: raise util.Abort(_('cannot specify revs and task'))
+    if opts['branch']: raise util.Abort(_('cannot specify branch and task'))
+    if opts['source']: raise util.Abort(_('cannot specify source and task'))
 
     tasks = parse(repo)
 
     if opts['task'] not in tasks:
-        raise util.Abort(_("invalid task name"))
+        raise util.Abort(_('invalid task name'))
 
     if tasks[opts['task']]['state'] == 0:
-        raise util.Abort(_("task has no changesets"))
+        raise util.Abort(_('task has no changesets'))
 
     tnodes = tasknodes(repo, tasks[opts['task']])
-    revs = [ "%d:%d" % (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1])) ]
+    revs = [ '%d:%d' %
+        (repo.changelog.rev(tnodes[0]), repo.changelog.rev(tnodes[-1])) ]
     return orig(ui, repo, *revs, **opts)
 
-
 def taskslog(orig, ui, repo, *args, **opts):
     '''allows you to use 'hg log [NAME]' '''
     if len(args) > 0:
             args = [ n for n in args[1:] ]
             if len(nodes) < 1:
                 return
-        opts['rev'] = ["%d:%d" % (repo.changelog.rev(nodes[-1]), repo.changelog.rev(nodes[0]))]
+        opts['rev'] = ['%d:%d' %
+            (repo.changelog.rev(nodes[-1]), repo.changelog.rev(nodes[0]))]
     return orig(ui, repo, *args, **opts)
 
-
 def stashshas(repo, task):
+    '''retrieve sha values from task stash'''
     stashpatch = stashfiles(repo, task)[0]
     shas = {}
     if os.path.exists(repo.join(stashpatch)):
         f = repo.opener(stashpatch)
         shasection = False
         for line in f:
-            if line == "#-\n":
+            if line == '#-\n':
                 if shasection:
                     break
                 else:
         # let's see if we should bail out before going through the trouble of
         # creating a stash
         # we are changing hg behaviour here, maybe people like the auto-merging?
-        if not ontask and bool(filter(None, repo.status())) and not 'clean' in opts:
-            raise util.Abort(_("uncommited changed in working copy, use --clean to abandon changes"))
+        if not ontask and bool(filter(None, repo.status())) \
+            and not 'clean' in opts:
+            raise util.Abort(_('uncommited changed in working copy, '
+                'use --clean to abandon changes'))
 
         # check for untracked files that will be clobbered
         untracked = repo.status(unknown = True)[4]
                 if f in shas:
                     untrackedinstash.append(f)
                     if filesha(repo, f) != shas[f]:
-                        raise util.Abort(_("untracked file in working directory differs from file in requested revision: '%s'" % f))
-
+                        raise util.Abort(_('untracked file in working '
+                            'directory differs from file in requested '
+                            'revision: \'%s\'' % f))
 
     # store all untracked files that are also in stash
     storeuntracked(repo, untrackedinstash)
         if stash(ui, repo, currenttask):
             # cleanup is safe as we have stashed all changes
             cleanup(repo)
-    # perform actual update
     try:
         res = orig(ui, repo, *args, **opts)
     except:
 
     return res
 
-
 def storeuntracked(repo, untracked):
     if not untracked:
         return
     os.mkdir(repo.join('tasks/untrackedbackup'))
     for f in untracked:
         shaname = util.sha1(f).hexdigest()
-        util.copyfile(util.pathto(repo.root, None, f), repo.join('tasks/untrackedbackup/%s' % shaname))
+        util.copyfile(util.pathto(repo.root, None, f),
+            repo.join('tasks/untrackedbackup/%s' % shaname))
         util.unlink(util.pathto(repo.root, None, f))
 
-
 def restoreuntracked(repo, untracked):
     for f in untracked:
         shaname = util.sha1(f).hexdigest()
-        util.copyfile(repo.join('tasks/untrackedbackup/%s' % shaname), util.pathto(repo.root, None, f))
-
+        util.copyfile(repo.join('tasks/untrackedbackup/%s' % shaname),
+            util.pathto(repo.root, None, f))
 
 def removeuntracked(repo):
     if os.path.exists(repo.join('tasks/untrackedbackup')):
         for f in os.listdir(repo.join('tasks/untrackedbackup')):
-            os.unlink("%s/%s" % (repo.join('tasks'), f))
+            os.unlink('%s/%s' % (repo.join('tasks'), f))
         os.rmdir(repo.join('tasks/untrackedbackup'))
 
-
 def debugtask(ui, repo, task=None, showstash=False, purge=False, force=False):
     '''tasks debug'''
 
     def showtask(ui, repo, tname, tinfo):
-        ui.write("%s\n" % tname)
-        ui.write(" state:  %d\n" % tinfo['state'])
-        ui.write(" parent: %s\n" % prettynode(ui, repo, tinfo['parent']))
-        ui.write(" start:  %s\n" % prettynode(ui, repo, tinfo['start']))
-        ui.write(" end:    %s\n" % prettynode(ui, repo, tinfo['end']))
-        ui.write(" stash files:\n")
+        ui.write('%s\n' % tname)
+        ui.write(' state:  %d\n' % tinfo['state'])
+        ui.write(' parent: %s\n' % prettynode(ui, repo, tinfo['parent']))
+        ui.write(' start:  %s\n' % prettynode(ui, repo, tinfo['start']))
+        ui.write(' end:    %s\n' % prettynode(ui, repo, tinfo['end']))
+        ui.write(' stash files:\n')
         showstashfiles(ui, repo, tname)
-        ui.write("\n")
+        ui.write('\n')
 
     def showstashfile(ui, repo, sf):
         if os.path.exists(repo.join(sf)):
-            existsstr = " - exists"
+            existsstr = ' - exists'
         else:
-            existsstr = " - does not exist"
-        ui.write("  %s %s\n" % (sf, existsstr))
+            existsstr = ' - does not exist'
+        ui.write('  %s %s\n' % (sf, existsstr))
 
     def showstashfiles(ui, repo, tname):
         for sf in stashfiles(repo, tname):
 
 
     if purge and not force:
-        raise util.Abort(_("this will wipe out all your tasks info, the entire\n.hg/tasks directory, if you're sure, use -f to force"))
+        raise util.Abort(_('this will wipe out all your tasks info, the '
+            'entire\n.hg/tasks directory, if you are sure, use -f to force'))
 
     if purge:
         for f in os.listdir(repo.join('tasks')):
-            os.unlink("%s/%s" % (repo.join('tasks'), f))
+            os.unlink('%s/%s' % (repo.join('tasks'), f))
         os.rmdir(repo.join('tasks'))
         return
 
     if showstash and not task:
-        raise util.Abort(_("must specify task with --showstash"))
+        raise util.Abort(_('must specify task with --showstash'))
 
     tasks = parse(repo)
 
     if not task:
-        ui.write("current task: %s\n\n" % str(current(repo)))
-        ui.write("number of tasks: %d\n\n" % len(tasks))
+        ui.write('current task: %s\n\n' % str(current(repo)))
+        ui.write('number of tasks: %d\n\n' % len(tasks))
         for tname, tinfo in tasks.iteritems():
             showtask(ui, repo, tname, tinfo)
         return
 
     if task not in tasks:
-        raise util.Abort(_("task does not exist"))
+        raise util.Abort(_('task does not exist'))
 
     if showstash:
-        ui.write("stash for %s:\n" % task)
+        ui.write('stash for %s:\n' % task)
         sfiles = stashfiles(repo, task)
         for sf in sfiles:
             showstashfile(ui, repo, sf)
         if os.path.exists(repo.join(sfiles[0])):
-            ui.write("---------------\n")
+            ui.write('---------------\n')
             ui.write(open(repo.join(sfiles[0])).read())
         return
 
     Calls custom push command with new custom args'''
     # all copied from mercurial/commands.py
     dest, revs, checkout = hg.parseurl(
-        ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
+        ui.expandpath(dest or 'default-push', dest or 'default'),
+        opts.get('rev'))
     cmdutil.setremoteconfig(ui, opts)
 
     other = hg.repository(ui, dest)
     if revs:
         revs = [repo.lookup(rev) for rev in revs]
     # add in our new options
-    r = repo.push(other, opts.get('force'), revs=revs, completed_tasks=opts.get('completed_tasks'), all_tasks=opts.get('all_tasks'))
+    r = repo.push(other, opts.get('force'), revs=revs,
+        completed_tasks=opts.get('completed_tasks'),
+        all_tasks=opts.get('all_tasks'))
     return r == 0
 
 cmdtable = {
-    "tasks":
+    'tasks':
         (task,
-            [
-                ('f', 'force', False, _('force')),
-                ('r', 'rev', '', _('revision')),
-                ('d', 'delete', False, _('delete a given task')),
-                ('c', 'complete', False, _('complete a given task')),
-                ('u', 'resume', False, _('resume a given task')),
-                ('A', 'delete-all', False, _('deletes all tasks')),
-                ('C', 'delete-complete', False, _('deletes all completed tasks')),
-                ('m', 'rename', '', _('rename a given task')),
-                ('i', 'info', False, _('gives info a given task')),
-                ('a', 'all', False, _('all tasks including completed tasks')),
-                ('n', 'append', False, _('append revisions to task')),
-                ('t', 'trim', False, _('trim revisions from given task')),
-                ('',  'purge-stash', False, _('purge stash information from given task'))
-                ],
-            _('hg tasks [-f] [-d] [-i] [-c] [-u] [-A] [-C] [-i] [-a] [-m OLDNAME NEWNAME] [-r REV] [NAME] [-t REV] [-n REV]')),
-    "debugtasks":
+        [
+        ('f', 'force', False, _('force')),
+        ('r', 'rev', '', _('revision')),
+        ('d', 'delete', False, _('delete a given task')),
+        ('c', 'complete', False, _('complete a given task')),
+        ('u', 'resume', False, _('resume a given task')),
+        ('A', 'delete-all', False, _('deletes all tasks')),
+        ('C', 'delete-complete', False, _('deletes all completed tasks')),
+        ('m', 'rename', '', _('rename a given task')),
+        ('i', 'info', False, _('gives info a given task')),
+        ('a', 'all', False, _('all tasks including completed tasks')),
+        ('n', 'append', False, _('append revisions to task')),
+        ('t', 'trim', False, _('trim revisions from given task')),
+        ('',  'purge-stash', False, _('purge stash information from given task'))
+        ],
+        _('hg tasks [-f] [-d] [-i] [-c] [-u] [-A] [-C] [-i] [-a] [-m OLDNAME'
+            ' NEWNAME] [-r REV] [NAME] [-n REV] [-t REV] [--purge-stash] ')),
+    'debugtasks':
         (debugtask,
-            [
-                ('',  'showstash', False, _('show stash info')),
-                ('',  'purge', False, _('purge all tasks')),
-                ('f', 'force', False, _('force'))
-                ],
-            _('hg debugtasks [-f] [--showstash] [--purge] [NAME]')),
+        [
+        ('',  'showstash', False, _('show stash info')),
+        ('',  'purge', False, _('purge all tasks')),
+        ('f', 'force', False, _('force'))
+        ],
+        _('hg debugtasks [-f] [--showstash] [--purge] [NAME]')),
 }