0

I currently have a repo with a default branch and a named branch. There process is I make changes in default, then merge to the named branch. The named branch is where I compile and release my code, but then I merge back to default so I have only one head and no floating heads in my repo.

My issue is there's one value, var, in foo.c that I want to track differently in default than in the named branch and the auto-merge keeps overwriting the current value and brining in the other value.

Initially var is set to 1 in the named branch and A in default. When I merge in new good stuff from default to named branch I see foo.c updates var from 1 to A.

I change the value back to 1, compile and release my code, and then merge back to default, which changes the value of var in default from 1 to A.

My question is, is there any way to stop mercurial from auto-merging and updating just this one line in the file? This is creating thrash in the form of multiple changesets where I'm simply putting the value back to what it used to be and because it's not a merge conflict can easily be overlooked during the merge (this is a shared repository with sometimes very green developers) and cause some major issues in my program. Thanks.

2 Answers 2

1

If you were only merging in one direction, it would be simple, just make the change in one branch, but you are merging in both directions. One option might be into looking into the Mq extension for Mercurial and using that to apply and remove a patch, but that probably adds more complication than it's worth. The better option would be to have a build system that selected the correct value of the variable at build time based on the name of the current branch. That can be retrieved by running the command hg id --branch. You mentioned using C code, but didn't mention an operating system. I'm going assume GNU Make with a minimal UNIX environment. In your Makefile, you would add something like as follows:

BRANCH := $(shell hg id --branch)

VAR_VALUE := $(shell if [ "$(BRANCH)" = "named" ]; then echo A; else echo 1; fi)

CFLAGS += -DVAR_VALUE=$(VAR_VALUE)

Then, in your C code, you could use this to reference the value:

#define VAR_VALUE_STR #VAR_VALUE

const char var[] = VAR_VALUE_STR;

The first define converts the defined value to a regular C string and then it's provided as the value to initialize the string var to.

0

Pure Mercurial-way

In your case you have to apply specific permanent change each time after merging into specific branch. In Mercurial such patches can be created once and used forever: see at MQ Extension.

In common: you'll have two independent patches in patch-queue (one per branch), in each branch after merge and before build you have to have only one branch-specific patch be applied. The latter task inside MQ can be solved by 3 slightly different ways:

  • Two patches in single queue, needed patch moved in queue (patch-queue is stack) and applied in pre-build event with some hand-made business-logic (credits to penguin359)

    if $BRANCH = "..." then hg qpush --move PATCH-OF-BRANCH

  • Two queues with single patch in it (the same if, different command-set hg qqueue QUEUE-OF-BRANCH; hg qpop)

  • In single queue protect each branch-specific patch with guards, in order to have for hg qpush --all only needed patch applied for each target

From my POV, solutions 2 and 3 have better scalability and protection from monkey with grenade

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.