cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: Add an "advanced merge" option that will try and take any remapped paths into account
Date Wed, 19 Mar 2014 18:56:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 1fa9f532b -> f0edc886b


Add an "advanced merge" option that will try and take any remapped paths into account


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f0edc886
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f0edc886
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f0edc886

Branch: refs/heads/master
Commit: f0edc886bbcac9318831edd8bfedc9ae89ed3d66
Parents: 1fa9f53
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Mar 19 14:56:01 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Mar 19 14:56:01 2014 -0400

----------------------------------------------------------------------
 bin/DoMerges.java | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f0edc886/bin/DoMerges.java
----------------------------------------------------------------------
diff --git a/bin/DoMerges.java b/bin/DoMerges.java
index 7d3df05..1fb9b0d 100644
--- a/bin/DoMerges.java
+++ b/bin/DoMerges.java
@@ -73,6 +73,17 @@ public class DoMerges {
     
     public static Set<String> records = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
     public static Set<String> patchIds = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+    
+    static class ToFrom {
+        final String from;
+        final String to;
+        
+        public ToFrom(String t, String f) {
+            to = t;
+            from = f;
+        }
+    }
+    public static List<ToFrom> pathMaps = new LinkedList<ToFrom>();
 
     static int waitFor(Process p) throws Exception  {
         return waitFor(p, true);
@@ -138,6 +149,13 @@ public class DoMerges {
         BufferedWriter writer = new BufferedWriter(new FileWriter(MERGEINFOFILE));
         writer.write(fromBranch);
         writer.newLine();
+        for (ToFrom ent : pathMaps) {
+            writer.write("A ");
+            writer.write(ent.from);
+            writer.write(" ");
+            writer.write(ent.to);
+            writer.newLine();
+        }
         for (String s : records) {
             writer.write(s);
             writer.newLine();
@@ -162,7 +180,14 @@ public class DoMerges {
             fromBranch = line;
             line = reader.readLine();
             while (line != null) {
-                records.add(line.trim());
+                if (line.startsWith("A ")) {
+                    line = line.substring(2).trim();
+                    String from = line.substring(0, line.indexOf(' '));
+                    String to = line.substring(line.indexOf(' ') + 1);
+                    pathMaps.add(new ToFrom(to, from));
+                } else {
+                    records.add(line.trim());
+                }
                 line = reader.readLine();
             }
             reader.close();
@@ -292,6 +317,53 @@ public class DoMerges {
             records.add("M " + ver);
         }
     }
+    private static void doMappedMerge(String ver) throws Exception {
+        Process p = Runtime.getRuntime().exec(getCommandLine(new String[] {"git", "format-patch",
"--stdout", "-1", ver}));
+        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        
+        File outputFile = File.createTempFile("merge", ".patch");
+        outputFile.deleteOnExit();
+        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
+        
+        String line = reader.readLine();
+        while (line != null) {
+            if ((line.startsWith("--- ")
+                || line.startsWith("+++ ")) && line.length() > 7) {
+                String file = line.substring(6).trim();
+                for (ToFrom ent : pathMaps) {
+                    if (file.contains(ent.from)) {
+                        String newf = file.replace(ent.from, ent.to);
+                        File fo = new File(newf);                        
+                        if (fo.exists() && fo.isFile()) {
+                            line = line.substring(0, 6) + newf;
+                            break;
+                        }
+                    }
+                }
+                //System.out.println("newl: " + line);
+            }
+            writer.append(line);
+            writer.newLine();
+            line = reader.readLine();
+        }
+        waitFor(p, false);
+        writer.flush();
+        writer.close();
+        
+        p = Runtime.getRuntime().exec(getCommandLine(new String[] {"git", "am", outputFile.getCanonicalPath()}));
+        
+        if (waitFor(p, false) != 0) {
+            p = Runtime.getRuntime().exec(getCommandLine(new String[] {"git", "status"}));
+            runProcess(p);
+                
+            if (doCommit()) {
+                records.add("M " + ver);
+            }
+        } else {
+            records.add("M " + ver);
+        }
+        outputFile.delete();
+    }
     private static String getPatchId(String id) throws Exception {
        
         String commands[] = new String[] { "git", "show", id};
@@ -407,13 +479,14 @@ public class DoMerges {
                 System.in.read();
             }
             while (c != 'M'
+                   && c != 'A'
                    && c != 'B'
                    && c != 'I'
                    && c != 'R'
                    && c != 'F'
                    && c != 'C'
                    && c != 'P') {
-                System.out.print("[M]erge, [B]lock, or [I]gnore, [R]ecord only, [F]lush,
[C]hanges? ");
+                System.out.print("[M]erge, [A]dvancedMerge, [B]lock, or [I]gnore, [R]ecord
only, [F]lush, [C]hanges? ");
                 int i = System.in.read();
                 c = Character.toUpperCase((char)i);
             }
@@ -422,6 +495,9 @@ public class DoMerges {
             case 'M':
                 doMerge(ver);
                 break;
+            case 'A':
+                doMappedMerge(ver);
+                break;
             case 'P':
                 System.out.println("Patch Id: " + getPatchId(ver));
                 cur--;


Mime
View raw message