Anyway to automatically merge or merge hgtags (Mercurial)?

We are trying to run a chron task that automatically converts individual CVS modules to mercury modules and finally consolidates these converted mercury modules in a single mercury repo.

I am trying to find ways to automatically merge .hgtags (from converted hg repositories) without prompting the user window (thus use in working with the chronometer).

Is there a way to say mercurial when using hg merge just to take a local file and add it to the input file?

Thanks for any information or any suggestions.

+6
merge dvcs merge-conflict-resolution mercurial .hgtags
source share
5 answers

Yes, you can customize the merge tool as described by Krtek. I just tried and it works:

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

Put this in your .hg/hgrc file on the server, and future merges will simply add tags. It happens that hg merge will do

 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 merge with.

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

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

 $ hg init $ echo a > a.txt $ hg add a.txt $ hg commit -ma $ echo b > b.txt $ hg add b.txt $ hg commit -mb $ 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 -mc created new head $ hg tag c 

Branches are visible at the exit of the graphic extension :

 @ changeset: 4:54c5397a23a4 | tag: tip | user: Martin Geisler < mg@aragost.com > | 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 < mg@aragost.com > | date: Wed Mar 02 11:45:17 2011 +0100 | summary: c | | o changeset: 2:a9af8514a64e | | user: Martin Geisler < mg@aragost.com > | | 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 < mg@aragost.com > | date: Wed Mar 02 11:44:44 2011 +0100 | summary: b | o changeset: 0:0db5fae8b6cc user: Martin Geisler < mg@aragost.com > 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 not 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 added:

 $ cat .hgtags aff5fe9be7d9b021e55dfb522b29fd03cbcf5cb7 c 0518533f37f6f37edbea5b46d9af2192f69ddecd b 
+8
source share

sort -mu gave me what I want. This command does not sort, but removes duplicates.

sort -u interrupt time order.

+3
source share

A window prompt will only occur if there is a conflict in the .hgtags file, which should be fairly rare. However, there may be an idea that will work.

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

Perhaps you can write a small program that will serve as a special merge tool for .hgtags that do exactly what you want, i.e. add a local file to the input file. You can then modify your hgrc to use this new tool when merging .hgtags.

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

+2
source share

Here is a simple merge tool in python. It also tries to maintain the existing line order in the .hgtags file.

The same clauses apply as in Martin's answer.

 import sys from heapq import merge local = sys.argv[1] other = sys.argv[2] output = sys.argv[3] merged_tags = merge(file(local).readlines(), file(other).readlines()) unique_tags = [] for tag in merged_tags: if tag not in unique_tags: unique_tags.append(tag) file(output, 'w').writelines(unique_tags) 
+1
source share

Offer fooobar.com/questions/272552 / ... :

hgtags.merge.template: changeset = "{tags}" tag = "{node} {tag} \ n"

[merge-tools] hgtags.executable = hg hgtags.args = log -r "tagged ()" --style hgtags.merge.template> $ output hgtags.premerge = False

[merge-patterns] .hgtags = hgtags

works for us.

0
source share

All Articles