예제 #1
1
 @NotNull
 private Map<String, Ref> getRemoteRefs(@NotNull Repository db, @NotNull GitVcsRoot gitRoot)
     throws Exception {
   long retryInterval = myConfig.getConnectionRetryIntervalMillis();
   int attemptsLeft = myConfig.getConnectionRetryAttempts();
   while (true) {
     final long start = System.currentTimeMillis();
     Transport transport = null;
     FetchConnection connection = null;
     try {
       transport =
           myTransportFactory.createTransport(
               db, gitRoot.getRepositoryFetchURL(), gitRoot.getAuthSettings());
       connection = transport.openFetch();
       return connection.getRefsMap();
     } catch (NotSupportedException nse) {
       throw friendlyNotSupportedException(gitRoot, nse);
     } catch (TransportException te) {
       attemptsLeft--;
       if (isRecoverable(te) && attemptsLeft > 0) {
         LOG.warn(
             "List remote refs failed: "
                 + te.getMessage()
                 + ", "
                 + attemptsLeft
                 + " attempt(s) left");
       } else {
         throw friendlyTransportException(te, gitRoot);
       }
     } catch (WrongPassphraseException e) {
       throw new VcsException(e.getMessage(), e);
     } finally {
       if (connection != null) connection.close();
       if (transport != null) transport.close();
       final long finish = System.currentTimeMillis();
       PERFORMANCE_LOG.debug(
           "[getRemoteRefs] repository: "
               + LogUtil.describe(gitRoot)
               + ", took "
               + (finish - start)
               + "ms");
     }
     Thread.sleep(retryInterval);
     retryInterval *= 2;
   }
 }
예제 #2
0
 public Collection<VcsClientMapping> getClientMapping(
     final @NotNull VcsRoot root, final @NotNull IncludeRule rule) throws VcsException {
   final OperationContext context = createContext(root, "client-mapping");
   try {
     GitVcsRoot gitRoot = context.getGitRoot();
     URIish uri = gitRoot.getRepositoryFetchURL();
     return Collections.singletonList(
         new VcsClientMapping(
             String.format("|%s|%s", uri.toString(), rule.getFrom()), rule.getTo()));
   } finally {
     context.close();
   }
 }
예제 #3
0
 @NotNull
 public RepositoryStateData getCurrentState(@NotNull GitVcsRoot gitRoot) throws VcsException {
   String refInRoot = gitRoot.getRef();
   String fullRef = GitUtils.expandRef(refInRoot);
   Map<String, String> branchRevisions = new HashMap<String, String>();
   for (Ref ref : getRemoteRefs(gitRoot.getOriginalRoot()).values()) {
     if (!ref.getName().startsWith("ref")) continue;
     if (!gitRoot.isReportTags() && isTag(ref) && !fullRef.equals(ref.getName())) continue;
     branchRevisions.put(ref.getName(), getRevision(ref));
   }
   if (branchRevisions.get(fullRef) == null && !gitRoot.isIgnoreMissingDefaultBranch()) {
     throw new VcsException(
         "Cannot find revision of the default branch '"
             + refInRoot
             + "' of vcs root "
             + LogUtil.describe(gitRoot));
   }
   return RepositoryStateData.createVersionState(fullRef, branchRevisions);
 }