# HG changeset patch # User jrice@netbeans.org # Date 1202857072 0 # Node ID 17ae6fe70cacecb497c6ad8656eafc2e3b97de1b # Parent be8a3d03a906525eb9309b59f082e71075c93e59 #127180: duplicate items added to .hgignore m- corrects this only adding ignore entries to an existing .hgignore file if required. diff -r be8a3d03a906 -r 17ae6fe70cac mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java Tue Feb 12 18:38:08 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java Tue Feb 12 22:57:52 2008 +0000 @@ -257,7 +257,7 @@ public class CloneAction extends Context String defaultPushWinStr = HgConfigFiles.HG_DEFAULT_PUSH_VALUE + " = " + defaultPush.replace("\\", "\\\\") + "\n"; // NOI18N tempFile = new File(hgrcFile.getAbsolutePath() + ".tmp"); // NOI18N - if (!tempFile.isFile() || !tempFile.canWrite()) return; + if (tempFile == null) return; br = new BufferedReader(new FileReader(hgrcFile)); pw = new PrintWriter(new FileWriter(tempFile)); diff -r be8a3d03a906 -r 17ae6fe70cac mercurial/src/org/netbeans/modules/mercurial/util/Bundle.properties --- a/mercurial/src/org/netbeans/modules/mercurial/util/Bundle.properties Tue Feb 12 18:38:08 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/Bundle.properties Tue Feb 12 22:57:52 2008 +0000 @@ -63,7 +63,7 @@ MSG_ARG_LIST_TOO_LONG_ERR = \nMercurial MSG_ARG_LIST_TOO_LONG_ERR = \nMercurial command "hg {0}" could not be executed as too many argumensts ({1}) where passed\n\nPlease perform this operation from the command line. MSG_USING_PROXY_INFO = using IDE Options->General Proxy settings: {0} -MSG_IGNORE_FILES = When working with this Clone, if you are doing any Merges or Reverts Mercurial\nmay generate additional files with extensions, .orig, .chg and .rej.\n\nWould you like the IDE to automatically ignore them by adding these extensions\nto the clone's .hgignore file? +MSG_IGNORE_FILES = When working with this Clone, if you are doing any Merges or Reverts Mercurial\nmay generate additional files with extensions, .orig, .chg and .rej.\n\nWould you like the IDE to automatically ignore them by adding these extensions\nto the clone's .hgignore file if not already there? MSG_IGNORE_FILES_TITLE = Mercurial Working Files diff -r be8a3d03a906 -r 17ae6fe70cac mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Tue Feb 12 18:38:08 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Tue Feb 12 22:57:52 2008 +0000 @@ -46,6 +46,7 @@ import java.io.FileReader; import java.io.FileReader; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -116,6 +117,10 @@ public class HgUtils { // IGNORE SUPPORT HG: following file patterns are added to {Hg repos}/.hgignore and Hg will ignore any files // that match these patterns, reporting "I"status for them // NOI18N private static final String [] HG_IGNORE_FILES = { "\\.orig$", "\\.orig\\..*$", "\\.chg\\..*$", "\\.rej$"}; // NOI18N + private static final String HG_IGNORE_ORIG_FILES = "\\.orig$"; // NOI18N + private static final String HG_IGNORE_ORIG_ANY_FILES = "\\.orig\\..*$"; // NOI18N + private static final String HG_IGNORE_CHG_ANY_FILES = "\\.chg\\..*$"; // NOI18N + private static final String HG_IGNORE_REJ_ANY_FILES = "\\.rej$"; // NOI18N private static final String FILENAME_HGIGNORE = ".hgignore"; // NOI18N @@ -363,23 +368,98 @@ public class HgUtils { return; } } - + try { - fileWriter = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(ignore, true))); - for (String name : HG_IGNORE_FILES) { - fileWriter.write(name + "\n"); // NOI18N + if (!ignore.exists()) { + fileWriter = new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(ignore))); + for (String name : HG_IGNORE_FILES) { + fileWriter.write(name + "\n"); // NOI18N + } + }else{ + addToExistingIgnoredFile(ignore); } } catch (IOException ex) { Mercurial.LOG.log(Level.FINE, "createIgnored(): File {0} - {1}", // NOI18N new Object[] {ignore.getAbsolutePath(), ex.toString()}); }finally { try { - fileWriter.close(); + if(fileWriter != null) fileWriter.close(); hg.getFileStatusCache().refresh(ignore, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); } catch (IOException ex) { Mercurial.LOG.log(Level.FINE, "createIgnored(): File {0} - {1}", // NOI18N new Object[] {ignore.getAbsolutePath(), ex.toString()}); + } + } + } + + private static void addToExistingIgnoredFile(File hgignoreFile) { + if(hgignoreFile == null || !hgignoreFile.exists() || !hgignoreFile.canWrite()) return; + File tempFile = null; + BufferedReader br = null; + PrintWriter pw = null; + boolean bOrigAnyPresent = false; + boolean bOrigPresent = false; + boolean bChgAnyPresent = false; + boolean bRejAnyPresent = false; + + try { + tempFile = new File(hgignoreFile.getAbsolutePath() + ".tmp"); // NOI18N + if (tempFile == null) return; + + br = new BufferedReader(new FileReader(hgignoreFile)); + pw = new PrintWriter(new FileWriter(tempFile)); + + String line = null; + while ((line = br.readLine()) != null) { + if(!bOrigAnyPresent && line.equals(HG_IGNORE_ORIG_ANY_FILES)){ + bOrigAnyPresent = true; + }else if (!bOrigPresent && line.equals(HG_IGNORE_ORIG_FILES)){ + bOrigPresent = true; + }else if (!bChgAnyPresent && line.equals(HG_IGNORE_CHG_ANY_FILES)){ + bChgAnyPresent = true; + }else if (!bRejAnyPresent && line.equals(HG_IGNORE_REJ_ANY_FILES)){ + bRejAnyPresent = true; + } + pw.println(line); + pw.flush(); + } + // If not found add as required + if (!bOrigAnyPresent) { + pw.println(HG_IGNORE_ORIG_ANY_FILES ); + pw.flush(); + } + if (!bOrigPresent) { + pw.println(HG_IGNORE_ORIG_FILES ); + pw.flush(); + } + if (!bChgAnyPresent) { + pw.println(HG_IGNORE_CHG_ANY_FILES ); + pw.flush(); + } + if (!bRejAnyPresent) { + pw.println(HG_IGNORE_REJ_ANY_FILES ); + pw.flush(); + } + + } catch (IOException ex) { + // Ignore + } finally { + try { + if(pw != null) pw.close(); + if(br != null) br.close(); + + boolean bAnyAdditions = !bOrigAnyPresent || !bOrigPresent || !bChgAnyPresent || !bRejAnyPresent; + if(bAnyAdditions){ + if(tempFile != null && tempFile.isFile() && tempFile.canWrite() && hgignoreFile != null){ + hgignoreFile.delete(); + tempFile.renameTo(hgignoreFile); + } + }else{ + tempFile.delete(); + } + } catch (IOException ex) { + // Ignore } } }