Timestamp Extension

This extension is not distributed with Mercurial.

Author: Friedrich Kastner-Masilko

Repository: http://bitbucket.org/face/timestamp/

(Developed with Mercurial 1.1.2 - works up to 1.3 until revision 13:12e14f81d23d - works with 1.4 up to 1.5 from revision 16:6ea28b25c44f)

This extension is still in alpha, use it at your own risk.


This extension saves and restores timestamps for files. It does this by means of a database file .hgtimestamp, residing in the repo's root and thus being versioned. The extension forces a hook/wrapping of the commit operation, updating the timestamp database before commiting. It additionally provides a postupdate hook for restoring the timestamps on update to another changeset and a command for explicit save and restore.

For an alternative approach to the timestamping problem, please take a look at Esben Skovenborg's timestamp hook. (quick differences: does not use mtime, but commit time; no selection of files possible)

Specifying tracked files

To start tracking timestamps of files, add a .hgtimestamp text file to your repo's root. Edit the file with a text editor and add a line for each file you want to track. Simply put the file's path - as it appears in the output of Mercurial's status command - in this line.

The extension edits this database file by means of adding the timestamp as double value to each line - comma separated. Files that can't be found will be ignored.

To stop tracking a file, simply remove it's line from the file.

For an initial commit of the .hgtimestamp file you can use the "hg timestamp -s" command to timestamp all specified files.


Configure your .hgrc to enable the extension by adding following lines:

timestamp = path/to/timestamp.py

This will already install the preprecommit hook. To additionally enable the postupdate hook for restoring the timestamps on update to another changeset, add the following lines:

update.timestamp = python:hgext.timestamp.hook

Unfortunately, this hook reference will not work with TortoiseHg. You will have to either:

  1. insert the timestamp.py file properly into the library.zip archive or
  2. use the following reference instead: update.timestamp = python:<DRIVELETTER>:\path\to\timestamp.py:hook

This workaround has been provided by Rob Maris.

Command Usage

The preprecommit hook saves timestamps for files in the database that are:

  1. modified or added during a commit without patterns specified or
  2. matched by the patterns specified in a commit.

To save the current timestamps for all files in the database, use the timestamp command with the save option:

hg timestamp -s

The postupdate hook automatically restores timestamps, if you update to another changeset. If you want to revert individual files and restore their timestamps without updating to a complete changeset, you can use the timestamp command with the restore option:

hg revert -r <changeset> FILE
hg revert -r <changeset> .hgtimestamps
hg timestamp -r

Unfortunately, this will restore the timestamps of all tracked files to the reverted changeset's status. An addition to define the file to be restored is on the TODO list.

To list the timestamps stored in the repo, use the timestamp command without options:

hg timestamp


TimestampExtension (last edited 2012-04-24 21:20:04 by ks3095497)