Supporting relative paths for hg diff and patch

Siddharth Agarwal sid at
Tue Mar 3 01:33:04 CST 2015

On 03/02/2015 11:29 PM, Siddharth Agarwal wrote:
> As we're merging repos, something that would be incredibly useful for
> both automated tools and humans at Facebook would be the ability to
> produce and apply patches relative to a subdirectory.

For reference, Git supports this with

git diff --relative=path


git apply --directory=path

> So (tentative UI):
> hg diff --relative prefix/
> would produce diffs only from files within prefix/, where all the paths
> are relative to prefix/. (Moves into and out of prefix/ would be
> presented as adds and deletes respectively.)
> Similarly,
> hg import --relative prefix/
> would apply a patch assuming paths in it are relative to prefix.
> While we could do this at a higher level by munging paths in the patch
> data, it's really much easier to do within Mercurial. (Moves make things
> particularly tricky.)
> Does that sound like a reasonable feature request? I'd be happy to
> implement it.
> - Siddharth

More information about the Mercurial-devel mailing list