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/0001-Make-Mercurial-at-least-slightly-usable.patch",
"patches/0002-HgRepository-HGPLAIN.patch", "patches/0002-HgRepository-HGPLAIN.patch",
"patches/0003-HgDestination-nonpublishing.patch", "patches/0003-HgDestination-nonpublishing.patch",
"patches/diff-support-T.patch",
]), ]),
core.move("", "third_party/copybara"), core.move("", "third_party/copybara"),
], ],

View file

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

View file

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