コード例 #1
0
  @Override
  protected boolean tryLock(boolean deref) throws IOException {
    dstRef = getRef();
    if (deref) dstRef = dstRef.getLeaf();

    if (dstRef.isSymbolic()) setOldObjectId(null);
    else setOldObjectId(dstRef.getObjectId());

    return true;
  }
コード例 #2
0
  @Override
  public Ref peel(Ref ref) throws IOException {
    final Ref oldLeaf = ref.getLeaf();
    if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref;

    DhtRef newLeaf = doPeel(oldLeaf);

    RefCache cur = readRefs();
    int idx = cur.ids.find(oldLeaf.getName());
    if (0 <= idx && cur.ids.get(idx) == oldLeaf) {
      RefList<DhtRef> newList = cur.ids.set(idx, newLeaf);
      if (cache.compareAndSet(cur, new RefCache(newList, cur))) cachePeeledState(oldLeaf, newLeaf);
    }

    return recreate(ref, newLeaf);
  }
コード例 #3
0
  void schedule(Project.NameKey project, String ref, URIish uri, ReplicationState state) {
    repLog.info("scheduling replication {}:{} => {}", project, ref, uri);
    if (!shouldReplicate(project, ref, state)) {
      return;
    }

    if (!config.replicatePermissions()) {
      PushOne e;
      synchronized (stateLock) {
        e = pending.get(uri);
      }
      if (e == null) {
        try (Repository git = gitManager.openRepository(project)) {
          try {
            Ref head = git.exactRef(Constants.HEAD);
            if (head != null
                && head.isSymbolic()
                && RefNames.REFS_CONFIG.equals(head.getLeaf().getName())) {
              return;
            }
          } catch (IOException err) {
            stateLog.error(String.format("cannot check type of project %s", project), err, state);
            return;
          }
        } catch (IOException err) {
          stateLog.error(String.format("source project %s not available", project), err, state);
          return;
        }
      }
    }

    synchronized (stateLock) {
      PushOne e = pending.get(uri);
      if (e == null) {
        e = opFactory.create(project, uri);
        pool.schedule(e, config.getDelay(), TimeUnit.SECONDS);
        pending.put(uri, e);
      }
      e.addRef(ref);
      state.increasePushTaskCount(project.get(), ref);
      e.addState(ref, state);
      repLog.info("scheduled {}:{} => {} to run after {}s", project, ref, e, config.getDelay());
    }
  }
コード例 #4
0
ファイル: RefDirectory.java プロジェクト: spearce/jgit
  @Override
  public Ref peel(final Ref ref) throws IOException {
    final Ref leaf = ref.getLeaf();
    if (leaf.isPeeled() || leaf.getObjectId() == null) return ref;

    ObjectIdRef newLeaf = doPeel(leaf);

    // Try to remember this peeling in the cache, so we don't have to do
    // it again in the future, but only if the reference is unchanged.
    if (leaf.getStorage().isLoose()) {
      RefList<LooseRef> curList = looseRefs.get();
      int idx = curList.find(leaf.getName());
      if (0 <= idx && curList.get(idx) == leaf) {
        LooseRef asPeeled = ((LooseRef) leaf).peel(newLeaf);
        RefList<LooseRef> newList = curList.set(idx, asPeeled);
        looseRefs.compareAndSet(curList, newList);
      }
    }

    return recreate(ref, newLeaf);
  }
コード例 #5
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final RepositoryTreeNode node = getSelectedNodes(event).get(0);

    if (node.getType() == RepositoryTreeNodeType.ADDITIONALREF) {
      Ref ref = (Ref) node.getObject();
      try {
        RevCommit baseCommit =
            new RevWalk(node.getRepository()).parseCommit(ref.getLeaf().getObjectId());
        WizardDialog dlg =
            new WizardDialog(
                getShell(event), new CreateBranchWizard(node.getRepository(), baseCommit.name()));
        dlg.setHelpAvailable(false);
        dlg.open();
      } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
      }
      return null;
    }
    String base = null;
    if (node.getObject() instanceof Ref) base = ((Ref) node.getObject()).getName();
    new WizardDialog(getShell(event), new CreateBranchWizard(node.getRepository(), base)).open();
    return null;
  }
コード例 #6
0
 private String getSimpleText(RepositoryTreeNode node) {
   switch (node.getType()) {
     case REPO:
       File directory = ((Repository) node.getObject()).getDirectory();
       StringBuilder sb = new StringBuilder();
       sb.append(directory.getParentFile().getName());
       sb.append(" - "); // $NON-NLS-1$
       sb.append(directory.getAbsolutePath());
       return sb.toString();
     case FILE:
       // fall through
     case FOLDER:
       return ((File) node.getObject()).getName();
     case BRANCHES:
       return UIText.RepositoriesView_Branches_Nodetext;
     case LOCAL:
       return UIText.RepositoriesViewLabelProvider_LocalNodetext;
     case REMOTETRACKING:
       return UIText.RepositoriesViewLabelProvider_RemoteTrackingNodetext;
     case BRANCHHIERARCHY:
       IPath fullPath = (IPath) node.getObject();
       return fullPath.lastSegment();
     case TAGS:
       return UIText.RepositoriesViewLabelProvider_TagsNodeText;
     case ADDITIONALREFS:
       return UIText.RepositoriesViewLabelProvider_SymbolicRefNodeText;
     case REMOTES:
       return UIText.RepositoriesView_RemotesNodeText;
     case REF:
       // fall through
     case TAG:
       {
         Ref ref = (Ref) node.getObject();
         // shorten the name
         String refName = Repository.shortenRefName(ref.getName());
         if (node.getParent().getType() == RepositoryTreeNodeType.BRANCHHIERARCHY) {
           int index = refName.lastIndexOf('/');
           refName = refName.substring(index + 1);
         }
         return refName;
       }
     case ADDITIONALREF:
       {
         Ref ref = (Ref) node.getObject();
         // shorten the name
         String refName = Repository.shortenRefName(ref.getName());
         if (ref.isSymbolic()) {
           refName =
               refName
                   + " - " //$NON-NLS-1$
                   + ref.getLeaf().getName()
                   + " - "
                   + ObjectId.toString(ref.getLeaf().getObjectId()); // $NON-NLS-1$
         } else {
           refName =
               refName
                   + " - " //$NON-NLS-1$
                   + ObjectId.toString(ref.getObjectId());
         }
         return refName;
       }
     case WORKINGDIR:
       if (node.getRepository().isBare())
         return UIText.RepositoriesView_WorkingDir_treenode
             + " - " //$NON-NLS-1$
             + UIText.RepositoriesViewLabelProvider_BareRepositoryMessage;
       else
         return UIText.RepositoriesView_WorkingDir_treenode
             + " - " //$NON-NLS-1$
             + node.getRepository().getWorkTree().getAbsolutePath();
     case REMOTE:
       // fall through
     case PUSH:
       // fall through
     case FETCH:
       // fall through
     case ERROR:
       return (String) node.getObject();
   }
   return null;
 }
コード例 #7
0
  public StyledString getStyledText(Object element) {
    if (!(element instanceof RepositoryTreeNode)) return null;

    RepositoryTreeNode node = (RepositoryTreeNode) element;

    try {
      switch (node.getType()) {
        case REPO:
          Repository repository = (Repository) node.getObject();
          File directory = repository.getDirectory();
          StyledString string = new StyledString(directory.getParentFile().getName());
          string.append(
              " - " + directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
          String branch = repository.getBranch();
          if (repository.getRepositoryState() != RepositoryState.SAFE)
            branch += " - " + repository.getRepositoryState().getDescription(); // $NON-NLS-1$
          string.append(
              " [" + branch + "]", StyledString.DECORATIONS_STYLER); // $NON-NLS-1$//$NON-NLS-2$
          return string;
        case ADDITIONALREF:
          Ref ref = (Ref) node.getObject();
          // shorten the name
          StyledString refName = new StyledString(Repository.shortenRefName(ref.getName()));
          if (ref.isSymbolic()) {
            refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
            refName.append(ref.getLeaf().getName(), StyledString.QUALIFIER_STYLER);
            refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
            refName.append(
                ObjectId.toString(ref.getLeaf().getObjectId()), StyledString.QUALIFIER_STYLER);
          } else {
            refName.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
            refName.append(ObjectId.toString(ref.getObjectId()), StyledString.QUALIFIER_STYLER);
          }
          return refName;
        case WORKINGDIR:
          StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode);
          dirString.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
          if (node.getRepository().isBare()) {
            dirString.append(
                UIText.RepositoriesViewLabelProvider_BareRepositoryMessage,
                StyledString.QUALIFIER_STYLER);
          } else {
            dirString.append(
                node.getRepository().getWorkTree().getAbsolutePath(),
                StyledString.QUALIFIER_STYLER);
          }
          return dirString;
        case PUSH:
          // fall through
        case FETCH:
          // fall through
        case FILE:
          // fall through
        case FOLDER:
          // fall through
        case BRANCHES:
          // fall through
        case LOCAL:
          // fall through
        case REMOTETRACKING:
          // fall through
        case BRANCHHIERARCHY:
          // fall through
        case TAGS:
          // fall through;
        case ADDITIONALREFS:
          // fall through
        case REMOTES:
          // fall through
        case REMOTE:
          // fall through
        case ERROR:
          // fall through
        case REF:
          // fall through
        case TAG:
          {
            String label = getSimpleText(node);
            if (label != null) return new StyledString(label);
          }
      }
    } catch (IOException e) {
      Activator.logError(e.getMessage(), e);
    }

    return null;
  }