Remove the conflict mark from Entries after the merge conflicts were successfully resolved.
This is a fix of issue #32330.
1.1 --- a/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsResolveConflicts.java Tue Aug 05 13:26:10 2003 +0000
1.2 +++ b/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsResolveConflicts.java Tue Aug 05 16:06:27 2003 +0000
1.3 @@ -31,6 +31,8 @@
1.4 import java.util.Iterator;
1.5 import java.util.Hashtable;
1.6
1.7 +import org.openide.DialogDisplayer;
1.8 +import org.openide.ErrorManager;
1.9 import org.openide.filesystems.FileLock;
1.10 import org.openide.filesystems.FileObject;
1.11 import org.openide.util.Lookup;
1.12 @@ -44,7 +46,6 @@
1.13 import org.netbeans.modules.vcscore.commands.CommandOutputListener;
1.14 import org.netbeans.modules.vcscore.commands.CommandDataOutputListener;
1.15 import org.netbeans.modules.vcscore.cmdline.*;
1.16 -import org.openide.DialogDisplayer;
1.17
1.18 /**
1.19 * This class is used to resolve merge conflicts in a graphical way using a merge visualizer.
1.20 @@ -273,9 +274,73 @@
1.21 }
1.22 }
1.23
1.24 + /**
1.25 + * Repair the CVS/Entries of the file - remove the conflict.
1.26 + * @param file The file to remove the conflict for
1.27 + */
1.28 + private static void repairEntries(File file) throws IOException {
1.29 + String name = file.getName();
1.30 + File entries = new File(file.getParentFile(), "CVS"+File.separator+"Entries");
1.31 + File backup = new File(entries.getAbsolutePath()+".Backup");
1.32 + int attemps = 100;
1.33 + while (backup.exists() && attemps-- > 0) {
1.34 + // Someone else is occupying Entries, wait a while...
1.35 + try {
1.36 + Thread.currentThread().sleep(500);
1.37 + } catch (InterruptedException intrex) {
1.38 + attemps = 0;
1.39 + }
1.40 + }
1.41 + if (attemps <= 0) return ; // Give up, someone else is occupying Entries
1.42 + backup.createNewFile();
1.43 + try {
1.44 + BufferedReader reader = null;
1.45 + BufferedWriter writer = null;
1.46 + try {
1.47 + reader = new BufferedReader(new FileReader(entries));
1.48 + writer = new BufferedWriter(new FileWriter(backup));
1.49 + String line;
1.50 + String pattern = "/"+name;
1.51 + while ((line = reader.readLine()) != null) {
1.52 + if (line.startsWith(pattern)) {
1.53 + line = removeConflict(line);
1.54 + }
1.55 + writer.write(line+"\n");
1.56 + }
1.57 + } finally {
1.58 + if (reader != null) reader.close();
1.59 + if (writer != null) writer.close();
1.60 + }
1.61 + backup.renameTo(entries);
1.62 + } finally {
1.63 + if (backup.exists()) backup.delete();
1.64 + }
1.65 + }
1.66 +
1.67 + private static String removeConflict(String line) {
1.68 + StringBuffer result = new StringBuffer();
1.69 + int n = line.length();
1.70 + int slashNum = 0;
1.71 + boolean ignoreField = false;
1.72 + for (int i = 0; i < n; i++) {
1.73 + char c = line.charAt(i);
1.74 + if (!ignoreField) result.append(c);
1.75 + if (c == '/') {
1.76 + ignoreField = false;
1.77 + slashNum++;
1.78 + if (slashNum == 3) {
1.79 + result.append("Result of merge/"); // NOI18N
1.80 + ignoreField = true;
1.81 + }
1.82 + }
1.83 + }
1.84 + return result.toString();
1.85 + }
1.86 +
1.87 private static class MergeResultWriterInfo extends StreamSource {
1.88
1.89 private File tempf1, tempf2, tempf3, outputFile;
1.90 + private File fileToRepairEntriesOf;
1.91 private String mimeType;
1.92 private String leftFileRevision;
1.93 private String rightFileRevision;
1.94 @@ -326,6 +391,7 @@
1.95 */
1.96 public Writer createWriter(Difference[] conflicts) throws IOException {
1.97 if (conflicts == null || conflicts.length == 0) {
1.98 + fileToRepairEntriesOf = outputFile;
1.99 if (fo != null) {
1.100 return new OutputStreamWriter(fo.getOutputStream((lock != null) ? lock : (lock = fo.lock())));
1.101 } else {
1.102 @@ -350,6 +416,14 @@
1.103 lock = null;
1.104 }
1.105 fo = null;
1.106 + if (fileToRepairEntriesOf != null) {
1.107 + try {
1.108 + repairEntries(fileToRepairEntriesOf);
1.109 + } catch (IOException ioex) {
1.110 + // The Entries will not be repaired at worse
1.111 + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioex);
1.112 + }
1.113 + }
1.114 }
1.115
1.116 }