Search in sources :

Example 6 with RevisionInfo

use of com.google.gerrit.client.info.ChangeInfo.RevisionInfo in project gerrit by GerritCodeReview.

the class ChangeScreen method renderDiffBaseListBox.

private void renderDiffBaseListBox(ChangeInfo info) {
    JsArray<RevisionInfo> list = info.revisions().values();
    RevisionInfo.sortRevisionInfoByNumber(list);
    int selectedIdx = list.length();
    for (int i = list.length() - 1; i >= 0; i--) {
        RevisionInfo r = list.get(i);
        diffBase.addItem(r.id() + ": " + r.name().substring(0, 6), r.id());
        if (r.name().equals(revision)) {
            SelectElement.as(diffBase.getElement()).getOptions().getItem(diffBase.getItemCount() - 1).setDisabled(true);
        }
        if (base.isPatchSet() && base.asPatchSetId().get() == r._number()) {
            selectedIdx = diffBase.getItemCount() - 1;
        }
    }
    RevisionInfo rev = info.revisions().get(revision);
    JsArray<CommitInfo> parents = rev.commit().parents();
    if (parents.length() > 1) {
        diffBase.addItem(Util.C.autoMerge(), DiffObject.AUTO_MERGE);
        for (int i = 0; i < parents.length(); i++) {
            int parentNum = i + 1;
            diffBase.addItem(Util.M.diffBaseParent(parentNum), String.valueOf(-parentNum));
        }
        if (base.isParent()) {
            selectedIdx = list.length() + base.getParentNum();
        }
    } else {
        diffBase.addItem(Util.C.baseDiffItem(), "");
    }
    diffBase.setSelectedIndex(selectedIdx);
}
Also used : RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo) CommitInfo(com.google.gerrit.client.info.ChangeInfo.CommitInfo) GerritUiExtensionPoint(com.google.gerrit.client.GerritUiExtensionPoint)

Example 7 with RevisionInfo

use of com.google.gerrit.client.info.ChangeInfo.RevisionInfo in project gerrit by GerritCodeReview.

the class ChangeScreen method resolveRevisionToDisplay.

private RevisionInfo resolveRevisionToDisplay(ChangeInfo info) {
    RevisionInfo rev = resolveRevisionOrPatchSetId(info, revision, info.currentRevision());
    if (rev != null) {
        revision = rev.name();
        return rev;
    }
    // the revision is not visible to the calling user (maybe it is a draft?)
    // or the change is corrupt, take the last revision that was returned,
    // if no revision was returned display an error
    JsArray<RevisionInfo> revisions = info.revisions().values();
    if (revisions.length() > 0) {
        RevisionInfo.sortRevisionInfoByNumber(revisions);
        rev = revisions.get(revisions.length() - 1);
        revision = rev.name();
        return rev;
    }
    new ErrorDialog(Resources.M.changeWithNoRevisions(info.legacyId().get())).center();
    throw new IllegalStateException("no revision, cannot proceed");
}
Also used : RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo) ErrorDialog(com.google.gerrit.client.ErrorDialog)

Example 8 with RevisionInfo

use of com.google.gerrit.client.info.ChangeInfo.RevisionInfo in project gerrit by GerritCodeReview.

the class PatchSetSelectBox method setUpPatchSetNav.

void setUpPatchSetNav(JsArray<RevisionInfo> list, int parents, DiffInfo.FileMeta meta, boolean editExists, boolean current, boolean open, boolean binary) {
    InlineHyperlink selectedLink = null;
    if (sideA) {
        if (parents <= 1) {
            InlineHyperlink link = createLink(PatchUtil.C.patchBase(), DiffObject.base());
            linkPanel.add(link);
            selectedLink = link;
        } else {
            for (int i = parents; i > 0; i--) {
                PatchSet.Id id = new PatchSet.Id(changeId, -i);
                InlineHyperlink link = createLink(Util.M.diffBaseParent(i), DiffObject.patchSet(id));
                linkPanel.add(link);
                if (revision != null && id.equals(revision)) {
                    selectedLink = link;
                }
            }
            InlineHyperlink link = createLink(Util.C.autoMerge(), DiffObject.autoMerge());
            linkPanel.add(link);
            if (selectedLink == null) {
                selectedLink = link;
            }
        }
    }
    for (int i = 0; i < list.length(); i++) {
        RevisionInfo r = list.get(i);
        InlineHyperlink link = createLink(r.id(), DiffObject.patchSet(new PatchSet.Id(changeId, r._number())));
        linkPanel.add(link);
        if (revision != null && r.id().equals(revision.getId())) {
            selectedLink = link;
        }
    }
    if (selectedLink != null) {
        selectedLink.setStyleName(style.selected());
    }
    if (meta == null) {
        return;
    }
    if (!Patch.isMagic(path)) {
        linkPanel.add(createDownloadLink());
    }
    if (!binary && open && !idActive.isBaseOrAutoMerge() && Gerrit.isSignedIn()) {
        if ((editExists && idActive.isEdit()) || (!editExists && current)) {
            linkPanel.add(createEditIcon());
        }
    }
    List<WebLinkInfo> webLinks = Natives.asList(meta.webLinks());
    if (webLinks != null) {
        for (WebLinkInfo webLink : webLinks) {
            linkPanel.add(webLink.toAnchor());
        }
    }
}
Also used : InlineHyperlink(com.google.gerrit.client.ui.InlineHyperlink) RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo) WebLinkInfo(com.google.gerrit.client.info.WebLinkInfo) PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 9 with RevisionInfo

use of com.google.gerrit.client.info.ChangeInfo.RevisionInfo in project gerrit by GerritCodeReview.

the class DiffScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    CallbackGroup group1 = new CallbackGroup();
    final CallbackGroup group2 = new CallbackGroup();
    CodeMirror.initLibrary(group1.add(new AsyncCallback<Void>() {

        final AsyncCallback<Void> themeCallback = group2.addEmpty();

        @Override
        public void onSuccess(Void result) {
            // Load theme after CM library to ensure theme can override CSS.
            ThemeLoader.loadTheme(prefs.theme(), themeCallback);
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    DiffApi.diff(revision, path).base(base.asPatchSetId()).wholeFile().intraline(prefs.intralineDifference()).ignoreWhitespace(prefs.ignoreWhitespace()).get(group1.addFinal(new GerritCallback<DiffInfo>() {

        final AsyncCallback<Void> modeInjectorCb = group2.addEmpty();

        @Override
        public void onSuccess(DiffInfo diffInfo) {
            diff = diffInfo;
            fileSize = bucketFileSize(diffInfo);
            if (prefs.syntaxHighlighting()) {
                if (fileSize.compareTo(FileSize.SMALL) > 0) {
                    modeInjectorCb.onSuccess(null);
                } else {
                    injectMode(diffInfo, modeInjectorCb);
                }
            } else {
                modeInjectorCb.onSuccess(null);
            }
        }
    }));
    if (Gerrit.isSignedIn()) {
        ChangeApi.edit(changeId.get(), group2.add(new AsyncCallback<EditInfo>() {

            @Override
            public void onSuccess(EditInfo result) {
                edit = result;
            }

            @Override
            public void onFailure(Throwable caught) {
            }
        }));
    }
    final CommentsCollections comments = new CommentsCollections(base, revision, path);
    comments.load(group2);
    countParents(group2);
    RestApi call = ChangeApi.detail(changeId.get());
    ChangeList.addOptions(call, EnumSet.of(ListChangesOption.ALL_REVISIONS));
    call.get(group2.add(new AsyncCallback<ChangeInfo>() {

        @Override
        public void onSuccess(ChangeInfo info) {
            changeStatus = info.status();
            info.revisions().copyKeysIntoChildren("name");
            if (edit != null) {
                edit.setName(edit.commit().commit());
                info.setEdit(edit);
                info.revisions().put(edit.name(), RevisionInfo.fromEdit(edit));
            }
            String currentRevision = info.currentRevision();
            boolean current = currentRevision != null && revision.get() == info.revision(currentRevision)._number();
            JsArray<RevisionInfo> list = info.revisions().values();
            RevisionInfo.sortRevisionInfoByNumber(list);
            getDiffTable().set(prefs, list, parents, diff, edit != null, current, changeStatus.isOpen(), diff.binary());
            header.setChangeInfo(info);
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    ConfigInfoCache.get(changeId, group2.addFinal(getScreenLoadCallback(comments)));
}
Also used : RestApi(com.google.gerrit.client.rpc.RestApi) ChangeInfo(com.google.gerrit.client.info.ChangeInfo) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) EditInfo(com.google.gerrit.client.info.ChangeInfo.EditInfo) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo)

Example 10 with RevisionInfo

use of com.google.gerrit.client.info.ChangeInfo.RevisionInfo in project gerrit by GerritCodeReview.

the class ChangeScreen method initEditMode.

private void initEditMode(ChangeInfo info, String revision) {
    if (Gerrit.isSignedIn()) {
        RevisionInfo rev = info.revision(revision);
        if (info.status().isOpen()) {
            if (isEditModeEnabled(info, rev)) {
                editMode.setVisible(fileTableMode == FileTable.Mode.REVIEW);
                addFile.setVisible(!editMode.isVisible());
                deleteFile.setVisible(!editMode.isVisible());
                renameFile.setVisible(!editMode.isVisible());
                reviewMode.setVisible(!editMode.isVisible());
                addFileAction = new AddFileAction(changeId, info.revision(revision), style, addFile, files);
                deleteFileAction = new DeleteFileAction(changeId, info.revision(revision), style, addFile);
                renameFileAction = new RenameFileAction(changeId, info.revision(revision), style, addFile);
            } else {
                editMode.setVisible(false);
                addFile.setVisible(false);
                reviewMode.setVisible(false);
            }
            if (rev.isEdit()) {
                if (info.hasEditBasedOnCurrentPatchSet()) {
                    publishEdit.setVisible(true);
                } else {
                    rebaseEdit.setVisible(true);
                }
                deleteEdit.setVisible(true);
            }
        } else if (rev.isEdit()) {
            deleteEdit.setStyleName(style.highlight());
            deleteEdit.setVisible(true);
        }
    }
}
Also used : RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo)

Aggregations

RevisionInfo (com.google.gerrit.client.info.ChangeInfo.RevisionInfo)14 GerritUiExtensionPoint (com.google.gerrit.client.GerritUiExtensionPoint)3 ActionInfo (com.google.gerrit.client.info.ActionInfo)3 CommitInfo (com.google.gerrit.client.info.ChangeInfo.CommitInfo)3 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)3 ChangeInfo (com.google.gerrit.client.info.ChangeInfo)2 EditInfo (com.google.gerrit.client.info.ChangeInfo.EditInfo)2 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 SafeHtmlBuilder (com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)2 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 NotFoundScreen (com.google.gerrit.client.NotFoundScreen)1 ActionButton (com.google.gerrit.client.actions.ActionButton)1 ChangeList (com.google.gerrit.client.changes.ChangeList)1 CommentInfo (com.google.gerrit.client.changes.CommentInfo)1 WebLinkInfo (com.google.gerrit.client.info.WebLinkInfo)1 NativeMap (com.google.gerrit.client.rpc.NativeMap)1 RestApi (com.google.gerrit.client.rpc.RestApi)1 InlineHyperlink (com.google.gerrit.client.ui.InlineHyperlink)1 Status (com.google.gerrit.reviewdb.client.Change.Status)1