开发者

How to automate the update of dozens of mercurial repositories with ant?

I have a legacy product, spread across dozens of repositories. I'm currently trying to refactor (and understand...) the given build process. First step was moving from the old version control system to mercurial, which was encouraging and easy.

The build process mainly uses ant build scripts (good news) but has to run 'on' the repository file structure (bad news...) because the ant scripts t开发者_如何学JAVAake files from all repositories and leave artifacts on .. lets say, several places... But that's not a blocker.

Before I trigger the build (now with hudson CI), I have to make sure, that all repositories are updated to the tip or a selected tag. I could write a script/batch or write a custom ant task (again) but, I don't want to ignore existing features (again):

is it possible to update a set of mercurial repositories by using existing ant tasks or mercurial features? All repositories are located in one folder (like /repo) and have a common prefix (like SYSTEMNAME_module) so it's easy to locate them/create a fileset.


The most simple solution today is to start the hg executable from Ant (using the exec task. Note: MacroDef is your friend). Just create a "main" build file in one of the projects, change to the parent directory (where you can access all the local copies) and then update each one.


I found a different ant based solution, based on the 'apply' task:

<apply executable="hg">
  <arg value="update" />
  <arg value="--verbose" />
  <arg value="--revision" />
  <dirset dir="/repos" include="REPO_SUFFIX*" />
</apply>

Thanks to Aaron, his very helpful answer showed me the right direction.


I think this would be a more flexible way to update a mercurial depo. From a set of directories it chooses which ones are depots and updates those. Note that you can also do this with the foreach tag of ant contrib but the 'for' seems to consume a lot less memory.

<!-- See if the directory looks like a mercurial depo, if so update it -->
    <target name="-mercurial-update">
         <dirset dir="${dir.deps}" id="lib.dirs">
             <exclude name="build"/>
             <present targetdir="${dir.deps}">
                   <mapper type="glob" from="*" to="*/.hg" />
             </present>
           </dirset>

         <for param="file">
             <path>
                <dirset refid="lib.dirs"/>
             </path>
             <sequential>
                 <echo>Trying to update mercuriali depo @{file}</echo>
                 <exec executable="hg" dir="@{file}">
                     <arg line="pull" />
                 </exec>
                 <exec executable="hg" dir="@{file}">
                     <arg line="up" />
                 </exec>
            </sequential>
         </for>
     </target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜