Home

HG_TIMESTAMP_UPDATE

The hg_timestamp_update is a small Java program intended as an update-hook for the Mercurial (hg) Source Control Management system. Used this way, the program will set the modification-time of each updated file to that of the last revision involving the file. In other words, all the updated files would get a modification date which is no newer than the date of the revision that is updated to.

The hg_timestamp_update will restore the modification-times whenever files in the repository are updated, without making any other changes to the files in the working directory or to the repository. The time-stamps stored in Mercurial's normal revision history are used. Thus, a repository does not need to be "prepared" in any way in order to work with hg_timestamp_update. At any time hg_timestamp_update can be enabled/disabled for a repository, by registering/removing its update-hooks.

Usage

It is recommended to install these hooks on a per-repository basis. To get the modification-dates of all files restored when cloning a repository, use the following procedure:

  1. hg clone --noupdate SOURCE [DEST]
  2. register the update-hooks in the newly cloned repository's hgrc file (see hooks/hgrc)
  3. hg update [[-r] REV]

Background

You may find it useful to have the modification-time show you which files were changed recently in a repository and which have been untouched for years - regardless of when you updated your local working directory. In particular, when keeping documents and other "non-code" files under revision control, the (restored) modification-time could be used for versioning the documents. The hg_timestamp_update was developed for such purposes.

Please note that this feature is undesirable in combination with time-stamp based build tools (e.g. make)! See the Mercurial FAQ.

This program could be considered a work-around for a requested (still missing) feature of core Mercurial: issue326.

An alternative approach has also been developed, the TimestampExtension. The table below outlines the differences between hg_timestamp_update and TimestampExtension:

hg_timestamp_updateTimestamp Extension
uses the commit-time of changesetsstores the timestamps of selected files in a database
modification-times of all changed files are adjusted upon updatemodification-times of the pre-selected files are adjusted upon update
the hook can be enabled/disabled for any repository at any timethe extension must be enabled from the beginning in order to track time-stamps
a preupdate- and an update-hook for Mercurialan extension and an update-hook for Mercurial

Installation

  1. Clone the project from bitbucket: hg clone http://bitbucket.org/esskov/hg_timestamp_update/
    Or just download a copy: http://bitbucket.org/esskov/hg_timestamp_update/downloads/
  2. Copy the hg_timestamp_update.jar, the hg_timestamp_files.style and the two hook scripts to the appropriate hg directories; InstallIt.bat or InstallIt.sh will normally do this for you.
  3. Register the update and preupdate hooks in the hgrc file of each repository where you want time-stamp restoring (you can copy from hooks/hgrc).

The hg_timestamp_update package has been tested on both Linux and Windows, with both command-line Mercurial and with TortoiseHg. A Java Runtime package is required (i.e., the “java” command), which you may or may not have already on your system.

Aside from the fact that hg_timestamp_update is not a regular Mercurial extension there are currently no known issues - however, use it at your own risk. Comments and patches are very welcome.

News

2013-03-17: The new version 0.5 of this extension now handles updates across (and within) branches correctly, using the excellent revset feature of Mercurial.

2011-03-15: Mercurial 1.8 / TortoiseHg 2.0 (Windows) has been reported to break hg_timestamp_update. This issue has now been fixed in Mercurial 1.8.1 / TortoiseHg 2.0.2.

Tips

Q: How do I restore the time-stamps of all files in an existing repository?
A: hg up -q -r null && hg up -q -r tip

Q: How do I check if hg_timestamp_update.jar has been installed correctly (by the install script)?
A: java -jar /usr/share/mercurial/hg_timestamp_update.jar 0 tip 2
A: java -jar %HG_ROOT%\hg_timestamp_update.jar 0 tip 2

Q: How do I make hg_timestamp_update work silently, i.e. without printing any [hg_timestamp hook] lines?
A: Add 0 after the HG_PARENT1 argument, in the java call in the JavaUpdateHook.sh/.cmd hook.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.