Esempio n. 1
0
 /** Update the settings for the global window cache of the workspace. */
 public static void reconfigureWindowCache() {
   final WindowCacheConfig c = new WindowCacheConfig();
   IEclipsePreferences d = DefaultScope.INSTANCE.getNode(Activator.getPluginId());
   IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
   c.setPackedGitLimit(
       p.getInt(
           GitCorePreferences.core_packedGitLimit,
           d.getInt(GitCorePreferences.core_packedGitLimit, 0)));
   c.setPackedGitWindowSize(
       p.getInt(
           GitCorePreferences.core_packedGitWindowSize,
           d.getInt(GitCorePreferences.core_packedGitWindowSize, 0)));
   c.setPackedGitMMAP(
       p.getBoolean(
           GitCorePreferences.core_packedGitMMAP,
           d.getBoolean(GitCorePreferences.core_packedGitMMAP, false)));
   c.setDeltaBaseCacheLimit(
       p.getInt(
           GitCorePreferences.core_deltaBaseCacheLimit,
           d.getInt(GitCorePreferences.core_deltaBaseCacheLimit, 0)));
   c.setStreamFileThreshold(
       p.getInt(
           GitCorePreferences.core_streamFileThreshold,
           d.getInt(GitCorePreferences.core_streamFileThreshold, 0)));
   c.install();
 }
 @Override
 public Image getImage(Object element) {
   RepositoryTreeNode node = (RepositoryTreeNode) element;
   if (node.getType() == RepositoryTreeNodeType.TAG) {
     // determine if we have a lightweight tag and
     // use the corresponding icon
     RevObject any;
     try {
       ObjectId id = node.getRepository().resolve(((Ref) node.getObject()).getName());
       if (id == null) return null;
       any = new RevWalk(node.getRepository()).parseAny(id);
     } catch (MissingObjectException e) {
       Activator.logError(e.getMessage(), e);
       return null;
     } catch (IOException e) {
       Activator.logError(e.getMessage(), e);
       return null;
     }
     if (any instanceof RevCommit)
       // lightweight tag
       return decorateImage(lightweightTagImage, element);
     else
       // annotated or signed tag
       return decorateImage(node.getType().getIcon(), element);
   } else return decorateImage(node.getType().getIcon(), element);
 }
Esempio n. 3
0
 private UserPasswordCredentials getCredentialsFromSecureStore(final URIish uri) {
   UserPasswordCredentials credentials = null;
   try {
     credentials = Activator.getDefault().getSecureStore().getCredentials(uri);
   } catch (StorageException e) {
     Activator.logError(UIText.EGitCredentialsProvider_errorReadingCredentials, e);
   }
   return credentials;
 }
Esempio n. 4
0
  private void map(final RepositoryMapping m) {
    final IResource r;
    final File git;
    final IResource dotGit;
    IContainer c = null;

    m.clear();
    r = getProject().findMember(m.getContainerPath());
    if (r instanceof IContainer) {
      c = (IContainer) r;
    } else if (r != null) {
      c = Utils.getAdapter(r, IContainer.class);
    }

    if (c == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    m.setContainer(c);

    IPath absolutePath = m.getGitDirAbsolutePath();
    if (absolutePath == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    git = absolutePath.toFile();
    if (!git.isDirectory() || !new File(git, "config").isFile()) { // $NON-NLS-1$
      logAndUnmapGoneMappedResource(m);
      return;
    }

    try {
      m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git));
    } catch (IOException ioe) {
      logAndUnmapGoneMappedResource(m);
      return;
    }

    m.fireRepositoryChanged();

    trace(
        "map " //$NON-NLS-1$
            + c
            + " -> " //$NON-NLS-1$
            + m.getRepository());
    try {
      c.setSessionProperty(MAPPING_KEY, m);
    } catch (CoreException err) {
      Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err);
    }

    dotGit = c.findMember(Constants.DOT_GIT);
    if (dotGit != null && dotGit.getLocation().toFile().equals(git)) {
      protect(dotGit);
    }
  }
 @Override
 public void reset(URIish uri) {
   try {
     Activator.getDefault().getSecureStore().clearCredentials(uri);
     user = null;
     password = null;
   } catch (IOException e) {
     Activator.logError(
         MessageFormat.format(UIText.EGitCredentialsProvider_FailedToClearCredentials, uri), e);
   }
 }
Esempio n. 6
0
  private IFileRevision[] buildRevisions(final IProgressMonitor monitor, final int flags) {
    if (walk == null) return NO_REVISIONS;

    final Repository db = walk.getRepository();
    final RevCommit root;
    try {
      final AnyObjectId headId = db.resolve(Constants.HEAD);
      if (headId == null) {
        Activator.logError(
            NLS.bind(
                CoreText.GitFileHistory_noHeadRevisionAvailable, resource.getProject().getName()),
            null);
        return NO_REVISIONS;
      }

      root = walk.parseCommit(headId);
      if ((flags & SINGLE_REVISION) == SINGLE_REVISION) {
        // If all Eclipse wants is one revision it probably is
        // for the editor "quick diff" feature. We can pass off
        // just the repository HEAD, even though it may not be
        // the revision that most recently modified the path.
        //
        final CommitFileRevision single;
        single = new CommitFileRevision(db, root, gitPath);
        return new IFileRevision[] {single};
      }

      walk.markStart(root);
    } catch (IOException e) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_invalidHeadRevision, resource.getProject().getName()),
          e);
      return NO_REVISIONS;
    }

    final KidCommitList list = new KidCommitList();
    list.source(walk);
    try {
      for (; ; ) {
        final int oldsz = list.size();
        list.fillTo(oldsz + BATCH_SIZE - 1);
        if (oldsz == list.size()) break;
        if (monitor != null && monitor.isCanceled()) break;
      }
    } catch (IOException e) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_errorParsingHistory, resource.getFullPath()), e);
      return NO_REVISIONS;
    }

    final IFileRevision[] r = new IFileRevision[list.size()];
    for (int i = 0; i < r.length; i++) r[i] = new CommitFileRevision(db, list.get(i), gitPath);
    return r;
  }
  @Override
  @Before
  public void beforeTestCase() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");

    repository1 = new TestRepository(new File(workdir, DOT_GIT));

    repository1.createInitialCommit("setUp");

    Repository repository = repository1.getRepository();
    new InitOperation(repository).execute(null);

    // now we create a project in repo1
    IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
    testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");

    repository1.connect(project);
    repository1.trackAllFiles(project);
    repository1.commit("Initial commit");

    // let's get rid of the project
    project.delete(false, false, null);

    // let's clone repository1 to repository2
    URIish uri = repository1.getUri();
    CloneOperation clop =
        new CloneOperation(uri, true, null, workdir2, R_HEADS + MY_MASTER, DEFAULT_REMOTE_NAME, 0);
    clop.run(null);

    Repository repo2 =
        Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, DOT_GIT));
    repository2 = new TestRepository(repo2);
  }
  /**
   * @param paths
   * @return the calculated commit message
   */
  private String calculateCommitMessage(Collection<String> paths) {
    if (commitMessage != null) {
      // special case for merge
      return commitMessage;
    }

    if (amending) return previousCommitMessage;
    String calculatedCommitMessage = null;

    Set<IResource> resources = new HashSet<IResource>();
    for (String path : paths) {
      IFile file = findFile(path);
      if (file != null) resources.add(file.getProject());
    }
    try {
      ICommitMessageProvider messageProvider = getCommitMessageProvider();
      if (messageProvider != null) {
        IResource[] resourcesArray = resources.toArray(new IResource[0]);
        calculatedCommitMessage = messageProvider.getMessage(resourcesArray);
      }
    } catch (CoreException coreException) {
      Activator.error(coreException.getLocalizedMessage(), coreException);
    }
    if (calculatedCommitMessage != null) return calculatedCommitMessage;
    else return EMPTY_STRING;
  }
Esempio n. 9
0
 /** @param repository */
 public IndexDiffCacheEntry(Repository repository) {
   this.repository = repository;
   indexChangedListenerHandle =
       repository
           .getListenerList()
           .addIndexChangedListener(
               new IndexChangedListener() {
                 public void onIndexChanged(IndexChangedEvent event) {
                   refreshIndexDelta();
                 }
               });
   refsChangedListenerHandle =
       repository
           .getListenerList()
           .addRefsChangedListener(
               new RefsChangedListener() {
                 public void onRefsChanged(RefsChangedEvent event) {
                   scheduleReloadJob("RefsChanged"); // $NON-NLS-1$
                 }
               });
   scheduleReloadJob("IndexDiffCacheEntry construction"); // $NON-NLS-1$
   createResourceChangeListener();
   if (!repository.isBare()) {
     try {
       lastIndex = repository.readDirCache();
     } catch (IOException ex) {
       Activator.error(
           MessageFormat.format(
               CoreText.IndexDiffCacheEntry_errorCalculatingIndexDelta, repository),
           ex);
     }
   }
 }
Esempio n. 10
0
 private void logAndUnmapGoneMappedResource(final RepositoryMapping m) {
   Activator.logError(
       MessageFormat.format(CoreText.GitProjectData_mappedResourceGone, m.toString()),
       new FileNotFoundException(m.getContainerPath().toString()));
   m.clear();
   UnmapJob unmapJob = new UnmapJob(getProject());
   unmapJob.schedule();
 }
Esempio n. 11
0
 /**
  * Create a MergeOperation object
  *
  * @param repository
  * @param refName name of a commit which should be merged
  * @param mergeStrategyName the strategy to use for merge. If not registered, the default merge
  *     strategy according to preferences will be used.
  */
 public MergeOperation(
     @NonNull Repository repository, @NonNull String refName, @NonNull String mergeStrategyName) {
   this.repository = repository;
   this.refName = refName;
   MergeStrategy strategy = null;
   strategy = MergeStrategy.get(mergeStrategyName);
   this.mergeStrategy =
       strategy != null ? strategy : Activator.getDefault().getPreferredMergeStrategy();
 }
Esempio n. 12
0
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      // The core plugin might have been stopped before we could cancel
      // this job.
      RepositoryCache repositoryCache =
          org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
      if (repositoryCache == null) return Status.OK_STATUS;

      Repository[] repos = repositoryCache.getAllRepositories();
      if (repos.length == 0) return Status.OK_STATUS;

      // When people use Git from the command line a lot of changes
      // may happen. Don't scan when inactive depending on the user's
      // choice.

      if (Activator.getDefault()
          .getPreferenceStore()
          .getBoolean(UIPreferences.REFESH_ONLY_WHEN_ACTIVE)) {
        if (!isActive()) {
          monitor.done();
          if (doReschedule) schedule(REPO_SCAN_INTERVAL);
          return Status.OK_STATUS;
        }
      }

      monitor.beginTask(UIText.Activator_scanningRepositories, repos.length);
      try {
        for (Repository repo : repos) {
          if (monitor.isCanceled()) break;
          if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
            GitTraceLocation.getTrace()
                .trace(
                    GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                    "Scanning " + repo + " for changes"); // $NON-NLS-1$ //$NON-NLS-2$

          repo.scanForRepoChanges();
          monitor.worked(1);
        }
      } catch (IOException e) {
        if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
          GitTraceLocation.getTrace()
              .trace(
                  GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                  "Stopped rescheduling " + getName() + "job"); // $NON-NLS-1$ //$NON-NLS-2$
        return createErrorStatus(UIText.Activator_scanError, e);
      } finally {
        monitor.done();
      }
      if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
        GitTraceLocation.getTrace()
            .trace(
                GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                "Rescheduling " + getName() + " job"); // $NON-NLS-1$ //$NON-NLS-2$
      if (doReschedule) schedule(REPO_SCAN_INTERVAL);
      return Status.OK_STATUS;
    }
  @After
  public void tearDown() throws Exception {
    testRepository.dispose();
    testRepositoryClone.dispose();
    testRepository2.dispose();
    Activator.getDefault().getRepositoryCache().clear();

    testProject.dispose();
    testProject2.dispose();
  }
Esempio n. 14
0
  public void execute(IProgressMonitor m) throws CoreException {
    if (mergeResult != null)
      throw new CoreException(
          new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
    IProgressMonitor monitor;
    if (m == null) monitor = new NullProgressMonitor();
    else monitor = m;
    IWorkspaceRunnable action =
        new IWorkspaceRunnable() {

          public void run(IProgressMonitor mymonitor) throws CoreException {
            IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
            mymonitor.beginTask(NLS.bind(CoreText.MergeOperation_ProgressMerge, refName), 3);
            Git git = new Git(repository);
            mymonitor.worked(1);
            MergeCommand merge = git.merge();
            try {
              Ref ref = repository.getRef(refName);
              if (ref != null) merge.include(ref);
              else merge.include(ObjectId.fromString(refName));
            } catch (IOException e) {
              throw new TeamException(CoreText.MergeOperation_InternalError, e);
            }
            if (fastForwardMode != null) merge.setFastForward(fastForwardMode);
            if (commit != null) merge.setCommit(commit.booleanValue());
            if (squash != null) merge.setSquash(squash.booleanValue());
            if (mergeStrategy != null) {
              merge.setStrategy(mergeStrategy);
            }
            if (message != null) merge.setMessage(message);
            try {
              mergeResult = merge.call();
              mymonitor.worked(1);
              if (MergeResult.MergeStatus.NOT_SUPPORTED.equals(mergeResult.getMergeStatus()))
                throw new TeamException(
                    new Status(IStatus.INFO, Activator.getPluginId(), mergeResult.toString()));
            } catch (NoHeadException e) {
              throw new TeamException(CoreText.MergeOperation_MergeFailedNoHead, e);
            } catch (ConcurrentRefUpdateException e) {
              throw new TeamException(CoreText.MergeOperation_MergeFailedRefUpdate, e);
            } catch (CheckoutConflictException e) {
              mergeResult = new MergeResult(e.getConflictingPaths());
              return;
            } catch (GitAPIException e) {
              throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } finally {
              ProjectUtil.refreshValidProjects(validProjects, new SubProgressMonitor(mymonitor, 1));
              mymonitor.done();
            }
          }
        };
    // lock workspace to protect working tree changes
    ResourcesPlugin.getWorkspace()
        .run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
  }
  @Before
  public void setUp() throws Exception {
    Activator.getDefault().getRepositoryCache().clear();

    this.testProject = new TestProject(true);
    this.testRepository = createTestRepository(testProject);

    this.testRepositoryClone = cloneRepository(testRepository);

    this.testProject2 = new TestProject(true);
    this.testRepository2 = createTestRepository(testProject2);
  }
Esempio n. 16
0
 private void notifyListeners() {
   IndexDiffChangedListener[] tmpListeners;
   synchronized (listeners) {
     tmpListeners = listeners.toArray(new IndexDiffChangedListener[listeners.size()]);
   }
   for (int i = 0; i < tmpListeners.length; i++)
     try {
       tmpListeners[i].indexDiffChanged(repository, indexDiffData);
     } catch (RuntimeException e) {
       Activator.logError("Exception occured in an IndexDiffChangedListener", e); // $NON-NLS-1$
     }
 }
Esempio n. 17
0
 private IBranchNameProvider getBranchNameProvider() {
   IExtensionRegistry registry = Platform.getExtensionRegistry();
   IConfigurationElement[] config = registry.getConfigurationElementsFor(BRANCH_NAME_PROVIDER_ID);
   if (config.length > 0) {
     Object provider;
     try {
       provider = config[0].createExecutableExtension("class"); // $NON-NLS-1$
       if (provider instanceof IBranchNameProvider) return (IBranchNameProvider) provider;
     } catch (Throwable e) {
       Activator.logError(UIText.CreateBranchPage_CreateBranchNameProviderFailed, e);
     }
   }
   return null;
 }
Esempio n. 18
0
 /**
  * @param p
  * @return {@link GitProjectData} for the specified project, or null if the Git provider is not
  *     associated with the project or an exception occurred
  */
 @Nullable
 public static synchronized GitProjectData get(final @NonNull IProject p) {
   try {
     GitProjectData d = lookup(p);
     if (d == null && ResourceUtil.isSharedWithGit(p)) {
       d = new GitProjectData(p).load();
       cache(p, d);
     }
     return d;
   } catch (IOException err) {
     Activator.logError(CoreText.GitProjectData_missing, err);
     return null;
   }
 }
 @Override
 protected ResourceTraversal[] getTraversals(ISynchronizationContext context, Object object) {
   if (object instanceof IAdaptable) {
     ResourceMapping rm = getResourceMapping(object);
     GitSubscriberMergeContext ctx = (GitSubscriberMergeContext) getContext();
     ResourceMappingContext rmCtx = new GitSubscriberResourceMappingContext(ctx.getSyncData());
     try {
       return rm.getTraversals(rmCtx, new NullProgressMonitor());
     } catch (CoreException e) {
       Activator.logError(e.getMessage(), e);
     }
   }
   return null;
 }
Esempio n. 20
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   try {
     RepositoryProvider.unmap(project);
     return Status.OK_STATUS;
   } catch (TeamException e) {
     return new Status(
         IStatus.ERROR,
         Activator.getPluginId(),
         MessageFormat.format(
             CoreText.GitProjectData_UnmappingGoneResourceFailed, project.getName()),
         e);
   }
 }
Esempio n. 21
0
  /**
   * Store information about the repository connection in the workspace
   *
   * @throws CoreException
   */
  public void store() throws CoreException {
    final File dat = propertyFile();
    final File tmp;
    boolean ok = false;

    try {
      trace("save " + dat); // $NON-NLS-1$
      tmp =
          File.createTempFile(
              "gpd_", //$NON-NLS-1$
              ".prop", //$NON-NLS-1$
              dat.getParentFile());
      final FileOutputStream o = new FileOutputStream(tmp);
      try {
        final Properties p = new Properties();
        for (final RepositoryMapping repoMapping : mappings) {
          repoMapping.store(p);
        }
        p.store(o, "GitProjectData"); // $NON-NLS-1$
        ok = true;
      } finally {
        o.close();
        if (!ok && tmp.exists()) {
          FileUtils.delete(tmp);
        }
      }
      if (dat.exists()) FileUtils.delete(dat);
      if (!tmp.renameTo(dat)) {
        if (tmp.exists()) FileUtils.delete(tmp);
        throw new CoreException(
            Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), null));
      }
    } catch (IOException ioe) {
      throw new CoreException(
          Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), ioe));
    }
  }
 private ICommitMessageProvider getCommitMessageProvider() throws CoreException {
   IExtensionRegistry registry = Platform.getExtensionRegistry();
   IConfigurationElement[] config =
       registry.getConfigurationElementsFor(COMMIT_MESSAGE_PROVIDER_ID);
   if (config.length > 0) {
     Object provider;
     provider = config[0].createExecutableExtension("class"); // $NON-NLS-1$
     if (provider instanceof ICommitMessageProvider) {
       return (ICommitMessageProvider) provider;
     } else {
       Activator.logError(UIText.CommitDialog_WrongTypeOfCommitMessageProvider, null);
     }
   }
   return null;
 }
Esempio n. 23
0
 private void protect(IResource resource) {
   IResource c = resource;
   while (c != null && !c.equals(getProject())) {
     trace("protect " + c); // $NON-NLS-1$
     protectedResources.add(c);
     try {
       c.setTeamPrivateMember(true);
     } catch (CoreException e) {
       Activator.logError(
           MessageFormat.format(CoreText.GitProjectData_FailedToMarkTeamPrivate, c.getFullPath()),
           e);
     }
     c = c.getParent();
   }
 }
Esempio n. 24
0
  /**
   * @param resource any workbench resource contained within this project.
   * @return the mapping for the specified project
   */
  @Nullable
  public /* TODO static */ RepositoryMapping getRepositoryMapping(@Nullable IResource resource) {
    IResource r = resource;
    try {
      for (; r != null; r = r.getParent()) {
        final RepositoryMapping m;

        if (!r.isAccessible()) continue;
        m = (RepositoryMapping) r.getSessionProperty(MAPPING_KEY);
        if (m != null) return m;
      }
    } catch (CoreException err) {
      Activator.logError(CoreText.GitProjectData_failedFindingRepoMapping, err);
    }
    return null;
  }
Esempio n. 25
0
  private KidWalk buildWalk() {
    final RepositoryMapping rm = RepositoryMapping.getMapping(resource);
    if (rm == null) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_gitNotAttached, resource.getProject().getName()), null);
      return null;
    }

    final KidWalk w = new KidWalk(rm.getRepository());
    gitPath = rm.getRepoRelativePath(resource);
    w.setTreeFilter(
        AndTreeFilter.create(
            PathFilterGroup.createFromStrings(Collections.singleton(gitPath)),
            TreeFilter.ANY_DIFF));
    return w;
  }
Esempio n. 26
0
 @Override
 @SuppressWarnings("synthetic-access")
 public void resourceChanged(final IResourceChangeEvent event) {
   switch (event.getType()) {
     case IResourceChangeEvent.PRE_CLOSE:
       uncache((IProject) event.getResource());
       break;
     case IResourceChangeEvent.PRE_DELETE:
       try {
         delete((IProject) event.getResource());
       } catch (IOException e) {
         Activator.logError(e.getMessage(), e);
       }
       break;
     default:
       break;
   }
 }
  /**
   * Creates project structure inside the base project
   *
   * @throws CoreException
   * @throws IOException
   * @throws WrongRepositoryStateException
   * @throws JGitInternalException
   * @throws ConcurrentRefUpdateException
   * @throws NoMessageException
   * @throws NoHeadException
   * @throws NoFilepatternException
   */
  public void createProjectStructure()
      throws NoFilepatternException, NoHeadException, NoMessageException,
          ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException,
          IOException, CoreException {
    File directory = createLocalGitRepo();

    addContentToGitRepo(directory);

    // Set persistent property so that we know when to show the context
    // menu item.
    project.setPersistentProperty(
        LocalFedoraPackagerPlugin.PROJECT_PROP, "true" /* unused value */); // $NON-NLS-1$

    ConnectProviderOperation connect = new ConnectProviderOperation(project);
    connect.execute(null);

    // Add created repository to the list of Git repositories so that it
    // shows up in the Git repositories view.
    final RepositoryUtil config = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
    config.addConfiguredRepository(repository.getDirectory());
  }
Esempio n. 28
0
  /**
   * Hide our private parts from the navigators other browsers.
   *
   * @throws CoreException
   */
  public void markTeamPrivateResources() throws CoreException {
    for (final Object rmObj : mappings) {
      final RepositoryMapping rm = (RepositoryMapping) rmObj;
      final IContainer c = rm.getContainer();
      if (c == null) continue; // Not fully mapped yet?

      final IResource dotGit = c.findMember(Constants.DOT_GIT);
      if (dotGit != null) {
        try {
          final Repository r = rm.getRepository();
          final File dotGitDir = dotGit.getLocation().toFile().getCanonicalFile();
          if (dotGitDir.equals(r.getDirectory())) {
            trace("teamPrivate " + dotGit); // $NON-NLS-1$
            dotGit.setTeamPrivateMember(true);
          }
        } catch (IOException err) {
          throw new CoreException(Activator.error(CoreText.Error_CanonicalFile, err));
        }
      }
    }
  }
Esempio n. 29
0
  /**
   * Refreshes all resources that changed in the index since the last call to this method. This is
   * suitable for incremental updates on index changed events
   *
   * <p>For bare repositories this does nothing.
   */
  private void refreshIndexDelta() {
    if (repository.isBare()) return;

    try {
      DirCache currentIndex = repository.readDirCache();
      DirCache oldIndex = lastIndex;

      lastIndex = currentIndex;

      if (oldIndex == null) {
        refresh(); // full refresh in case we have no data to compare.
        return;
      }

      Set<String> paths = new TreeSet<String>();
      TreeWalk walk = new TreeWalk(repository);

      try {
        walk.addTree(new DirCacheIterator(oldIndex));
        walk.addTree(new DirCacheIterator(currentIndex));
        walk.setFilter(new InterIndexDiffFilter());

        while (walk.next()) {
          if (walk.isSubtree()) walk.enterSubtree();
          else paths.add(walk.getPathString());
        }
      } finally {
        walk.release();
      }

      if (!paths.isEmpty()) refreshFiles(paths);

    } catch (IOException ex) {
      Activator.error(
          MessageFormat.format(CoreText.IndexDiffCacheEntry_errorCalculatingIndexDelta, repository),
          ex);
      scheduleReloadJob(
          "Exception while calculating index delta, doing full reload instead"); //$NON-NLS-1$
    }
  }
  @After
  public void tearDown() throws Exception {

    Thread.sleep(1000); // FIXME: We need a good way to wait for things to settle

    RepositoryProvider.unmap(project);
    RepositoryProvider.unmap(project2);

    GitProjectData.delete(project);
    GitProjectData.delete(project2);

    project.delete(true, true, null);
    project2.delete(true, true, null);

    repository.close();
    repository2.close();

    org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().clear();

    FileUtils.delete(gitDir, FileUtils.RECURSIVE);
    // gitDir2 is inside project, already gone
  }