Remember which files were already processed by commit (variable ALREADY_COMMITTED_FILES added) turbo_sync2
authormentlicher@netbeans.org
Thu, 09 Sep 2004 12:27:33 +0000
changeset 517227a7292b2dcd
parent 5171 5c9bc4de0ad0
child 5173 067600b19994
Remember which files were already processed by commit (variable ALREADY_COMMITTED_FILES added)
and do not keep showing the commit dialog when the reported files were already processed.
This is a fix of issue #48399.
vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommit.java
vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommitTemplateGetter.java
     1.1 --- a/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommit.java	Thu Sep 09 09:27:44 2004 +0000
     1.2 +++ b/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommit.java	Thu Sep 09 12:27:33 2004 +0000
     1.3 @@ -36,6 +36,7 @@
     1.4  import org.netbeans.modules.vcscore.cmdline.UserCommand;
     1.5  import org.netbeans.modules.vcscore.cmdline.VcsAdditionalCommand;
     1.6  import org.netbeans.modules.vcscore.util.Table;
     1.7 +import org.netbeans.modules.vcscore.util.VcsUtilities;
     1.8  import org.netbeans.spi.vcs.commands.CommandSupport;
     1.9  import org.openide.ErrorManager;
    1.10  
    1.11 @@ -62,8 +63,6 @@
    1.12      
    1.13      private VcsFileSystem fileSystem = null;
    1.14      
    1.15 -    private HashMap cachedEntries = new HashMap();
    1.16 -    
    1.17      private FileStatusUpdater fileStatusUpdater;
    1.18  
    1.19      /** Creates new CvsCommit */
    1.20 @@ -93,12 +92,14 @@
    1.21          return files;
    1.22      }
    1.23  
    1.24 -    private ArrayList getCommitedFiles(String fsRoot, String relativePath,
    1.25 -                                       String template, char ps) {
    1.26 +    static List getCommitedFiles(String fsRoot, String relativePath,
    1.27 +                                 String template, char ps) {
    1.28          //System.out.println("getCommitedFiles("+template+")");
    1.29          ArrayList list = new ArrayList();
    1.30          int beginPath = template.indexOf(COMMITTING);
    1.31          //System.out.println("beginPath = "+beginPath);
    1.32 +        Map cachedEntries = new HashMap();
    1.33 +    
    1.34          File root = new File(fsRoot);
    1.35          if (beginPath < 0) beginPath = template.length();
    1.36          do {
    1.37 @@ -128,21 +129,22 @@
    1.38                  beginFile += PRE_FILE.length();
    1.39                  String files = template.substring(beginFile, eol).trim();
    1.40                  files = files.replace(File.separatorChar, '/');
    1.41 -                addFiles(list, root, path, files, ps);
    1.42 +                addFiles(list, root, path, files, ps, cachedEntries);
    1.43                  //list.add(path + "/" + file);
    1.44              } while (true);
    1.45          } while (beginPath < template.length());
    1.46          return list;
    1.47      }
    1.48      
    1.49 -    private void addFiles(List list, File root, String path, String files, char ps) {
    1.50 +    private static void addFiles(List list, File root, String path, String files,
    1.51 +                                 char ps, Map cachedEntries) {
    1.52          int begin = 0;
    1.53          int end = files.indexOf(' ');
    1.54          if (end < 0) end = files.length();
    1.55          while (begin < end) {
    1.56              String name;
    1.57              if (end < files.length()) {
    1.58 -                name = getFileFromRow(files.substring(begin), root, path, ps);
    1.59 +                name = getFileFromRow(files.substring(begin), root, path, ps, cachedEntries);
    1.60                  end = begin + name.length();
    1.61              } else {
    1.62                  name = files.substring(begin, end);
    1.63 @@ -159,7 +161,8 @@
    1.64          }
    1.65      }
    1.66      
    1.67 -    private String getFileFromRow(String row, File root, String path, char ps) {
    1.68 +    private static String getFileFromRow(String row, File root, String path,
    1.69 +                                         char ps, Map cachedEntries) {
    1.70          int index;
    1.71          //System.out.println("getFileFromRow("+row+")");
    1.72          for (index = row.indexOf(' '); index > 0 && index < row.length(); index = row.indexOf(' ', index + 1)) {
    1.73 @@ -168,10 +171,10 @@
    1.74              if (sepIndex > 0) {
    1.75                  String fileName = file.substring(sepIndex + 1);
    1.76                  String filePath = file.substring(0, sepIndex);
    1.77 -                if (isCVSFile(root, path + "/" + filePath, fileName, ps)) break;
    1.78 +                if (isCVSFile(root, path + "/" + filePath, fileName, ps, cachedEntries)) break;
    1.79              } else {
    1.80                  //System.out.println(" file = "+file);
    1.81 -                if (isCVSFile(root, path, file, ps)) break;
    1.82 +                if (isCVSFile(root, path, file, ps, cachedEntries)) break;
    1.83                  //System.out.println("   is not CVS file!");
    1.84              }
    1.85          }
    1.86 @@ -180,15 +183,16 @@
    1.87          else return row;
    1.88      }
    1.89      
    1.90 -    private boolean isCVSFile(File root, String path, String name, char ps) {
    1.91 +    private static boolean isCVSFile(File root, String path, String name,
    1.92 +                                     char ps, Map cachedEntries) {
    1.93          path = path.replace('/', ps);
    1.94          File dir = new File(root, path);
    1.95          File entries = new File(dir, "CVS/Entries");
    1.96          if (!entries.exists() || !entries.canRead()) return true;
    1.97 -        return isFileInEntries(name, entries);
    1.98 +        return isFileInEntries(name, entries, cachedEntries);
    1.99      }
   1.100      
   1.101 -    private boolean isFileInEntries(String name, File entries) {
   1.102 +    private static boolean isFileInEntries(String name, File entries, Map cachedEntries) {
   1.103          List files = (List) cachedEntries.get(entries);
   1.104          if (files == null) {
   1.105              files = loadEntries(entries);
   1.106 @@ -197,7 +201,7 @@
   1.107          return files.contains(name);
   1.108      }
   1.109      
   1.110 -    private List loadEntries(File entries) {
   1.111 +    private static List loadEntries(File entries) {
   1.112          ArrayList entriesFiles = new ArrayList();
   1.113          if (entries.exists() && entries.canRead() && entries.canWrite()) {
   1.114              int fileIndex = -1;
   1.115 @@ -227,7 +231,7 @@
   1.116      //private void setProcessingFiles(ArrayList files, Hashtable vars) {
   1.117      //}
   1.118  
   1.119 -    private Table getFiles(ArrayList filesList) {
   1.120 +    private Table getFiles(List filesList) {
   1.121          Table files = new Table();
   1.122          for (Iterator it = filesList.iterator(); it.hasNext(); ) {
   1.123              String file = (String) it.next();
   1.124 @@ -240,7 +244,7 @@
   1.125      /**
   1.126       * Run the commit and return the appropriate task IDs.
   1.127       */
   1.128 -    private long[] doCommit(CommandsPool cpool, VcsCommand cmdCommit, ArrayList filesList,
   1.129 +    private long[] doCommit(CommandsPool cpool, VcsCommand cmdCommit, List filesList,
   1.130                              Hashtable vars, CommandOutputListener stderrNRListener,
   1.131                              CommandDataOutputListener stderrListener,
   1.132                              VcsCommandExecutor[][] executorsRet) {
   1.133 @@ -301,7 +305,17 @@
   1.134          //boolean committed = false;
   1.135          String committedStr = (String) vars.get("IS_COMMITTED");
   1.136          boolean committed = committedStr != null && committedStr.length() > 0;
   1.137 -        ArrayList alreadyCommittedFiles = new ArrayList();
   1.138 +        List alreadyCommittedFiles;
   1.139 +        String alreadyCommittedFilesStr = (String) vars.get("ALREADY_COMMITTED_FILES");
   1.140 +        if (alreadyCommittedFilesStr == null) {
   1.141 +            alreadyCommittedFiles = new ArrayList();
   1.142 +        } else {
   1.143 +            try {
   1.144 +                alreadyCommittedFiles = (List) VcsUtilities.decodeValue(alreadyCommittedFilesStr);
   1.145 +            } catch (IOException ioex) {
   1.146 +                alreadyCommittedFiles = new ArrayList();
   1.147 +            }
   1.148 +        }
   1.149          //do {
   1.150              //VcsCommand cmdTemplate = fileSystem.getCommand(args[0]);
   1.151              VcsCommand cmdCommit1 = fileSystem.getCommand(args[0]);
   1.152 @@ -311,7 +325,7 @@
   1.153              //buff.delete(0, buff.length());
   1.154              String templateContent = (String) vars.get("ORIGINAL_TEMPLATE_CONTENT");
   1.155              if (templateContent == null) templateContent = "";
   1.156 -            ArrayList filesCommited = null;
   1.157 +            List filesCommited = null;
   1.158              if ("-f".equals(vars.get("FORCE"))) {
   1.159                  filesCommited = new ArrayList(filePaths);
   1.160              } else {
   1.161 @@ -357,6 +371,9 @@
   1.162              if (filePaths.size() > 0) {
   1.163                  vars.put("TEMPLATE_FILE_PLEASE_WAIT_TEXT", NbBundle.getMessage(CvsCommit.class, "CvsCommit.templateFileCheck"));
   1.164                  vars.put("COMMIT_COMMANDS_IDS", IDStr);
   1.165 +                try {
   1.166 +                    vars.put("ALREADY_COMMITTED_FILES", VcsUtilities.encodeValue(alreadyCommittedFiles));
   1.167 +                } catch (IOException ioex) {}
   1.168                  CommandSupport cmdSupport = fileSystem.getCommandSupport("COMMIT"); // Myself
   1.169                  Command cmd = cmdSupport.createCommand();
   1.170                  if (cmd instanceof VcsDescribedCommand) {
     2.1 --- a/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommitTemplateGetter.java	Thu Sep 09 09:27:44 2004 +0000
     2.2 +++ b/vcs.profiles.cvsprofiles/src/org/netbeans/modules/vcs/profiles/cvsprofiles/commands/CvsCommitTemplateGetter.java	Thu Sep 09 12:27:33 2004 +0000
     2.3 @@ -22,6 +22,7 @@
     2.4  import java.io.OutputStream;
     2.5  import java.io.Writer;
     2.6  import java.util.Hashtable;
     2.7 +import java.util.List;
     2.8  import java.util.regex.Pattern;
     2.9  
    2.10  import org.openide.ErrorManager;
    2.11 @@ -356,12 +357,22 @@
    2.12                  return false;
    2.13              }
    2.14              String committedStr = (String) vars.get("IS_COMMITTED");
    2.15 +            String alreadyCommittedFilesStr = (String) vars.get("ALREADY_COMMITTED_FILES");
    2.16              vars.clear(); // So that many variables are not unnecessarily updated.
    2.17              String outputStr = output.toString();
    2.18              vars.put("ORIGINAL_TEMPLATE_CONTENT", outputStr);//outputFile.getAbsolutePath());
    2.19              vars.put(org.netbeans.modules.vcscore.util.VariableInputDialog.VAR_UPDATE_CHANGED_FROM_SELECTOR, "true");
    2.20 -            if (outputStr.trim().length() == 0) {
    2.21 -                boolean committed = committedStr != null && committedStr.length() > 0;
    2.22 +            boolean areRemainingFiles = true;
    2.23 +            if (alreadyCommittedFilesStr != null) {
    2.24 +                List alreadyCommittedFiles;
    2.25 +                try {
    2.26 +                    alreadyCommittedFiles = (List) VcsUtilities.decodeValue(alreadyCommittedFilesStr);
    2.27 +                    areRemainingFiles = areSomeFilesRemaining(fsRoot, relativePath, outputStr, ps, alreadyCommittedFiles);
    2.28 +                } catch (IOException ioex) {
    2.29 +                }
    2.30 +            }
    2.31 +            if (outputStr.trim().length() == 0 || !areRemainingFiles) {
    2.32 +                boolean committed = committedStr != null && committedStr.length() > 0 || !areRemainingFiles;
    2.33                  if (committed) {
    2.34                      vars.put(org.netbeans.modules.vcscore.util.VariableInputDialog.VAR_CANCEL_DIALOG_BY_PRECOMMAND, "true");
    2.35                  }
    2.36 @@ -372,6 +383,14 @@
    2.37          return true;
    2.38      }
    2.39      
    2.40 +    private boolean areSomeFilesRemaining(String fsRoot, String relativePath,
    2.41 +                                          String templateContent, char ps,
    2.42 +                                          List filesCommitted) {
    2.43 +        List filesToBeCommited = CvsCommit.getCommitedFiles(fsRoot, relativePath, templateContent, ps);
    2.44 +        filesToBeCommited.removeAll(filesCommitted);
    2.45 +        return filesToBeCommited.size() > 0;
    2.46 +    }
    2.47 +    
    2.48      private static void waitForCommands(String IDStr) throws InterruptedException {
    2.49          String[] IDStrs = VcsUtilities.getQuotedStrings(IDStr);
    2.50          for (int i = 0; i < IDStrs.length; i++) {