--- a/buildframework/helium/sf/java/scm/src/com/nokia/maven/scm/provider/hg/command/update/HgUpdateCommand.java Wed Jun 16 16:51:40 2010 +0300
+++ b/buildframework/helium/sf/java/scm/src/com/nokia/maven/scm/provider/hg/command/update/HgUpdateCommand.java Fri Aug 13 14:59:05 2010 +0300
@@ -17,72 +17,74 @@
package com.nokia.maven.scm.provider.hg.command.update;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.update.UpdateScmResult;
+import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
import org.apache.maven.scm.provider.ScmProviderRepository;
import org.apache.maven.scm.provider.hg.HgUtils;
import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
import org.apache.maven.scm.provider.hg.command.HgConsumer;
import org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer;
-import org.apache.maven.scm.ScmFileSet;
-import org.apache.maven.scm.command.update.UpdateScmResult;
-import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
-import org.apache.maven.scm.ScmFile;
-import org.apache.maven.scm.ScmFileStatus;
-import org.apache.maven.scm.ScmResult;
-import org.apache.maven.scm.ScmVersion;
-import org.apache.maven.scm.ScmException;
import org.codehaus.plexus.util.StringUtils;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import java.io.File;
+import com.nokia.maven.scm.provider.hg.HgUtilsInternal;
/**
*/
public class HgUpdateCommand extends
- org.apache.maven.scm.provider.hg.command.update.HgUpdateCommand {
+ org.apache.maven.scm.provider.hg.command.update.HgUpdateCommand {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
- protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo,
- ScmFileSet fileSet, ScmVersion tag) throws ScmException {
+ protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet,
+ ScmVersion tag) throws ScmException {
File workingDir = fileSet.getBasedir();
// Find changes from last revision
- int previousRevision = HgUtils.getCurrentRevisionNumber(getLogger(),
- workingDir);
+ long previousRevision = HgUtilsInternal.getCurrentRevisionNumber(getLogger(), workingDir);
// Update branch
- String[] updateCmd = new String[] {
- "update",
- HgCommandConstants.REVISION_OPTION,
- tag != null && !StringUtils.isEmpty(tag.getName()) ? tag
- .getName() : "tip" };
- ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()),
- getLogger(), workingDir, updateCmd);
+ String[] updateCmd = new String[] { "update", HgCommandConstants.REVISION_OPTION,
+ tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
+ ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
if (!updateResult.isSuccess()) {
return new UpdateScmResult(null, null, updateResult);
}
// Find changes from last revision
- int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(),
+ long currentRevision = HgUtilsInternal.getCurrentRevisionNumber(getLogger(),
workingDir);
+
+ // No point of calculating a delta if nothing has been updated.
+ getLogger().debug("Changeset before update: " + String.format("%012x", previousRevision));
+ getLogger().debug("Changeset after update: " + String.format("%012x", currentRevision));
+ if (previousRevision == currentRevision) {
+ return new UpdateScmResultWithRevision(new ArrayList<ScmFile>(), new ArrayList(), String
+ .valueOf(currentRevision), updateResult);
+ }
+
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
List changes = new ArrayList();
String[] diffCmd = null;
if (currentRevision == 0) {
- diffCmd = new String[] { HgCommandConstants.DIFF_CMD,
- "-c", "" + currentRevision};
+ diffCmd = new String[] { HgCommandConstants.DIFF_CMD, "-c", "" + String.format("%012x", currentRevision)};
} else {
diffCmd = new String[] { HgCommandConstants.DIFF_CMD,
- HgCommandConstants.REVISION_OPTION, "" + previousRevision,
- HgCommandConstants.REVISION_OPTION, "" + currentRevision};
+ HgCommandConstants.REVISION_OPTION, "" + String.format("%012x", previousRevision),
+ HgCommandConstants.REVISION_OPTION, "" + String.format("%012x", currentRevision)};
}
- HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(),
- workingDir);
- updateResult = HgUtils.execute(diffConsumer, getLogger(),
- workingDir, diffCmd);
+ HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
+ updateResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
// Now translate between diff and update file status
List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
@@ -95,8 +97,10 @@
updatedFiles.add(diffFile);
}
}
+
return new UpdateScmResultWithRevision(updatedFiles, changes, String
- .valueOf(currentRevision), updateResult);
+ .valueOf(currentRevision), new ScmResult(updateResult.getCommandLine(),
+ updateResult.getCommandOutput(), updateResult.getProviderMessage(), true));
}
}