コード例 #1
0
 /** {@inheritDoc} */
 @Override
 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   String t = (String) aValue;
   BranchDescriptor d = myBranches.get(rowIndex);
   if (d.root == null) {
     return;
   }
   if (columnIndex == REVISION_COLUMN) {
     String currentCandidate = getCandidateLocal(d.referenceToCheckout, d);
     boolean isCurrentMatchCandidate =
         currentCandidate != null && currentCandidate.equals(d.newBranchName);
     d.referenceToCheckout = t;
     if ((StringUtil.isEmpty(d.newBranchName) || isCurrentMatchCandidate)
         && t.startsWith(REMOTES_PREFIX)
         && d.referencesToSelect.contains(t)) {
       String candidate = getCandidateLocal(t, d);
       if (candidate != null) {
         d.newBranchName = candidate;
       }
     }
   } else if (columnIndex == NEW_BRANCH_COLUMN) {
     d.newBranchName = t;
   }
   d.updateStatus();
   fireTableRowsUpdated(rowIndex, rowIndex);
 }
コード例 #2
0
 /**
  * Prepare branches for the case of remote checkout
  *
  * @param remoteBranch the remote branch to checkout
  * @param roots the collection of vcs roots
  * @return the list of descriptors for the remote
  * @throws VcsException if failed
  */
 private List<BranchDescriptor> prepareBranchesForRemote(
     String remoteBranch, List<VirtualFile> roots) throws VcsException {
   assert roots.size() > 0;
   List<BranchDescriptor> rc = new ArrayList<BranchDescriptor>();
   HashSet<String> allBranches = new HashSet<String>();
   allBranches.addAll(myConfig.getConfigurationNames());
   final String qualifiedBranch = "remotes/" + remoteBranch;
   String firstRemote = remoteBranch.endsWith("/HEAD") ? null : qualifiedBranch;
   for (VirtualFile root : roots) {
     BranchDescriptor d = new BranchDescriptor();
     d.root = root;
     d.currentReference = myConfig.describeRoot(root);
     if (firstRemote == null) {
       firstRemote = resolveHead(qualifiedBranch, d.root.getPath());
     }
     d.referenceToCheckout = qualifiedBranch;
     Branch.listAsStrings(myProject, root, false, true, d.existingBranches, null);
     Branch.listAsStrings(myProject, root, true, true, d.referencesToSelect, null);
     allBranches.addAll(d.existingBranches);
     rc.add(d);
   }
   String candidate;
   if (firstRemote == null) {
     candidate = "untitled";
   } else {
     int p = firstRemote.indexOf('/', REMOTES_PREFIX.length() + 1);
     assert p > 0 && p < firstRemote.length() - 1
         : "Unexpected format for remote branch: " + firstRemote;
     candidate = firstRemote.substring(p + 1);
   }
   String actual = null;
   if (!allBranches.contains(candidate)) {
     actual = candidate;
   } else {
     for (int i = 2; i < Integer.MAX_VALUE; i++) {
       String t = candidate + i;
       if (!allBranches.contains(t)) {
         actual = t;
         break;
       }
     }
     assert actual != null : "Unexpected number of branches: " + remoteBranch;
   }
   for (BranchDescriptor d : rc) {
     d.newBranchName = actual;
     d.updateStatus();
   }
   return rc;
 }