Search in sources :

Example 1 with ReflogEntry

use of org.eclipse.jgit.lib.ReflogEntry in project gerrit by GerritCodeReview.

the class GetReflog method apply.

@Override
public List<ReflogEntryInfo> apply(BranchResource rsrc) throws AuthException, ResourceNotFoundException, RepositoryNotFoundException, IOException {
    if (!rsrc.getControl().isOwner()) {
        throw new AuthException("not project owner");
    }
    try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
        ReflogReader r = repo.getReflogReader(rsrc.getRef());
        if (r == null) {
            throw new ResourceNotFoundException(rsrc.getRef());
        }
        List<ReflogEntry> entries;
        if (from == null && to == null) {
            entries = limit > 0 ? r.getReverseEntries(limit) : r.getReverseEntries();
        } else {
            entries = limit > 0 ? new ArrayList<>(limit) : new ArrayList<>();
            for (ReflogEntry e : r.getReverseEntries()) {
                Timestamp timestamp = new Timestamp(e.getWho().getWhen().getTime());
                if ((from == null || from.before(timestamp)) && (to == null || to.after(timestamp))) {
                    entries.add(e);
                }
                if (limit > 0 && entries.size() >= limit) {
                    break;
                }
            }
        }
        return Lists.transform(entries, ReflogEntryInfo::new);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ReflogReader(org.eclipse.jgit.lib.ReflogReader) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Timestamp(java.sql.Timestamp)

Example 2 with ReflogEntry

use of org.eclipse.jgit.lib.ReflogEntry in project egit by eclipse.

the class SwitchToMenu method createDynamicMenu.

private void createDynamicMenu(Menu menu, final Repository repository) {
    MenuItem newBranch = new MenuItem(menu, SWT.PUSH);
    newBranch.setText(UIText.SwitchToMenu_NewBranchMenuLabel);
    newBranch.setImage(newBranchImage);
    newBranch.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String sourceRef = repository.getConfig().getString(ConfigConstants.CONFIG_WORKFLOW_SECTION, null, ConfigConstants.CONFIG_KEY_DEFBRANCHSTARTPOINT);
            CreateBranchWizard wiz = null;
            try {
                Ref ref = null;
                if (sourceRef != null) {
                    ref = repository.findRef(sourceRef);
                }
                if (ref != null) {
                    wiz = new CreateBranchWizard(repository, ref.getName());
                } else {
                    wiz = new CreateBranchWizard(repository, repository.getFullBranch());
                }
            } catch (IOException e1) {
            // Ignore
            }
            if (wiz == null) {
                wiz = new CreateBranchWizard(repository);
            }
            WizardDialog dlg = new WizardDialog(e.display.getActiveShell(), wiz);
            dlg.setHelpAvailable(false);
            dlg.open();
        }
    });
    createSeparator(menu);
    try {
        String currentBranch = repository.getFullBranch();
        Map<String, Ref> localBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS);
        TreeMap<String, Ref> sortedRefs = new TreeMap<>(CommonUtils.STRING_ASCENDING_COMPARATOR);
        // Add the MAX_NUM_MENU_ENTRIES most recently used branches first
        ReflogReader reflogReader = repository.getReflogReader(Constants.HEAD);
        List<ReflogEntry> reflogEntries;
        if (reflogReader == null) {
            reflogEntries = Collections.emptyList();
        } else {
            reflogEntries = reflogReader.getReverseEntries();
        }
        for (ReflogEntry entry : reflogEntries) {
            CheckoutEntry checkout = entry.parseCheckout();
            if (checkout != null) {
                Ref ref = localBranches.get(checkout.getFromBranch());
                if (ref != null)
                    if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES)
                        sortedRefs.put(checkout.getFromBranch(), ref);
                ref = localBranches.get(checkout.getToBranch());
                if (ref != null)
                    if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES)
                        sortedRefs.put(checkout.getToBranch(), ref);
            }
        }
        // Add the recently used branches to the menu, in alphabetical order
        int itemCount = 0;
        for (final Entry<String, Ref> entry : sortedRefs.entrySet()) {
            itemCount++;
            final String shortName = entry.getKey();
            final String fullName = entry.getValue().getName();
            createMenuItem(menu, repository, currentBranch, fullName, shortName);
            // Do not duplicate branch names
            localBranches.remove(shortName);
        }
        if (itemCount < MAX_NUM_MENU_ENTRIES) {
            // local branches
            if (itemCount > 0 && localBranches.size() > 0)
                createSeparator(menu);
            // Now add more other branches if we have only a few branch switches
            // Sort the remaining local branches
            sortedRefs.clear();
            sortedRefs.putAll(localBranches);
            for (final Entry<String, Ref> entry : sortedRefs.entrySet()) {
                itemCount++;
                // protect ourselves against a huge sub-menu
                if (itemCount > MAX_NUM_MENU_ENTRIES)
                    break;
                final String fullName = entry.getValue().getName();
                final String shortName = entry.getKey();
                createMenuItem(menu, repository, currentBranch, fullName, shortName);
            }
        }
        if (itemCount > 0)
            createSeparator(menu);
        MenuItem others = new MenuItem(menu, SWT.PUSH);
        others.setText(UIText.SwitchToMenu_OtherMenuLabel);
        others.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                CheckoutDialog dialog = new CheckoutDialog(e.display.getActiveShell(), repository);
                if (dialog.open() == Window.OK) {
                    BranchOperationUI.checkout(repository, dialog.getRefName()).start();
                }
            }
        });
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
}
Also used : ReflogReader(org.eclipse.jgit.lib.ReflogReader) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CheckoutDialog(org.eclipse.egit.ui.internal.dialogs.CheckoutDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) IOException(java.io.IOException) TreeMap(java.util.TreeMap) CreateBranchWizard(org.eclipse.egit.ui.internal.repository.CreateBranchWizard) Ref(org.eclipse.jgit.lib.Ref) CheckoutEntry(org.eclipse.jgit.lib.CheckoutEntry) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with ReflogEntry

use of org.eclipse.jgit.lib.ReflogEntry in project egit by eclipse.

the class RepositoryUtil method mapCommitToRef.

/**
 * Tries to map a commit to a symbolic reference.
 * <p>
 * This value will be cached for the given commit ID unless refresh is
 * specified. The return value will be the full name, e.g.
 * "refs/remotes/someBranch", "refs/tags/v.1.0"
 * <p>
 * Since this mapping is not unique, the following precedence rules are
 * used:
 * <ul>
 * <li>Tags take precedence over branches</li>
 * <li>Local branches take preference over remote branches</li>
 * <li>Newer references take precedence over older ones where time stamps
 * are available. Use commiter time stamp from commit if no stamp can be
 * found on the tag</li>
 * <li>If there are still ambiguities, the reference name with the highest
 * lexicographic value will be returned</li>
 * </ul>
 *
 * @param repository
 *            the {@link Repository}
 * @param commitId
 *            a commit
 * @param refresh
 *            if true, the cache will be invalidated
 * @return the symbolic reference, or <code>null</code> if no such reference
 *         can be found
 */
public String mapCommitToRef(Repository repository, String commitId, boolean refresh) {
    synchronized (commitMappingCache) {
        if (!ObjectId.isId(commitId)) {
            return null;
        }
        try {
            ReflogReader reflogReader = repository.getReflogReader(Constants.HEAD);
            if (reflogReader != null) {
                List<ReflogEntry> lastEntry = reflogReader.getReverseEntries();
                for (ReflogEntry entry : lastEntry) {
                    if (entry.getNewId().name().equals(commitId)) {
                        CheckoutEntry checkoutEntry = entry.parseCheckout();
                        if (checkoutEntry != null) {
                            Ref ref = repository.findRef(checkoutEntry.getToBranch());
                            if (ref != null) {
                                ObjectId objectId = ref.getObjectId();
                                if (objectId != null && objectId.getName().equals(commitId)) {
                                    return checkoutEntry.getToBranch();
                                }
                                ref = repository.peel(ref);
                            }
                            if (ref != null) {
                                ObjectId id = ref.getPeeledObjectId();
                                if (id != null && id.getName().equals(commitId)) {
                                    return checkoutEntry.getToBranch();
                                }
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
        // ignore here
        }
        Map<String, String> cacheEntry = commitMappingCache.get(repository.getDirectory().toString());
        if (!refresh && cacheEntry != null && cacheEntry.containsKey(commitId)) {
            // this may be null in fact
            return cacheEntry.get(commitId);
        }
        if (cacheEntry == null) {
            cacheEntry = new HashMap<>();
            commitMappingCache.put(repository.getDirectory().getPath(), cacheEntry);
        } else {
            cacheEntry.clear();
        }
        Map<String, Date> tagMap = new HashMap<>();
        try (RevWalk rw = new RevWalk(repository)) {
            Map<String, Ref> tags = repository.getRefDatabase().getRefs(Constants.R_TAGS);
            for (Ref tagRef : tags.values()) {
                RevObject any = rw.parseAny(repository.resolve(tagRef.getName()));
                if (any instanceof RevTag) {
                    RevTag tag = (RevTag) any;
                    if (tag.getObject().name().equals(commitId)) {
                        Date timestamp;
                        if (tag.getTaggerIdent() != null) {
                            timestamp = tag.getTaggerIdent().getWhen();
                        } else {
                            try {
                                RevCommit commit = rw.parseCommit(tag.getObject());
                                timestamp = commit.getCommitterIdent().getWhen();
                            } catch (IncorrectObjectTypeException e) {
                                // not referencing a comit.
                                timestamp = null;
                            }
                        }
                        tagMap.put(tagRef.getName(), timestamp);
                    }
                } else if (any instanceof RevCommit) {
                    RevCommit commit = ((RevCommit) any);
                    if (commit.name().equals(commitId))
                        tagMap.put(tagRef.getName(), commit.getCommitterIdent().getWhen());
                }
            // else ignore here
            }
        } catch (IOException e) {
        // ignore here
        }
        String cacheValue = null;
        if (!tagMap.isEmpty()) {
            // we try to obtain the "latest" tag
            Date compareDate = new Date(0);
            for (Map.Entry<String, Date> tagEntry : tagMap.entrySet()) {
                if (tagEntry.getValue() != null && tagEntry.getValue().after(compareDate)) {
                    compareDate = tagEntry.getValue();
                    cacheValue = tagEntry.getKey();
                }
            }
            // if we don't have time stamps, we sort
            if (cacheValue == null) {
                // $NON-NLS-1$
                String compareString = "";
                for (String tagName : tagMap.keySet()) {
                    if (tagName.compareTo(compareString) >= 0) {
                        cacheValue = tagName;
                        compareString = tagName;
                    }
                }
            }
        }
        if (cacheValue == null) {
            // we didnt't find a tag, so let's look for local branches
            Set<String> branchNames = new TreeSet<>();
            // put this into a sorted set
            try {
                Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS);
                for (Ref branch : remoteBranches.values()) {
                    ObjectId objectId = branch.getObjectId();
                    if (objectId != null && objectId.name().equals(commitId)) {
                        branchNames.add(branch.getName());
                    }
                }
            } catch (IOException e) {
            // ignore here
            }
            if (!branchNames.isEmpty()) {
                // get the last (sorted) entry
                cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1];
            }
        }
        if (cacheValue == null) {
            // last try: remote branches
            Set<String> branchNames = new TreeSet<>();
            // put this into a sorted set
            try {
                Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_REMOTES);
                for (Ref branch : remoteBranches.values()) {
                    ObjectId objectId = branch.getObjectId();
                    if (objectId != null && objectId.name().equals(commitId)) {
                        branchNames.add(branch.getName());
                    }
                }
                if (!branchNames.isEmpty()) {
                    // get the last (sorted) entry
                    cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1];
                }
            } catch (IOException e) {
            // ignore here
            }
        }
        cacheEntry.put(commitId, cacheValue);
        return cacheValue;
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) ReflogReader(org.eclipse.jgit.lib.ReflogReader) ObjectId(org.eclipse.jgit.lib.ObjectId) HashMap(java.util.HashMap) RevObject(org.eclipse.jgit.revwalk.RevObject) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Date(java.util.Date) Ref(org.eclipse.jgit.lib.Ref) CheckoutEntry(org.eclipse.jgit.lib.CheckoutEntry) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) TreeSet(java.util.TreeSet) Map(java.util.Map) HashMap(java.util.HashMap) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with ReflogEntry

use of org.eclipse.jgit.lib.ReflogEntry in project egit by eclipse.

the class ReflogView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    dateFormatter = PreferenceBasedDateFormatter.create();
    GridLayoutFactory.fillDefaults().applyTo(parent);
    toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
        }
    });
    form = toolkit.createForm(parent);
    Image repoImage = UIIcons.REPOSITORY.createImage();
    UIUtils.hookDisposal(form, repoImage);
    Image commitImage = UIIcons.CHANGESET.createImage();
    UIUtils.hookDisposal(form, commitImage);
    form.setImage(repoImage);
    form.setText(UIText.StagingView_NoSelectionTitle);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
    toolkit.decorateFormHeading(form);
    GridLayoutFactory.fillDefaults().applyTo(form.getBody());
    Composite tableComposite = toolkit.createComposite(form.getBody());
    tableComposite.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
    final TreeColumnLayout layout = new TreeColumnLayout();
    FilteredTree filteredTree = new FilteredTree(tableComposite, SWT.NONE | SWT.BORDER | SWT.FULL_SELECTION, new PatternFilter(), true) {

        @Override
        protected void createControl(Composite composite, int treeStyle) {
            super.createControl(composite, treeStyle);
            treeComposite.setLayout(layout);
        }
    };
    toolkit.adapt(filteredTree);
    refLogTableTreeViewer = filteredTree.getViewer();
    refLogTableTreeViewer.getTree().setLinesVisible(true);
    refLogTableTreeViewer.getTree().setHeaderVisible(true);
    refLogTableTreeViewer.setContentProvider(new ReflogViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(refLogTableTreeViewer);
    TreeViewerColumn toColumn = createColumn(layout, UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
    toColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getNewId().abbreviate(7).name();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getNewId().name();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof ReflogEntry) {
                return commitImage;
            }
            return null;
        }
    });
    TreeViewerColumn commitMessageColumn = createColumn(layout, UIText.ReflogView_CommitMessageColumnHeader, 40, SWT.LEFT);
    commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                RevCommit c = getCommit(entry);
                // $NON-NLS-1$
                return c == null ? "" : c.getShortMessage();
            } else if (element instanceof IWorkbenchAdapter) {
                return ((IWorkbenchAdapter) element).getLabel(element);
            }
            return null;
        }

        private RevCommit getCommit(final ReflogEntry entry) {
            try (RevWalk walk = new RevWalk(getRepository())) {
                walk.setRetainBody(true);
                return walk.parseCommit(entry.getNewId());
            } catch (IOException ignored) {
                // ignore
                return null;
            }
        }
    });
    TreeViewerColumn dateColumn = createColumn(layout, UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
    dateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                final PersonIdent who = entry.getWho();
                return dateFormatter.formatDate(who);
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            return null;
        }
    });
    TreeViewerColumn messageColumn = createColumn(layout, UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
    messageColumn.setLabelProvider(new ColumnLabelProvider() {

        private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getComment();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (!(element instanceof ReflogEntry)) {
                return null;
            }
            String comment = ((ReflogEntry) element).getComment();
            if (// $NON-NLS-1$ //$NON-NLS-2$
            comment.startsWith("commit:") || comment.startsWith("commit (initial):"))
                return (Image) resourceManager.get(UIIcons.COMMIT);
            if (// $NON-NLS-1$
            comment.startsWith("commit (amend):"))
                return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
            if (// $NON-NLS-1$
            comment.startsWith("pull"))
                return (Image) resourceManager.get(UIIcons.PULL);
            if (// $NON-NLS-1$
            comment.startsWith("clone"))
                return (Image) resourceManager.get(UIIcons.CLONEGIT);
            if (// $NON-NLS-1$
            comment.startsWith("rebase"))
                return (Image) resourceManager.get(UIIcons.REBASE);
            if (// $NON-NLS-1$
            comment.startsWith("merge"))
                return (Image) resourceManager.get(UIIcons.MERGE);
            if (// $NON-NLS-1$
            comment.startsWith("fetch"))
                return (Image) resourceManager.get(UIIcons.FETCH);
            if (// $NON-NLS-1$
            comment.startsWith("branch"))
                return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
            if (// $NON-NLS-1$
            comment.startsWith("checkout"))
                return (Image) resourceManager.get(UIIcons.CHECKOUT);
            return null;
        }

        @Override
        public void dispose() {
            resourceManager.dispose();
            super.dispose();
        }
    });
    new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {

        @Override
        protected void linkToEditor(ISelection selection) {
        // Not supported
        }

        @Override
        protected void open(ISelection sel, boolean activate) {
            handleOpen(sel, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                if (selection.isEmpty())
                    return;
            Repository repo = getRepository();
            if (repo == null)
                return;
            try (RevWalk walk = new RevWalk(repo)) {
                for (Object element : ((IStructuredSelection) selection).toArray()) {
                    ReflogEntry entry = (ReflogEntry) element;
                    ObjectId id = entry.getNewId();
                    if (id == null || id.equals(ObjectId.zeroId()))
                        id = entry.getOldId();
                    if (id != null && !id.equals(ObjectId.zeroId()))
                        CommitEditor.openQuiet(new RepositoryCommit(repo, walk.parseCommit(id)), activateOnOpen);
                }
            } catch (IOException e) {
                Activator.logError(UIText.ReflogView_ErrorOnOpenCommit, e);
            }
        }
    };
    uiPrefsListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
                dateFormatter = PreferenceBasedDateFormatter.create();
                refLogTableTreeViewer.refresh();
            }
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                if (input instanceof IFileEditorInput)
                    reactOnSelection(new StructuredSelection(((IFileEditorInput) input).getFile()));
            } else
                reactOnSelection(selection);
        }
    };
    IWorkbenchPartSite site = getSite();
    ISelectionService service = CommonUtils.getService(site, ISelectionService.class);
    service.addPostSelectionListener(selectionChangedListener);
    // Use current selection to populate reflog view
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
    site.setSelectionProvider(new RepositorySelectionProvider(refLogTableTreeViewer, () -> getRepository()));
    addRefsChangedListener = Repository.getGlobalListenerList().addRefsChangedListener(this);
    // Toolbar
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    switchRepositoriesAction = new RepositoryToolbarAction(false, () -> getRepository(), repo -> reactOnSelection(new StructuredSelection(repo)));
    toolbar.add(switchRepositoriesAction);
    getViewSite().getActionBars().updateActionBars();
    // register context menu
    MenuManager menuManager = new MenuManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    Tree tree = refLogTableTreeViewer.getTree();
    tree.setMenu(menuManager.createContextMenu(tree));
    MenuManager resetManager = ResetMenu.createMenu(getSite());
    menuManager.add(resetManager);
    getSite().registerContextMenu(POPUP_MENU_ID, menuManager, refLogTableTreeViewer);
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) AdapterUtils(org.eclipse.egit.core.AdapterUtils) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIPreferences(org.eclipse.egit.ui.UIPreferences) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ResourceManager(org.eclipse.jface.resource.ResourceManager) DisposeListener(org.eclipse.swt.events.DisposeListener) IToolBarManager(org.eclipse.jface.action.IToolBarManager) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) RepositoryState(org.eclipse.jgit.lib.RepositoryState) OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) RefsChangedListener(org.eclipse.jgit.events.RefsChangedListener) Separator(org.eclipse.jface.action.Separator) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) Constants(org.eclipse.jgit.lib.Constants) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ResetMenu(org.eclipse.egit.ui.internal.actions.ResetMenu) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) OpenStrategy(org.eclipse.jface.util.OpenStrategy) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Window(org.eclipse.jface.window.Window) UIText(org.eclipse.egit.ui.internal.UIText) ReflogInput(org.eclipse.egit.ui.internal.reflog.ReflogViewContentProvider.ReflogInput) Tree(org.eclipse.swt.widgets.Tree) IFormColors(org.eclipse.ui.forms.IFormColors) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IShowInTarget(org.eclipse.ui.part.IShowInTarget) UIIcons(org.eclipse.egit.ui.internal.UIIcons) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) ViewPart(org.eclipse.ui.part.ViewPart) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) JFaceResources(org.eclipse.jface.resource.JFaceResources) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ShowInContext(org.eclipse.ui.part.ShowInContext) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) ControlContribution(org.eclipse.jface.action.ControlContribution) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) RefsChangedEvent(org.eclipse.jgit.events.RefsChangedEvent) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IOException(java.io.IOException) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) ObjectId(org.eclipse.jgit.lib.ObjectId) Form(org.eclipse.ui.forms.widgets.Form) RowLayout(org.eclipse.swt.layout.RowLayout) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContextService(org.eclipse.ui.contexts.IContextService) IResource(org.eclipse.core.resources.IResource) UIUtils(org.eclipse.egit.ui.UIUtils) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Repository(org.eclipse.jgit.lib.Repository) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DisposeListener(org.eclipse.swt.events.DisposeListener) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IEditorPart(org.eclipse.ui.IEditorPart) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IToolBarManager(org.eclipse.jface.action.IToolBarManager) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) MenuManager(org.eclipse.jface.action.MenuManager) IEditorInput(org.eclipse.ui.IEditorInput) Separator(org.eclipse.jface.action.Separator)

Example 5 with ReflogEntry

use of org.eclipse.jgit.lib.ReflogEntry in project egit by eclipse.

the class AbstractReflogCommandHandler method getSelectedCommit.

/**
 * @param event
 * @param repo
 * @return commit selected in Reflog View
 * @throws ExecutionException
 */
protected RevCommit getSelectedCommit(ExecutionEvent event, Repository repo) throws ExecutionException {
    ReflogEntry entry = (ReflogEntry) ((IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event)).getFirstElement();
    if (entry == null)
        return null;
    RevCommit commit = null;
    try (RevWalk w = new RevWalk(repo)) {
        commit = w.parseCommit(entry.getNewId());
    } catch (IOException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return commit;
}
Also used : ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ExecutionException(org.eclipse.core.commands.ExecutionException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

ReflogEntry (org.eclipse.jgit.lib.ReflogEntry)9 Repository (org.eclipse.jgit.lib.Repository)6 IOException (java.io.IOException)4 ReflogReader (org.eclipse.jgit.lib.ReflogReader)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 Change (com.google.gerrit.entities.Change)3 File (java.io.File)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 Test (org.junit.Test)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 Timestamp (java.sql.Timestamp)1 Instant (java.time.Instant)1 Date (java.util.Date)1