Tasks extension for mercurial

Tasks are collections of contiguous changesets. A task can be short or long lived, but its information is only available locally. This extension overrides the behaviour of push so that it will not push incomplete tasks by default. A task can be in one of 3 states:

new - this task has no changesets only a parent node

active - a task with some changesets but not complete

complete - a task with some changesets and marked as complete

Use 'hg tasks' to list all new and active tasks. 'hg tasks --all' will show completed tasks along with those that are new and active.

This extension adds two new options to push:

--all-tasks will push all tasks including incomplete tasks

--completed-tasks will only push completed tasks

Use 'hg update [TASK]' to update to the tip node of a task and set it as current. When a task is set as current, all subsequent commits will be assigned/appended to the task.

If the auto.track.new option is set, newly created tasks will automatically be set as current. Otherwise, you will need to first create the task, and then update to it to make it current.

If the auto.stash option is set, your locally changed tracked files will be stashed when using 'hg update' to another revision.

enabling the tasks extension

To enable this extension download the tasks.py and save it somewhere on your system. Then edit your config file so that it has something similar to:

[extensions]
tasks = /my/path/to/tasks.py

optional behaviour

The tasks extension can automatically mark newly created tasks as current if you set the auto.track.new. This will allow you to start work on a task right away. To enable this functionality, add this to your config:

[tasks]
auto.track.new = True

You can have the tasks extension automatically 'stash' changes to tracked files in your working copy when you are working on a task. This allows you to update to a task, do some work, and then update to another task or node and not lose your changes. This means you can switch your context easily and not worry about committing your files. To enable auto stashing of tasks, add this to your config:

additional push options

This extension changes the behaviour of the 'push' command and adds two new options.

When performing an 'hg push' you will be warned and the operation will abort if you have incomplete tasks in your outgoing changesets. This is to stop you from pushing incomplete work. When this occurs, you can do one of two things:

1. push the incomplete work, use the --all-tasks option:

$ hg push --all-tasks

2. push only completed tasks (all revisions belonging to an incomplete task will be stripped from the outgoing changesets), use the --completed-tasks option:

$ hg push --completed-tasks

Note that push ignores tasks that are new (i.e. not complete but have no changesets attached).

Visual example of push behaviour:

additional outgoing options

The --all-tasks and --completed-tasks options are also added to the 'outgoing' command.

If you don't specify either of these new options and there are incomplete tasks changesets not in your remote repo, the output will be the same except with a warning that some changesets will not be pushed by default.

1. use --all-tasks option to make outgoing report all outgoing changesets with no warnings about changesets belonging to incomplete tasks:

$ hg outgoing --all-tasks

2. use --completed-tasks option to make outgoing only show changesets that will be pushed when using the --completed-tasks option with the push command:

$ hg outgoing --completed-tasks

using transplant with tasks

If you have the transplant extensions entabled you can use it as follows:

$ hg transplant --task mytask
$ hg transplant -t mytask

using log with tasks

The log command is wrapped to accept task names as an argument and will show only changesets that belong to a particular task.

$ hg log mytask

using export with tasks

The export command is wrapped to accept a task name as an argument and will then create a patch from the start->end nodes of the given task.

$ hg export mytask

using patchbomb with tasks

The email command is wrapped to accept a task name as an argument and will then email patches representing each changeset assigned to the given task.

$ hg email --task mytask

using mq with tasks

The qimport command is wrapped to accept a task name as an argument and will then import all patches in the given task.

$ hg qimport -t mytask
$ hg qimport --task mytask

implementation notes

Task information is stored in two files:

.hg/tasks/tasks # all task info
.hg/tasks/tasks.current # the current task

The file format for the tasks and tasks.complete filesa are as follows:

<taskname>,<parent_node>,<start_node>,<end_node>,state

The state can be one of the following: 0 - new, 1 - active, 2 - complete.
The first entry shows a task with 2 or more changesets assigned to it, the second entry is a newly created task with no changesets - only a parent:

The above two tasks were created on the same revision (they share the same parent 2ed12f...) but only task1 has any work done against it.

Task stash information is stored in two files, one holds the diff of the working copy compared to the revision stored in hg, the other is a backup of the dirstate (so that stash will rememember if you did something like 'hg add'):

.hg/tasks/<task>.dirstate # copy of .hg/dirstate
.hg/tasks/<task>.stash # a git diff of working copy compared to current rev + sha list for all modified files

The stash file is divided into 3 parts. 1) two lines which show the task name and date of stash creation. 2) one or more lines separated by "#-" markers; each one of these lines contains a filename and a sha of the contents. 3) the actual git patch.

request for help/improvements

Code optimizations/recommendations/patches are welcome. I know that this extension does not make the best use of either the Python language or the Mercurial API.