Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
expand tagdiff to support branches as well. Submitted by Danny Angus.…
… PR 47105.

git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/svn/trunk@771707 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed May 5, 2009
1 parent 7b0a927 commit eee0767aa7f9d7a3ba85286773c9e99e6ddd78d7
Showing 4 changed files with 184 additions and 47 deletions.
@@ -30,6 +30,10 @@
<introduction>
These are some of the many people who have helped with this Ant Library.
</introduction>
<name>
<first>Danny</first>
<last>Angus</last>
</name>
<name>
<first>Kevin</first>
<last>Jackson</last>
@@ -43,10 +43,19 @@ <h3>Description</h3>
-----&gt; tags
|
|
----------&gt; tag1
----------&gt; tag2
----------&gt; fromTag
----------&gt; toTag
-----&gt; branches
|
|
----------&gt; fromBranch
----------&gt; toBranch
</pre>

<p>It is possible to compare two branches, two tags or tags and
branches. The magic name "trunk" can be used in as from* or to* in
order to compare a tag/branch to trunk.</p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -55,14 +64,30 @@ <h3>Parameters</h3>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">tag1</td>
<td valign="top">fromTag</td>
<td valign="top">The first tag.</td>
<td align="center" valign="top">Yes.</td>
<td align="center" valign="top" rowspan="3">One of the three.</td>
</tr>
<tr>
<td valign="top">tag2</td>
<td valign="top">fromBranch</td>
<td valign="top">The first branch.</td>
</tr>
<tr>
<td valign="top">tag1</td>
<td valign="top"><b>Deprecated.</b> Equivalent to fromTag.</td>
</tr>
<tr>
<td valign="top">toTag</td>
<td valign="top">The second tag.</td>
<td align="center" valign="top">No, defaults to "trunk/"</td>
<td align="center" valign="top" rowspan="3">No, default is "trunk/"</td>
</tr>
<tr>
<td valign="top">toBranch</td>
<td valign="top">The second branch.</td>
</tr>
<tr>
<td valign="top">tag2</td>
<td valign="top"><b>Deprecated.</b> Equivalent to toTag.</td>
</tr>
<tr>
<td valign="top">destfile</td>
@@ -97,8 +122,8 @@ <h3>Examples</h3>
&lt;tagdiff failonerror="true"
baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
destfile="diff.xml"
tag1="initial"
tag2="BCEL_5_0"
fromTag="initial"
toTag="BCEL_5_0"
/&gt;
</pre>

@@ -111,8 +136,8 @@ <h3>Examples</h3>
&lt;tagdiff failonerror="true"
baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
destfile="diff.xml"
tag1="BCEL_5_0"
tag2="trunk"
fromTag="BCEL_5_0"
toBranch="trunk"
/&gt;
</pre>

@@ -125,11 +150,11 @@ <h3>Examples</h3>
&lt;tagdiff failonerror="true"
baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
destfile="diff.xml"
tag1="BCEL_5_0"
fromTag="BCEL_5_0"
/&gt;
</pre>

<p>Does the same, using <code>trunk</code> as <code>tag2</code>
<p>Does the same, using <code>trunk</code> as <code>to*</code>
implicitly.</p>

<h4>Generate Report</h4>
@@ -150,7 +175,7 @@ <h4>Generate Report</h4>
<h4>(Shortened) Example Output</h4>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;tagdiff tag1="BCEL_5_0" svnurl="http://svn.apache.org/repos/asf/jakarta/bcel/" &gt;
&lt;tagdiff fromTag="BCEL_5_0" svnurl="http://svn.apache.org/repos/asf/jakarta/bcel/" &gt;
&lt;path&gt;
&lt;name&gt;&lt;![CDATA[default.properties]]&gt;&lt;/name&gt;
&lt;action&gt;added&lt;/action&gt;
@@ -60,7 +60,7 @@
<h1>
<a name="top"><xsl:value-of select="$title"/></a>
</h1>
diff between <xsl:value-of select="@start"/><xsl:value-of select="@tag1"/> and <xsl:value-of select="@end"/><xsl:value-of select="@tag2"/>
diff between <xsl:value-of select="@start"/><xsl:value-of select="@fromTag"/><xsl:value-of select="@fromBranch"/> and <xsl:value-of select="@end"/><xsl:value-of select="@toTag"/><xsl:value-of select="@toBranch"/>
<p align="right">Designed for use with <a href="http://ant.apache.org/">Apache Ant</a>.</p>
<hr size="2"/>
<a name="TOP"/>
@@ -44,18 +44,39 @@
* -----&gt; tags
* |
* |
* ----------&gt; tag1
* ----------&gt; tag2
* ----------&gt; fromTag
* ----------&gt; toTag
* -----&gt; branches
* |
* |
* ----------&gt; fromBranch
* ----------&gt; toBranch
* </pre>
*
* It produces an XML output representing the list of changes.
* <p>It produces an XML output representing the list of changes.</p>
*
* <p>The task will compare any combination of branches and tags. To
* compare a newer branch to an older tag use the fromTag and toBranch
* attributes. To compare two tags use fromTag and toTag All
* combinations work as expected.</p>
*
* <p>You can specify the trunk for any of the four branch/tag
* attibutes by using the special value "trunk" (without the quotes).</p>
*
* <p>The older syntax using tag1 tag2 attributes is deprecated (but
* it still works)</p>
*
* <PRE>
* &lt;!-- Root element --&gt;
* &lt;!ELEMENT tagdiff ( paths? ) &gt;
* &lt;!-- First tag --&gt;
* &lt;!ATTLIST tagdiff tag1 NMTOKEN #IMPLIED &gt;
* &lt;!ATTLIST tagdiff fromTag NMTOKEN #IMPLIED &gt;
* &lt;!-- Second tag --&gt;
* &lt;!ATTLIST tagdiff tag2 NMTOKEN #IMPLIED &gt;
* &lt;!ATTLIST tagdiff toTag NMTOKEN #IMPLIED &gt;
* &lt;!-- First branch --&gt;
* &lt;!ATTLIST tagdiff fromBranch NMTOKEN #IMPLIED &gt;
* &lt;!-- Second branch --&gt;
* &lt;!ATTLIST tagdiff toBranch NMTOKEN #IMPLIED &gt;
* &lt;!-- Subversion BaseURL --&gt;
* &lt;!ATTLIST tagdiff svnurl NMTOKEN #IMPLIED &gt;
*
@@ -78,13 +99,20 @@ public class SvnTagDiff extends AbstractSvnTask {
/**
* The earliest revision from which diffs are to be included in the report.
*/
private String tag1;
private String fromTag;

/**
* The latest revision from which diffs are to be included in the report.
*/
private String tag2;

private String toTag;
/**
* The earliest revision from which diffs are to be included in the report.
*/
private String fromBranch;
/**
* The latest revision from which diffs are to be included in the report.
*/
private String toBranch;
/**
* The file in which to write the diff report.
*/
@@ -94,23 +122,90 @@ public class SvnTagDiff extends AbstractSvnTask {
* Base URL.
*/
private String baseURL;
/**
* the name of the older branch or tag
*/
private String fromCopy;
/**
* the name of the newer branch or tag
*/
private String toCopy;
/**
* Base the name of the attribute in the output
* e.g "fromBranch" or "fromTag" for the older copy
*/
private String fromName;
/**
* Base the name of the attribute in the output
* e.g "toBranch" or "toTag" for the newer copy
*/
private String toName;
/**
* Base the name of the directory of branches or tags
* e.g "branches/" or "tags/" for the older copy
*/
private String fromDir;
/**
* Base the name of the directory of branches or tags
* e.g "branches/" or "tags/" for the newer copy
*/
private String toDir;


/**
* Set the first tag.
*
* @param s the first tag.
*/
public void setFromTag(String s) {
fromTag = s;
}

/**
* Set the second tag.
*
* @param s the second tag.
*/
public void setToTag(String s) {
toTag = s;
}

/**
* Set the first tag.
*
* @param s the first tag.
* @deprecated use fromTag
*/
public void setTag1(String s) {
tag1 = s;
setFromTag(s);
}

/**
* Set the second tag.
*
* @param s the second tag.
* @deprecated use toTag
*/
public void setTag2(String s) {
tag2 = s;
setToTag(s);
}

/**
* Set the first branch.
*
* @param s the first branch.
*/
public void setFromBranch(String s) {
fromBranch = s;
}

/**
* Set the second branch.
*
* @param s the second branch.
*/
public void setToBranch(String s) {
toBranch = s;
}

/**
@@ -143,28 +238,19 @@ public void execute() throws BuildException {
// validate the input parameters
validate();

// sort out whats tags and whats branches
this.fromCopy = fromTag !=null ? fromTag : fromBranch;
this.toCopy = toTag != null ? toTag : toBranch;
this.fromName = fromTag != null ? "fromTag" : "fromBranch";
this.toName = toTag != null ? "toTag" : "toBranch";
this.fromDir = fromTag != null ? "tags/" : "branches/";
this.toDir = toTag != null ? "tags/" : "branches/";

// build the rdiff command
setSubCommand("diff");
addSubCommandArgument("--no-diff-deleted");
if (tag1.equals("trunk") || tag1.equals("trunk/")) {
addSubCommandArgument(baseURL + "trunk/");
} else {
if (tag1.endsWith("/")) {
addSubCommandArgument(baseURL + "tags/" + tag1);
} else {
addSubCommandArgument(baseURL + "tags/" + tag1 + "/");
}
}
if (tag2 == null || tag2.equals("trunk") || tag2.equals("trunk/")) {
addSubCommandArgument(baseURL + "trunk/");
} else {
if (tag2.endsWith("/")) {
addSubCommandArgument(baseURL + "tags/" + tag2);
} else {
addSubCommandArgument(baseURL + "tags/" + tag2 + "/");
}
}

addDiffArguments();

File tmpFile = null;
try {
tmpFile =
@@ -180,8 +266,8 @@ public void execute() throws BuildException {

// write the revision diff
SvnDiffHandler.writeDiff(mydestfile, entries, "tagdiff",
"tag1", tag1, "tag2",
tag2 == null ? "trunk" : tag2,
fromName, fromCopy, toName,
toCopy,
baseURL);
} finally {
if (tmpFile != null) {
@@ -190,6 +276,28 @@ public void execute() throws BuildException {
}
}

private void addDiffArguments(){
if (fromCopy.equals("trunk") || fromCopy.equals("trunk/")) {
addSubCommandArgument(baseURL + "trunk/");
} else {
if (fromCopy.endsWith("/")) {
addSubCommandArgument(baseURL + fromDir + fromCopy);
} else {
addSubCommandArgument(baseURL + fromDir + fromCopy + "/");
}
}
if (toCopy == null || toCopy.equals("trunk")
|| toCopy.equals("trunk/")) {
addSubCommandArgument(baseURL + "trunk/");
} else {
if (toCopy.endsWith("/")) {
addSubCommandArgument(baseURL + toDir + toCopy);
} else {
addSubCommandArgument(baseURL + toDir + toCopy + "/");
}
}
}

/**
* Validate the parameters specified for task.
*
@@ -200,8 +308,8 @@ private void validate() throws BuildException {
throw new BuildException("Destfile must be set.");
}

if (null == tag1) {
throw new BuildException("tag1 must be set.");
if (null == fromTag && null== fromBranch) {
throw new BuildException("fromTag or fromBranch must be set.");
}

if (null == baseURL) {

0 comments on commit eee0767

Please sign in to comment.