/** Returns the file used for backup the specified file in the edit command. */
 public static File getEditBackupFile(File file) {
   return new File(file.getParent(), "CVS/Base/" + file.getName()); // NOI18N
 }
  /** 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);
  }