Example #1
0
 /**
  * Determines the sticky information for a given file. If the file is new then it returns its
  * parent directory's sticky info, if any.
  *
  * @param file file to examine
  * @return String sticky information for a file (without leading N, D or T specifier) or null
  */
 public static String getSticky(File file) {
   if (file == null) return null;
   FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(file);
   if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) {
     return getSticky(file.getParentFile());
   } else if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
     return null;
   }
   if (file.isDirectory()) {
     String std =
         CvsVersioningSystem.getInstance().getAdminHandler().getStickyTagForDirectory(file);
     if (std != null) {
       std = std.substring(1);
     }
     return std;
   }
   Entry entry = info.getEntry(file);
   if (entry != null) {
     String stickyInfo = null;
     if (entry.getTag() != null) stickyInfo = entry.getTag(); // NOI18N
     else if (entry.getDate() != null) stickyInfo = entry.getDateFormatted(); // NOI18N
     return stickyInfo;
   }
   return null;
 }
 private static FileStatus getFileStatusForAbsentFile(Entry entry) {
   if (entry == null || entry.isDirectory()) {
     return FileStatus.UNKNOWN;
   }
   if (entry.isRemoved()) {
     return FileStatus.DELETED;
   }
   return FileStatus.DELETED_FROM_FS;
 }
Example #3
0
 /**
  * Get the locally deleted files (files which are under version control, and which existed
  * locally, but which have been deleted locally).
  *
  * @param set The set to store the locally deleted files in
  * @param dir The directory to look for deleted files in (non-recursively)
  * @throws IOException
  */
 public void getLocallyDeletedFiles(Set set, File dir) throws IOException {
   Iterator i = adminHandler.getEntries(dir);
   while (i.hasNext()) {
     Entry entry = (Entry) i.next();
     File file = new File(dir, entry.getName());
     if (!file.exists() && !entry.isDirectory()) {
       set.add(new File(dir, entry.getName()));
     }
   }
 }
Example #4
0
 /**
  * Set the revision of a versioned file to the given revision, without altering the file contents.
  * (This is a way to "update" but keep the current file contents. The server doesn't need to be
  * contacted).
  */
 public synchronized void setFileVersion(File file, String revision) throws IOException {
   Entry cvsEntry = adminHandler.getEntry(file);
   if (cvsEntry != null) {
     cvsEntry.setRevision(revision);
   } else {
     cvsEntry = new Entry();
     cvsEntry.setName(file.getName());
     cvsEntry.setRevision(revision);
   }
   adminHandler.setEntry(file, cvsEntry);
 }
  public static FileStatus getStatus(VirtualFile file, Entry entry) {
    if (file == null) {
      return getFileStatusForAbsentFile(entry);
    }

    if (entry == null) {
      return getFileStatusForAbsentEntry(file);
    }

    if (entry.isDirectory()) {
      return FileStatus.NOT_CHANGED;
    }

    if (entry.isAddedFile()) {
      return FileStatus.ADDED;
    }

    if (entry.isRemoved()) {
      return FileStatus.DELETED;
    }

    if (entry.isResultOfMerge()) {
      if (entry.isConflict()) {
        return FileStatus.MERGED_WITH_CONFLICTS;
      } else {
        return FileStatus.MERGE;
      }
    }

    Date revisionDate = entry.getLastModified();

    if (revisionDate == null) {
      return FileStatus.MODIFIED;
    }

    final long entryDate = revisionDate.getTime();
    final long fileDate = CvsVfsUtil.getTimeStamp(file);
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "getStatus() for "
              + file.getPath()
              + ": entry date "
              + entryDate
              + ", file date "
              + fileDate);
    }
    return (timeStampsAreEqual(entryDate, fileDate)) ? FileStatus.NOT_CHANGED : FileStatus.MODIFIED;
  }
Example #6
0
  /**
   * Client must checks conflicted files timestamps. Until it changes it should not commit the file
   * (it actually decides server by testing sent entry).
   *
   * <p>Uses fake PseudoCvsServer.
   */
  public void test36288() throws Exception {
    File tmpDir = TestKit.createTmpFolder("commitConflictTest");
    String protocolLog = new File(tmpDir, "protocol").getAbsolutePath();
    System.setProperty("cvsClientLog", protocolLog);
    System.out.println(protocolLog);

    // prepare working directory
    File CVSdir = new File(tmpDir, "CVS");
    CVSdir.mkdirs();
    File entries = new File(CVSdir, "Entries");
    OutputStream out = new FileOutputStream(entries);
    String dateString = "Thu Mar 24 15:14:27 2005";
    String data = "/conflict.txt/1.2/Result of merge+" + dateString + "//\nD";
    out.write(data.getBytes("utf8"));
    out.flush();
    out.close();

    File conflict_txt = new File(tmpDir, "conflict.txt");
    out = new FileOutputStream(conflict_txt);
    data =
        "AAA\n"
            + "BBB\n"
            + "<<<<<<< conflict.txt\n"
            + "YYY <= fix\n"
            + "=======\n"
            + "222 <= fix\n"
            + ">>>>>>> 1.2\n"
            + "DDD\n"
            + "EEE\n";
    out.write(data.getBytes("utf8"));
    out.flush();
    out.close();
    Date date = Entry.getLastModifiedDateFormatter().parse(dateString);
    conflict_txt.setLastModified(date.getTime());

    PseudoCvsServer cvss = new PseudoCvsServer("protocol/iz36288.in");

    File requestsLog = File.createTempFile("requests", null, tmpDir);
    cvss.logRequests(new FileOutputStream(requestsLog));
    Thread cvssThread = new Thread(cvss);
    cvssThread.start();
    String cvsRoot = cvss.getCvsRoot();

    File root = new File(CVSdir, "Root");
    out = new FileOutputStream(root);
    out.write(cvsRoot.getBytes("utf8"));
    out.flush();
    out.close();

    File repo = new File(CVSdir, "Repository");
    out = new FileOutputStream(repo);
    out.write("/cvs".getBytes("utf8"));
    out.flush();
    out.close();

    // commit command
    CVSRoot CvsRoot = CVSRoot.parse(cvsRoot);
    GlobalOptions gtx = new GlobalOptions();
    gtx.setCVSRoot(cvsRoot);
    Connection connection = new PServerConnection(CvsRoot);
    Client client = new Client(connection, new StandardAdminHandler());
    client.setLocalPath(tmpDir.getAbsolutePath());

    CommitCommand commit = new CommitCommand();
    File[] files = new File[] {new File(tmpDir, "conflict.txt")};
    commit.setFiles(files);

    client.executeCommand(commit, gtx);
    cvss.stop();
    cvssThread.join();

    // check test matching golden file (here critical line from iz36288.out)

    InputStream actual = new FileInputStream(requestsLog);
    LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "UTF-8"));
    boolean foundConflictLine = false;
    String line = lineReader.readLine();
    StringBuffer sb = new StringBuffer();
    while (foundConflictLine == false && line != null) {
      sb.append(line + "\n");
      foundConflictLine |= "Entry /conflict.txt/1.2/+=//".equals(line);
      line = lineReader.readLine();
    }
    assertTrue("Missing 'Entry /conflict.txt/1.2/+=//' in:\n" + sb.toString(), foundConflictLine);

    TestKit.deleteRecursively(tmpDir);
  }
Example #7
0
  /** Create file CVS/Baserev with entries like BEntry.java/1.2/ */
  private void addBaserevEntry(ClientServices clientServices, File file) throws IOException {
    final Entry entry = clientServices.getEntry(file);
    if (entry == null
        || entry.getRevision() == null
        || entry.isNewUserFile()
        || entry.isUserFileToBeRemoved()) {
      throw new IllegalArgumentException(
          "File does not have an Entry or Entry is invalid!"); // NOI18N
    }

    File baserevFile = new File(file.getParentFile(), "CVS/Baserev"); // NOI18N
    File backupFile = new File(baserevFile.getAbsolutePath() + '~');
    BufferedReader reader = null;
    BufferedWriter writer = null;
    boolean append = true;
    boolean writeFailed = true;
    final String entryStart = 'B' + file.getName() + '/';
    try {
      writer = new BufferedWriter(new FileWriter(backupFile));
      writeFailed = false;
      reader = new BufferedReader(new FileReader(baserevFile));

      for (String line = reader.readLine(); line != null; line = reader.readLine()) {

        if (line.startsWith(entryStart)) {
          append = false;
        }
        writeFailed = true;
        writer.write(line);
        writer.newLine();
        writeFailed = false;
      }
    } catch (IOException ex) {
      if (writeFailed) {
        throw ex;
      }
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException ex) {
          // ignore
        }
      }
      if (writer != null) {
        try {
          if (append && !writeFailed) {
            writer.write(entryStart + entry.getRevision() + '/');
            writer.newLine();
          }
        } finally {
          try {
            writer.close();
          } catch (IOException ex) {
            // ignore
          }
        }
      }
    }
    baserevFile.delete();
    backupFile.renameTo(baserevFile);
  }