3p/copybara: support 'T' from diff

This commit is contained in:
Luke Granger-Brown 2021-07-04 15:01:53 +00:00
parent 634fe97655
commit a69c2d64ef
4 changed files with 103 additions and 17 deletions

View file

@ -22,6 +22,7 @@ core.workflow(
"patches/0001-Make-Mercurial-at-least-slightly-usable.patch",
"patches/0002-HgRepository-HGPLAIN.patch",
"patches/0003-HgDestination-nonpublishing.patch",
"patches/diff-support-T.patch",
]),
core.move("", "third_party/copybara"),
],

View file

@ -237,22 +237,30 @@ public class HgDestination implements Destination<HgRevision> {
Operation diffOp = diff.getOperation();
if (diffOp.equals(Operation.ADD)) {
Path targetPath = localRepo.getHgDir().getParent().resolve(diff.getName());
Files.createDirectories(targetPath.getParent());
Files.copy(workDir.resolve(diff.getName()),
targetPath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
}
switch (diffOp) {
case ADD:
Path targetPath = localRepo.getHgDir().getParent().resolve(diff.getName());
Files.createDirectories(targetPath.getParent());
Files.copy(
workDir.resolve(diff.getName()),
targetPath,
StandardCopyOption.COPY_ATTRIBUTES,
StandardCopyOption.REPLACE_EXISTING);
break;
if (diffOp.equals(Operation.MODIFIED)) {
Files.copy(workDir.resolve(diff.getName()),
localRepo.getHgDir().getParent().resolve(diff.getName()), StandardCopyOption.REPLACE_EXISTING);
}
case MODIFIED:
case TYPE_CHANGED:
Files.copy(
workDir.resolve(diff.getName()),
localRepo.getHgDir().getParent().resolve(diff.getName()),
StandardCopyOption.REPLACE_EXISTING);
break;
if (diffOp.equals(Operation.DELETE)) {
if (!diff.getName().equals(".hg_archival.txt")) {
Files.delete(localRepo.getHgDir().getParent().resolve(diff.getName()));
}
case DELETE:
if (!diff.getName().equals(".hg_archival.txt")) {
Files.delete(localRepo.getHgDir().getParent().resolve(diff.getName()));
}
break;
}
}
} catch (InsideGitDirException e) {
@ -280,8 +288,10 @@ public class HgDestination implements Destination<HgRevision> {
localRepo.cleanUpdate(remoteFetch);
// Set the default path of the local repo to be the remote repo, so we can push to it
Files.write(localRepo.getHgDir().getParent().resolve(".hg/hgrc"),
String.format("[paths]\ndefault = %s\n\n[phases]\npublish = False\n", repoUrl).getBytes(StandardCharsets.UTF_8));
Files.write(
localRepo.getHgDir().getParent().resolve(".hg/hgrc"),
String.format("[paths]\ndefault = %s\n\n[phases]\npublish = False\n", repoUrl)
.getBytes(StandardCharsets.UTF_8));
console.progress("Hg Destination: Computing diff");
getDiffAndStageChanges(destinationFiles, workdir, localRepo);

View file

@ -119,7 +119,8 @@ public class DiffUtil {
public enum Operation {
ADD("A"),
DELETE("D"),
MODIFIED("M");
MODIFIED("M"),
TYPE_CHANGED("T");
private final String charType;

View file

@ -0,0 +1,74 @@
diff --git a/java/com/google/copybara/hg/HgDestination.java b/java/com/google/copybara/hg/HgDestination.java
--- a/java/com/google/copybara/hg/HgDestination.java
+++ b/java/com/google/copybara/hg/HgDestination.java
@@ -237,22 +237,30 @@ public class HgDestination implements De
Operation diffOp = diff.getOperation();
- if (diffOp.equals(Operation.ADD)) {
- Path targetPath = localRepo.getHgDir().getParent().resolve(diff.getName());
- Files.createDirectories(targetPath.getParent());
- Files.copy(workDir.resolve(diff.getName()),
- targetPath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
- }
+ switch (diffOp) {
+ case ADD:
+ Path targetPath = localRepo.getHgDir().getParent().resolve(diff.getName());
+ Files.createDirectories(targetPath.getParent());
+ Files.copy(
+ workDir.resolve(diff.getName()),
+ targetPath,
+ StandardCopyOption.COPY_ATTRIBUTES,
+ StandardCopyOption.REPLACE_EXISTING);
+ break;
- if (diffOp.equals(Operation.MODIFIED)) {
- Files.copy(workDir.resolve(diff.getName()),
- localRepo.getHgDir().getParent().resolve(diff.getName()), StandardCopyOption.REPLACE_EXISTING);
- }
+ case MODIFIED:
+ case TYPE_CHANGED:
+ Files.copy(
+ workDir.resolve(diff.getName()),
+ localRepo.getHgDir().getParent().resolve(diff.getName()),
+ StandardCopyOption.REPLACE_EXISTING);
+ break;
- if (diffOp.equals(Operation.DELETE)) {
- if (!diff.getName().equals(".hg_archival.txt")) {
- Files.delete(localRepo.getHgDir().getParent().resolve(diff.getName()));
- }
+ case DELETE:
+ if (!diff.getName().equals(".hg_archival.txt")) {
+ Files.delete(localRepo.getHgDir().getParent().resolve(diff.getName()));
+ }
+ break;
}
}
} catch (InsideGitDirException e) {
@@ -280,8 +288,10 @@ public class HgDestination implements De
localRepo.cleanUpdate(remoteFetch);
// Set the default path of the local repo to be the remote repo, so we can push to it
- Files.write(localRepo.getHgDir().getParent().resolve(".hg/hgrc"),
- String.format("[paths]\ndefault = %s\n\n[phases]\npublish = False\n", repoUrl).getBytes(StandardCharsets.UTF_8));
+ Files.write(
+ localRepo.getHgDir().getParent().resolve(".hg/hgrc"),
+ String.format("[paths]\ndefault = %s\n\n[phases]\npublish = False\n", repoUrl)
+ .getBytes(StandardCharsets.UTF_8));
console.progress("Hg Destination: Computing diff");
getDiffAndStageChanges(destinationFiles, workdir, localRepo);
diff --git a/java/com/google/copybara/util/DiffUtil.java b/java/com/google/copybara/util/DiffUtil.java
--- a/java/com/google/copybara/util/DiffUtil.java
+++ b/java/com/google/copybara/util/DiffUtil.java
@@ -119,7 +119,8 @@ public class DiffUtil {
public enum Operation {
ADD("A"),
DELETE("D"),
- MODIFIED("M");
+ MODIFIED("M"),
+ TYPE_CHANGED("T");
private final String charType;