private String getRelativePath(Repository repo) {
   String path = repo.isBare() ? repo.getDirectory().getPath() : repo.getDirectory().getParent();
   if (repo.isBare()) {
     path = repo.getDirectory().getPath();
     if (path.endsWith(".git")) {
       path = path.substring(0, path.length() - 4);
     }
   } else {
     path = repo.getDirectory().getParent();
   }
   return getRelativePath(path);
 }
Esempio n. 2
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);
     }
   }
 }
 private String getRepositoryName(Repository repo) {
   String path = getRelativePath(repo);
   if (repo.isBare() && path.endsWith(".git")) {
     path = path.substring(0, path.length() - 4);
   }
   return path;
 }
Esempio n. 4
0
 public void addRemote(Repository toConfigure, String name, Repository remoteRepo)
     throws IOException {
   final String refSpec = String.format(REF_SPEC_PATTERN, name);
   File dest = remoteRepo.getDirectory();
   if (!remoteRepo.isBare()) {
     dest = dest.getParentFile();
   }
   toConfigure.getConfig().setString("remote", name, "fetch", refSpec);
   toConfigure.getConfig().setString("remote", name, "url", dest.getAbsolutePath());
   // write down configuration in .git/config
   toConfigure.getConfig().save();
 }
Esempio n. 5
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$
    }
  }
Esempio n. 6
0
  @Override
  public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(4, false));

    Label sourceLabel = new Label(main, SWT.NONE);
    sourceLabel.setText(UIText.CreateBranchPage_SourceLabel);
    sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceTooltip);

    sourceIcon = new Label(main, SWT.NONE);
    sourceIcon.setImage(UIIcons.getImage(resourceManager, UIIcons.BRANCH));
    sourceIcon.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    sourceNameLabel = new Label(main, SWT.NONE);
    sourceNameLabel.setLayoutData(
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

    Button selectButton = new Button(main, SWT.NONE);
    selectButton.setText(UIText.CreateBranchPage_SourceSelectButton);
    selectButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            selectSource();
          }
        });
    UIUtils.setButtonLayoutData(selectButton);

    Label nameLabel = new Label(main, SWT.NONE);
    nameLabel.setText(UIText.CreateBranchPage_BranchNameLabel);
    nameLabel.setLayoutData(
        GridDataFactory.fillDefaults().span(1, 1).align(SWT.BEGINNING, SWT.CENTER).create());
    nameLabel.setToolTipText(UIText.CreateBranchPage_BranchNameToolTip);

    nameText = new Text(main, SWT.BORDER);
    // give focus to the nameText if label is activated using the mnemonic
    nameLabel.addTraverseListener(
        new TraverseListener() {
          @Override
          public void keyTraversed(TraverseEvent e) {
            nameText.setFocus();
          }
        });

    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            nameIsSuggestion = false;
          }
        });
    // enable testing with SWTBot
    nameText.setData("org.eclipse.swtbot.widget.key", "BranchName"); // $NON-NLS-1$ //$NON-NLS-2$
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(nameText);

    upstreamConfigComponent = new UpstreamConfigComponent(main, SWT.NONE);
    GridDataFactory.fillDefaults()
        .grab(true, false)
        .span(4, 1)
        .applyTo(upstreamConfigComponent.getContainer());

    upstreamConfigComponent.addUpstreamConfigSelectionListener(
        new UpstreamConfigSelectionListener() {
          @Override
          public void upstreamConfigSelected(UpstreamConfig newUpstreamConfig) {
            upstreamConfig = newUpstreamConfig;
            checkPage();
          }
        });

    boolean isBare = myRepository.isBare();
    checkout = new Button(main, SWT.CHECK);
    checkout.setText(UIText.CreateBranchPage_CheckoutButton);
    // most of the time, we probably will check this out
    // unless we have a bare repository which doesn't allow
    // check out at all
    checkout.setSelection(!isBare);
    checkout.setEnabled(!isBare);
    checkout.setVisible(!isBare);
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(checkout);
    checkout.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            checkPage();
          }
        });

    Dialog.applyDialogFont(main);
    setControl(main);

    if (this.myBaseCommit != null) setSourceCommit(this.myBaseCommit);
    else if (myBaseRef != null) setSourceRef(myBaseRef);

    nameText.setFocus();
    // add the listener just now to avoid unneeded checkPage()
    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            checkPage();
          }
        });
  }