A question about "hg patch/import": how to use a patch?

View: New views
2 Messages — Rating Filter:   Alert me  

A question about "hg patch/import": how to use a patch?

by alex.wang-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone. I am new to Mercurial.
As mentioned in the captial, assuming I have one directory containing a simple source code file, which is empty:
A\simple.c
Then I clone it to B, and we have:
A\simple.c
B\simple.c
Now, I add a line to simple.c, and run command: "hg diff > patch.v1 ", the patch content is:
diff -r 664ebf7b0f2c simple.c
--- a/simple.c Fri Oct 30 08:57:26 2009 +0800
+++ b/simple.c Fri Oct 30 08:58:33 2009 +0800
@@ -0,0 +1,1 @@
+/* patch for a new line: 1 */
\ No newline at end of fil
 
cd to the B content, run command "hg import/patch [path/to/]patch.v1"
Everything works perfectly until now.
 
Then I add another line to A\simple.c, run command: "hg diff > patch.v2", the patch content is:
 
diff -r 664ebf7b0f2c simple.c
--- a/simple.c Fri Oct 30 08:57:26 2009 +0800
+++ b/simple.c Fri Oct 30 09:01:58 2009 +0800
@@ -0,0 +1,2 @@
+/* patch for a new line: 1 */
+/* patch for a new line: 2 */
\ No newline at end of file
 
cd to the B content, run command "hg import/patch [path/to/]patch.v2"
Now it works wrongly.
The content of A\simple.c is:
/* patch for a new line: 1 */
/* patch for a new line: 2 */
 
The content of B\simple.c is:
/* patch for a new line: 1 */
/* patch for a new line: 2 *//* patch for a new line: 1 */
 
Since this is a extremely simple case, which is guranteed to be sucessful. However, the result of B\simple.c is definitely not what we want.
 
Can anyone tell me how to solve this problem? Thank you very much.
 
PS: Although there is solution: we can just run "hg commit", "hg update" in directory A, and then run "hg pull" in directory B, (this method works perfectly), since I am working for a huge code base, it is not allowed to push modified codes directly to the base. The normal workflow is to modified the code and use "hg diff > patch" to generate patch file, and submit the patch to the commitee to review it. Just the first time I commited my first patch, the commitee complains they can't apply the patch to the source tree. That is really annoying. I hope anyone here can help me sincerely. Thank you again.
 
 
 
 
2009-10-30

alex.w.y.wang

_______________________________________________
Mercurial mailing list
Mercurial@...
http://selenic.com/mailman/listinfo/mercurial

Re: A question about "hg patch/import": how to use a patch?

by Benoit Boissinot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 30, 2009 at 09:33:22AM +0800, alex.w.y.wang wrote:

> Hi everyone. I am new to Mercurial.
> As mentioned in the captial, assuming I have one directory containing a simple source code file, which is empty:
> A\simple.c
> Then I clone it to B, and we have:
> A\simple.c
> B\simple.c
> Now, I add a line to simple.c, and run command: "hg diff > patch.v1 ", the patch content is:
> diff -r 664ebf7b0f2c simple.c
> --- a/simple.c Fri Oct 30 08:57:26 2009 +0800
> +++ b/simple.c Fri Oct 30 08:58:33 2009 +0800
> @@ -0,0 +1,1 @@
> +/* patch for a new line: 1 */
> \ No newline at end of fil
>
> cd to the B content, run command "hg import/patch [path/to/]patch.v1"
> Everything works perfectly until now.
>
> Then I add another line to A\simple.c, run command: "hg diff > patch.v2", the patch content is:
>
> diff -r 664ebf7b0f2c simple.c
> --- a/simple.c Fri Oct 30 08:57:26 2009 +0800
> +++ b/simple.c Fri Oct 30 09:01:58 2009 +0800
> @@ -0,0 +1,2 @@
> +/* patch for a new line: 1 */
> +/* patch for a new line: 2 */
> \ No newline at end of file
>
> cd to the B content, run command "hg import/patch [path/to/]patch.v2"
> Now it works wrongly.
> The content of A\simple.c is:
> /* patch for a new line: 1 */
> /* patch for a new line: 2 */
>
> The content of B\simple.c is:
> /* patch for a new line: 1 */
> /* patch for a new line: 2 *//* patch for a new line: 1 */
>
> Since this is a extremely simple case, which is guranteed to be
> sucessful. However, the result of B\simple.c is definitely not what we
> want.
>
> Can anyone tell me how to solve this problem? Thank you very much.

The problem you have is that both patches are based on the same rev
(664ebf7b0f2c), while B has one more commit.

So if we call the first patch p and the second p', A has p', and B has
p.
So after importing the patch, B will have p+p' which is obviously not
correct (and p' will often fail to apply, you just got lucky with your
simple example).

So you could either not commit when importing (hg import --no-commit)
and revert the changes or update to the parent before importing (hg up
664ebf7b0f2c), but this will create a new head.

Hope it helps,

Benoit


--
:wq
_______________________________________________
Mercurial mailing list
Mercurial@...
http://selenic.com/mailman/listinfo/mercurial