views:

554

answers:

8

Branching sources for release cycle is one of common source management scenarios. Merging as soon as possible is a good practice. Thus we have a human factor: branch is closed, but someone forgot to merge something back to trunk.

Q: Is there a "one click" way to get all revision numbers that were not merged from branch X to trunk?

(Note: I do not need these revision numbers to find what to merge, I need them to create automated validation, that would remind people to make sure they did not forget to merge something to trunk. Merging itself is not an issue.)

It seams like svn mergeinfo command fails to help here. Passing branch and trunk roots will fail if merge was performed not on root level (and it is a common scenario).

Scripts, tools any kind of svn hooks as a solution are welcome.

P.S.

Latest version of SVN. No need to argue how common or good this scenario is ;)

A: 

For that reason CVS created a tag to mark a root of branch :) For SVN that should look like:

+ trunk / project1
+ tags / project1-b1-root
+ branches / project1-b1

Notes:

  1. Tag project1-b1-root and branch project1-b1 are created at the same time from trunk.
  2. Nobody should commit to project1-b1-root (you can restrict this operation for tags/ path).
  3. When everybody claimed, that he has put everything to the trunk, you make a diff between project1-b1-root and project1-b1 and try to apply it to trunk: the changes, which are already applied, will be silently skipped, for the rest you will see the difference or collisions.
dma_k
@dma_k 3 step requires human interaction. I really need something exactly like svn mergeinfo that returns a simple list of revisions merged (or not merged). In your scenario after getting merge results further manual investigation is needed to find out what revisions were not merged and who is the author.
Dandikas
A: 

I wouldn't worry about the specific change numbers that need to get merged, but rather just look at the diffs:

First, bring the side branch up to date with trunk (or see what would be merged):

cd branch-dir
svn merge --reintegrate http://svnrepo/path-to-trunk .
svn ci -m'making this branch current'

cd ../trunk-dir
svn merge --dry-run http://svnrepo/path-to-trunk http://svnrepo/path-to-branch .
svn ci -m'merging in all unmerged changes from <branch>'

Remember, svn merge commands look just like svn diff commands - you create a diff/patch, then apply that to a particular location. That merge command above is simply saying "take all the differences between trunk and the branch, and apply them to a working copy of trunk". So you could just as easily change that second merge command into a diff for your mail notification.

Don't forget to check the diffs before committing in each case, to be sure that nothing bad has happened. You may also have to resolve some conflicts.

Ether
@Ether that's a good short explanation on merge ;) I do know how to merge(i.e. that was not the question). I am interested in source maintaining, and want to get an automated answer on question "what was not merged". The answer would than be mailed to people who forgot to merge.
Dandikas
@Dandikas: I've amended my answer to be more clear what I meant.
Ether
+4  A: 

You can do this super easily if you're using a relatively newish version of Subversion (1.5 or higher, I think) with the mergeinfo sub-command.

svn mergeinfo --show-revs eligible svn://repo/branches/your-branch-name svn://repo/trunk

This will show you all the revisions that are eligible to be merged to the trunk from the branch "your-branch-name".

Source: http://svnbook.red-bean.com/en/1.5/svn.ref.svn.c.mergeinfo.html

tmont
@tmont from question: "It seams like svn mergeinfo command fails to help here. Passing branch and trunk roots will fail if merge was performed not on root level (and it is a common scenario)."--show-revs eligible only changes list from "what was merged" to "yet to merge" but mentioned sub folder commit failure is still there.
Dandikas
A: 

Will svn merge --dry-run give you the details you need?

Adam Liss
nope :( dry run will tell if running merge is going to produce conflicts. Again, you can than try to find out revisions that were not merged, but it's more a game not a "one click" action that could be scheduled for automated run on branch closure.
Dandikas
+1  A: 

I realize your case is probably too late for this, but what I do for this sort of thing is to establish a convention for the merge commits so they're identifiable later. For example "Merging [1234]: ...(full commit log of 1234)...". Then I can parse it out of svn log with a script later.

To make sure your whole team does it, make the merge convention into a script and put it in your project. (e.g., ./scripts/merge 1234). People will generally even appreciate this, doubly so if the script makes merges easier than the raw svn command would be by doing things like figuring out the source url automatically

Good luck.

matschaffer
This sounds like what is needed, except that I do not want to make a convention on comments since we have mergeinfo property starting from SVN v1.5
Dandikas
I hear you. I wish that worked too, but I have yet to have the 1.5 merge handling do anything other than complicate the situation.
matschaffer
+1  A: 

Short answer: I don't think so.

Long answer: I ended up writing a python script to answer this question. Whenever developers merge a changeset they're required to put "merged rXXX" in the log message. (This from before svn:mergeinfo existed) The script parses all live svn branches + trunk and recursively scans all "merged" links, outputting a per-developer list of changes they haven't merged.

Nathan Kidd
@Nathan Kidd this is exactly what I am looking for! Only difference is that I expect it to work without special comment, as now we have svn:mergeinfo property in place.
Dandikas
@Dandikas If I were to write it again I'm not sure I'd use svn:mergeinfo anyway. The reason is our concern is not really that a particular diff gets merged, but that the logical fix for the issue is applied. Sometimes if a branch diverges enough we'll fix the issue and mark it 'merged' but in fact we didn't apply any of the original diff; a separate approach was used to fix the same issue. The manual log message approach lets you do this, svn:mergeinfo doesn't so much.
Nathan Kidd
@Nathan Kidd got your point. Our work-flow is slightly different in the way that merges are performed as soon as possible. I.e. if developer commits fix to a branch (be it one commit or several, that accomplishes the fix) he than immediately merges them to trunk. This approach has many strengths and one serious weakness - human factor. Any fix in a branch is potentially performed under more pressure with less available time. Yet we still must assure, that people (devs are people right) know when they might have forgotten to merge something.
Dandikas
A: 

I'm sorry I don't have my SVN server up at home to test this right now, but could the command:

svn log --verbose

Which you could parse? I'm not sure the output after you merge back to main, but you might be able to parse through (using a script, which I don't have as I'm the only one using my SVN server) the log and read all the files that have been checked in, and then look for a keyword indicating that the file has been merged to main?

I'll try to check it out sometime tonight when I get home if I have some time.

onaclov2000
A: 

Due to the lack of a silver bullet, the disciplined way is to keep a note of what has been merged and from where.

Amit Kumar
True as long as there are < 10 developers working on the same project. With a big teem you either change coding work-flow or do the check manually(sux).
Dandikas