hg import to apply patch to a subdirectory

Brendan Cully brendan at kublai.com
Fri May 4 10:40:22 CDT 2012


On 12-05-04 03:21 AM, Martin Geisler wrote:
> Sean Farley<sean.michael.farley at gmail.com>  writes:
>
>>> I can see how this would be useful, though it's not something I've
>>> needed before -- when I apply patches coming from 'hg export', then
>>> they're already rooted correctly at the repository root.
>>>
>>> Where do you get your patches from if they only apply on a
>>> subdirectory?
>>
>> These patches usually come from subdirectories that /should/ be
>> subrepositories but for reasons out of my control are not. Using
>> transplant has been extremely nice for the 'strip' direction (I was
>> able to patch transplant to pass --strip down to patch.patch) but the
>> other direction would be more code intrusion than just a patch for
>> transplant.py; hence this email asking about potential ideas.
>
> Okay, so you have two unrelated repositories main and sub. You
> transplant changes from sub into main, applying them onto a subdirectory
> of main that "happens" to look just like sub. Hmm... :)
>
> It doesn't sound like a very common workflow. I was going to suggest
> using the --filter flag for transplant, but I see now that filterdiff
> will remove the Mercurial patch header. So it's not just a matter of
> running
>
>    hg transplant \
>      --filter "filterdiff --strip 2 --addoldprefix a/ --addnewprefix b/"
>
> when stripping out the top-level directory.
>
> Since it's more complicated than that, maybe we should include an option
> for this? I'm not really sure...

Actually, transplant --filter splits each change into separate header 
and patch files for this reason, so I believe your simple example will 
work. A similar workflow is documented at

http://mercurial.selenic.com/wiki/TransplantExtension



More information about the Mercurial-devel mailing list