Search in sources :

Example 1 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class ImportChangedProjectsCommand method determineChangedFilesOfCommit.

private Set<File> determineChangedFilesOfCommit(RepositoryCommit repoCommit) {
    Set<File> changedFilesOfCommit = new HashSet<>();
    File rootOfWorkingDirectory = repoCommit.getRepository().getWorkTree();
    FileDiff[] fileDiffs = repoCommit.getDiffs();
    for (FileDiff fileDiff : fileDiffs) {
        // in case of brand new files there is no old path
        addIfNotDevNull(changedFilesOfCommit, rootOfWorkingDirectory, fileDiff.getNewPath());
        // in case of deletions there is no new path
        addIfNotDevNull(changedFilesOfCommit, rootOfWorkingDirectory, fileDiff.getOldPath());
    }
    return changedFilesOfCommit;
}
Also used : FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class CommitEditorPage method loadSections.

void loadSections() {
    Job refreshJob = new CommitEditorPageJob(getCommit()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final List<Ref> tags = loadTags();
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final List<Ref> branches = loadBranches();
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final FileDiff[] diffs = getCommit().getDiffs();
            updateUI(monitor, () -> {
                fillTags(getManagedForm().getToolkit(), tags);
                fillDiffs(diffs);
                fillBranches(branches);
            });
            return Status.OK_STATUS;
        }
    };
    refreshJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Ref(org.eclipse.jgit.lib.Ref) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class BlameInformationControl method createDiffLinkAndText.

private void createDiffLinkAndText(final RevCommit parent, final Diff diff) throws IOException {
    String parentId = parent.toObjectId().abbreviate(7).name();
    String parentMessage = parent.getShortMessage();
    EditList interestingDiff = getInterestingDiff(diff.getEditList());
    final Integer parentLine;
    if (!interestingDiff.isEmpty())
        parentLine = Integer.valueOf(interestingDiff.get(0).getBeginA());
    else
        parentLine = null;
    Composite header = new Composite(diffComposite, SWT.NONE);
    header.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    Label diffHeaderLabel = new Label(header, SWT.NONE);
    diffHeaderLabel.setText(NLS.bind(UIText.BlameInformationControl_DiffHeaderLabel, parentId, parentMessage));
    showAnnotationsLink = new Link(header, SWT.NONE);
    showAnnotationsLink.setText(UIText.BlameInformationControl_ShowAnnotationsLink);
    showAnnotationsLinkSelectionAdapter = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            blameParent(parent, diff, parentLine);
        }
    };
    showAnnotationsLink.addSelectionListener(showAnnotationsLinkSelectionAdapter);
    DiffViewer diffText = new DiffViewer(diffComposite, null, SWT.NONE);
    diffText.configure(new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
    diffText.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    DiffDocument document = new DiffDocument();
    try (DiffRegionFormatter diffFormatter = new DiffRegionFormatter(document)) {
        diffFormatter.setContext(1);
        diffFormatter.setRepository(revision.getRepository());
        diffFormatter.format(interestingDiff, diff.getOldText(), diff.getNewText());
        try (ObjectReader reader = revision.getRepository().newObjectReader()) {
            DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(revision.getRepository(), revision.getSourcePath(), revision.getCommit(), parent, reader);
            if (diffEntry != null) {
                FileDiff fileDiff = new FileDiff(revision.getCommit(), diffEntry);
                document.setDefault(revision.getRepository(), fileDiff);
            }
        }
        document.connect(diffFormatter);
    }
    diffText.setDocument(document);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) DiffRegionFormatter(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ObjectReader(org.eclipse.jgit.lib.ObjectReader) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) EditList(org.eclipse.jgit.diff.EditList) DiffDocument(org.eclipse.egit.ui.internal.commit.DiffDocument) Link(org.eclipse.swt.widgets.Link) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 4 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class StashEditorPage method getUnstagedDiffs.

/**
 * @return diffs for unstaged and untracked changes
 */
protected FileDiff[] getUnstagedDiffs() {
    List<FileDiff> unstagedDiffs = new ArrayList<>();
    RevCommit stagedCommit = getCommit().getRevCommit().getParent(PARENT_COMMIT_STAGED);
    List<FileDiff> workingDirDiffs = asList(getCommit().getDiffs(stagedCommit));
    unstagedDiffs.addAll(workingDirDiffs);
    if (getCommit().getRevCommit().getParentCount() > 2) {
        RevCommit untrackedCommit = getCommit().getRevCommit().getParent(PARENT_COMMIT_UNTRACKED);
        FileDiff[] untrackedDiffs = new RepositoryCommit(getCommit().getRepository(), untrackedCommit).getDiffs();
        unstagedDiffs.addAll(asList(untrackedDiffs));
    }
    return unstagedDiffs.toArray(new FileDiff[unstagedDiffs.size()]);
}
Also used : ArrayList(java.util.ArrayList) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class StashEditorPage method loadSections.

@Override
void loadSections() {
    RepositoryCommit commit = getCommit();
    Job refreshJob = new Job(MessageFormat.format(UIText.CommitEditorPage_JobName, commit.getRevCommit().name())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final FileDiff[] unstagedDiffs = getUnstagedDiffs();
            final FileDiff[] indexDiffs = getStagedDiffs();
            final ScrolledForm form = getManagedForm().getForm();
            if (UIUtils.isUsable(form))
                form.getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!UIUtils.isUsable(form))
                            return;
                        fillDiffs(unstagedDiffs);
                        fillStagedDiffs(indexDiffs);
                        form.reflow(true);
                        form.layout(true, true);
                    }
                });
            return Status.OK_STATUS;
        }
    };
    refreshJob.setRule(this);
    refreshJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

FileDiff (org.eclipse.egit.ui.internal.history.FileDiff)12 ArrayList (java.util.ArrayList)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 IOException (java.io.IOException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 File (java.io.File)2 DiffEntry (org.eclipse.jgit.diff.DiffEntry)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1