Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyway to automatically merge or concatenate hgtags (Mercurial)?

We are trying to run a chron job that automatically converts seperate CVS modules to mercurial modules and finally, consolidate those converted mercurial modules to in a single mercurial repo.

I've been trying to find ways to automatically merge .hgtags (from the converted hg repos) without having a user window prompt (thus usage in a chron job).

Is there a way to tell mercurial when using hg merge to just to take the local file and append it to the incoming file?

thanks for any info or any suggestions

like image 278
DavidW Avatar asked Mar 01 '11 16:03

DavidW


People also ask

How do you combine two mercurial heads?

To start a merge between the two heads, we use the hg merge command. We resolve the contents of hello. c This updates the working directory so that it contains changes from both heads, which is reflected in both the output of hg parents and the contents of hello.

What does hg update do?

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch head as closed.

How do you revert a merge in Heartgold?

To check out earlier revisions, you should use hg update REV. To cancel an uncommitted merge (and lose your changes), use hg merge --abort. With no revision specified, revert the specified files or directories to the contents they had in the parent of the working directory.

What is hg graft?

Description. This command uses Mercurial's merge logic to copy individual changes from other branches without merging branches in the history graph. This is sometimes known as 'backporting' or 'cherry-picking'. By default, graft will copy user, date, and description from the source changesets.


3 Answers

Yes, you can setup a merge tool like Krtek describes. I just tried it out and this works:

[merge-tools]
merge-tags.executable = cat
merge-tags.args = $local $other | sort -u >> $output

[merge-patterns]
.hgtags = merge-tags

Put that in your .hg/hgrc file on the server and future merges will just append the tags. What happens is that hg merge will execute

cat /tmp/hgtags.local /tmp/hgtags.other | sort -u >> .hgtags

where the first argument to cat is the local version of the .hgtags file, and the second argument is the version you are merging with.

I sort and make the output unique in order to avoid duplicating lines that are common in the two files. As long as you only add tags, this will work fine -- but if you also delete tags, then the order of lines in the .hgtags file matters and so you cannot just sort it like this. Please see my extended answer for handling this situation.

This is my test session. I start by making a repository with two heads:

$ hg init
$ echo a > a.txt
$ hg add a.txt
$ hg commit -m a
$ echo b > b.txt
$ hg add b.txt
$ hg commit -m b
$ hg tag b
$ hg update 0
0 files updated, 0 files merged, 2 files removed, 0 files unresolved
$ echo c > c.txt
$ hg add c.txt
$ hg commit -m c
created new head           
$ hg tag c

The branches are visible in the output from the graphlog extension:

@  changeset:   4:54c5397a23a4
|  tag:         tip
|  user:        Martin Geisler <[email protected]>
|  date:        Wed Mar 02 11:45:20 2011 +0100
|  summary:     Added tag c for changeset aff5fe9be7d9
|
o  changeset:   3:aff5fe9be7d9
|  tag:         c
|  parent:      0:0db5fae8b6cc
|  user:        Martin Geisler <[email protected]>
|  date:        Wed Mar 02 11:45:17 2011 +0100
|  summary:     c
|
| o  changeset:   2:a9af8514a64e
| |  user:        Martin Geisler <[email protected]>
| |  date:        Wed Mar 02 11:45:02 2011 +0100
| |  summary:     Added tag b for changeset 0518533f37f6
| |
| o  changeset:   1:0518533f37f6
|/   tag:         b
|    user:        Martin Geisler <[email protected]>
|    date:        Wed Mar 02 11:44:44 2011 +0100
|    summary:     b
|
o  changeset:   0:0db5fae8b6cc
   user:        Martin Geisler <[email protected]>
   date:        Wed Mar 02 11:44:33 2011 +0100
   summary:     a

There is a conflict in the .hgtags file:

$ hg cat -r 2 .hgtags
0518533f37f6f37edbea5b46d9af2192f69ddecd b
$ hg cat -r 4 .hgtags
aff5fe9be7d9b021e55dfb522b29fd03cbcf5cb7 c

but the merge is still non-interactive:

$ hg merge
merging .hgtags
1 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

You can see how the files were appended:

$ cat .hgtags
aff5fe9be7d9b021e55dfb522b29fd03cbcf5cb7 c
0518533f37f6f37edbea5b46d9af2192f69ddecd b
like image 144
Martin Geisler Avatar answered Nov 15 '22 12:11

Martin Geisler


sort -mu gave me what i want. This command do not sorts, but removes duplicates.

sort -u breaking time order.

like image 25
Ugi Veller Avatar answered Nov 15 '22 10:11

Ugi Veller


The window prompt will only happen if you have a conflict in your .hgtags file, which should be pretty rare. However, here's maybe an idea that will work.

Mercurial let you use a different merge tool than the internal one, for more information, see MergeToolConfiguration. You can also change the mergetool via the command line with the --tool option (see hg merge --help).

Maybe you can write some little program to serve as a special merge tool for .hgtags which do exactly what you want, ie append the local file to the incoming file. You can then modify your hgrc to use this new tool when merging .hgtags.

I never tried this solution, it's just an idea, but maybe it will help you.

like image 24
krtek Avatar answered Nov 15 '22 10:11

krtek