Subversion: howto find all revisions that are not merged to trunk?

…衆ロ難τιáo~ 提交于 2019-12-03 04:53:57

问题


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 seems 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 ;)


回答1:


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.

[update] The answer from @tmont is better now that everyone has a svn version that supports svn mergeinfo --show-revs eligible and svn merge --record-only for those times when you want to record the logical fix only.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



回答7:


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




回答8:


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




回答9:


Based on Ether's reply above, from the branch you want to check for unmerged revisions

svn merge --dry-run http://svnrepo/path-to-merge-source .  \
| grep Merging                                             \
| sed 's/--- Merging//'                                    \
| sed 's/into.*//'                                         \
| sort -u                                                  \
| sed 's/ through r/:/'                                    \
| sed -e :a -e N -e 's/\n//' -e ta                         \
| sed 's/ r/ -r/g'                                         \
| sed 's|^|svn log http://svnrepo/path-to-merge-source |'



回答10:


I'm enjoying your thread after 3 years of it being created. And I believe there is still no solution for your task in the form you put it :)

What I found though in the $ svn help merge is the advice not to do sub tree merges:

If you want to merge only a subtree, then the subtree path must be included in both SOURCE and TARGET_WCPATH; this is discouraged, to avoid subtree mergeinfo

So I guess the solution is to break your "common scenario" of doing subtree merges.

It would be mandatory to establish some control for merge operation, as otherwise anybody having Read access to one branch and Write access to another can do the merge from first to second. So the actual question is - how to control subtree merges ))




回答11:


I have written Java Web Application using Wicket and SVNKit for finding not merged revisions between branches, it could be customized to do whatever you want... link

o

来源:https://stackoverflow.com/questions/2207756/subversion-howto-find-all-revisions-that-are-not-merged-to-trunk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!