diff --git a/third_party/copybara/copy.bara.sky b/third_party/copybara/copy.bara.sky index 2d543e2496..4a34d64d6c 100644 --- a/third_party/copybara/copy.bara.sky +++ b/third_party/copybara/copy.bara.sky @@ -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"), ], diff --git a/third_party/copybara/java/com/google/copybara/hg/HgDestination.java b/third_party/copybara/java/com/google/copybara/hg/HgDestination.java index 41ca1c83b3..86f190cebb 100644 --- a/third_party/copybara/java/com/google/copybara/hg/HgDestination.java +++ b/third_party/copybara/java/com/google/copybara/hg/HgDestination.java @@ -237,22 +237,30 @@ public class HgDestination implements Destination { 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 { 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/third_party/copybara/java/com/google/copybara/util/DiffUtil.java b/third_party/copybara/java/com/google/copybara/util/DiffUtil.java index a3bcb29eae..acfb69b162 100644 --- a/third_party/copybara/java/com/google/copybara/util/DiffUtil.java +++ b/third_party/copybara/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; diff --git a/third_party/copybara/patches/diff-support-T.patch b/third_party/copybara/patches/diff-support-T.patch new file mode 100644 index 0000000000..4932033970 --- /dev/null +++ b/third_party/copybara/patches/diff-support-T.patch @@ -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; +