Export with diff hash?

Jason Harris jason at jasonfharris.com
Sun Jun 20 05:15:00 CDT 2010


Hi All,

In exporting patches (via 'hg export') the typical header looks like:

---------

# HG changeset patch
# User jfh <jason at jasonfharris.com>
# Date 1276961422 -7200
# Node ID 58e3679ba81330385744e98ccd5de9fb9e18e84b
# Parent  fb24fe2f74e0e97fca3044923ff24c817bf37d73
Some message

<diff content...>

---------

But the very point of exporting a patch is so you can import it again somewhere else. Internally the logic of 'hg import' will use the parent hash number for where to figure out to which exact revision the patch should apply. the import command has the '--exact' option to do exactly this.

However if one is importing the patch to a different tree or the history has been edited, which one can do through export followed by import, then the parent hash number will not exist as is. However, likely there is still the same 'parent' just with a different hash set. Ie the diff is the same for the parent, the author is the same, etc.

So would it make sense to include this in the above header. Something like:

---------

# HG changeset patch
# User jfh <jason at jasonfharris.com>
# Date 1276961422 -7200
# Node ID 58e3679ba81330385744e98ccd5de9fb9e18e84b
# Parent  fb24fe2f74e0e97fca3044923ff24c817bf37d73
# Diff Hash  c2838b6b38ab0823bac3486f82a246eb
Some message

<diff content...>

---------

Where the diff hash is just calculated hg diff -c parentRev | md5

Then if you do an export and then import there is a lot more chance the patches will "stick" in the right places. Of course Mercurial could still warn when the diff hash  could import in several places... (ie the diff might be present multiple times in the same repository (on different branches, etc.))

I sent a related message about this where I wanted to find if a patch / changeset was part of an existing repository.

It seems to me that hashes of diffs are a useful concept...

Cheers,
  Jas


> Hi Christoph & All,
> 
> I just saw Christoph Rissner's contains hg extension.
> 
> I was wondering if it can be extended (or maybe I am just missing something) or if there are other ways to look for rebased changesets, or imported changesets, or changesets arising from histedit. It often turns out in my work flows that I have a lot of temporary branches floating around, which sometimes have been included on the main branch and sometimes not, you can't use a changeset hash to figure out inclusion since after rebasing or maybe a histedit to change order in one of the branches the hashes will change.
> 
> Instead I was thinking to compute a new "diff hash" between the child and parent ie take the diff between child and parent with some context lines, and MD5 that. Then even if the change has been rebased or transplanted it will still be detected as the same thing.
> 
> Eg here is a simple example I contrived. Basically I used histedit to reorder some things in one clone and then pulled these reordered things into another clone, to end up with duplicates in my repository. Like so this:
> 
> [Bolt:/Development/MacHgDev/MacHgClone] MacHgClone 237(237) ⌘ hg glog -r 229:237
> @  237:56c20556c649 tip  - Get rid of unused code.
> |
> o  236:7ebe3968ed0f   - Start testing having the private HGRC file located in the Application Support directory.
> |
> o  235:4c32c175dfb7   - Move applicationSupportFolder functions to Common
> |
> o  234:0c1a96e92a6d   - MacHgSpash -> MacHgSplash
> |
> | o  233:573861d0fb8d   - MacHgSpash -> MacHgSplash
> | |
> | o  232:b24991eb83a9   - Get rid of unused code.
> | |
> | o  231:b4b05d09f4c7   - Start testing having the private HGRC file located in the Application Support directory.
> | |
> | o  230:48046b304ed9   - Move applicationSupportFolder functions to Common
> |/
> o  229:2b715bcd5a6b   - Fix some more cases of Ok -> OK
> |
> 
> version 232:b24991eb83a9 is exactly the same as version 237:56c20556c649. You can see that because they have the same diff:
> 
> [Bolt:/Development/MacHgDev/MacHgClone] MacHgClone 237(237) ⌘ hg diff -c 232 | md5
> c2838b6b38ab0823bac3486f82a246eb
> [Bolt:/Development/MacHgDev/MacHgClone] MacHgClone 237(237) ⌘ hg diff -c 237 | md5
> c2838b6b38ab0823bac3486f82a246eb
> 
> Thus one can compare revisions based on the md5 of their diff's to parents. Even more advanced would be some "diff hash" which then threw outthe line numbers, etc and could detect a patch even if the line numbers had changed.... etc.
> 
> Is there such an extension already around or a niece way to do this which I don't know about? Anyone feel like writing one if not? :) :)
> 
> Cheers & Thanks,
>  Jas


More information about the Mercurial-devel mailing list