[issue3068] 'hg import' can not operate properly with '--git' style patches when '--similarity' also supplied.

Oleksandr Gavenko bugs at mercurial.selenic.com
Thu Oct 20 14:24:56 CDT 2011


New submission from Oleksandr Gavenko <gavenkoa at gmail.com>:

I discover this issue when examine http://mercurial.selenic.com/bts/issue3048

To fix Mercurial file copying history I make such trick (with 'hg addremove
---similarity'):

  $ hg qnew
  $ hg qimport -r 0:tip
  $ echo >.hg/patches/status

 From this point I can add one by one all patches from .hg/patches/ to new
history with:

  $ i=0
  $ while [ -f .hg/patches/$i.diff ]; do \
      hg import --similarity 40 .hg/patches/$i.diff \
    done

'--similarity' fix untraced copying in history. But unfortunately 'hg
import' with '--similarity' option don't fully support '--git' diff format
which used 'hg qimport'. For example such lines simply ignored:

  diff --git a/common/test.vcproj b/common/xpcom.vcproj
  rename from common/test.vcproj
  rename to common/xpcom.vcproj

Next patches that related for renamed file can not be applied as renamed
file does not created...

To workaround with I make import in 3 steps:

  $ hg import --no-commit .hg/patches/$i.diff
  $ hg addremove --similarity 40
  $ hg ci -u "$user" -d "$date" -m "$msg"

As you can see in this workaround I need make some additional steps and also
I need extract $user, $date, and $msg from '.hg/patches/$i.diff' file:

   msg=`sed -n '/^[^#]/,/^diff/{/^diff/q;p}' .hg/mypatches/$rev.diff`
   user=`sed -n '/^# User /{s=^# User ==;p;q}' .hg/mypatches/$rev.diff`
   date=`sed -n '/^# Date /{s=^# Date ==;p;q}' .hg/mypatches/$rev.diff`

instead directly just:

  $ hg import --similarity 40 .hg/patches/$i.diff

NOTE: My trick with fixing history work because I have linear history
without branches. For practical case where this can be useful look to link
for issue3048 (when you convert SVN trunk to HG).

Please fix this issue!

  $ hg version
Mercurial Distributed SCM (version 1.9.2)

on Cygwin.

----------
messages: 17715
nosy: gavenkoa
priority: bug
status: unread
title: 'hg import' can not operate properly with '--git' style patches when '--similarity' also supplied.

____________________________________________________
Mercurial issue tracker <bugs at mercurial.selenic.com>
<http://mercurial.selenic.com/bts/issue3068>
____________________________________________________


More information about the Mercurial-devel mailing list