Search in sources :

Example 1 with RevisionSyntaxException

use of org.eclipse.jgit.errors.RevisionSyntaxException in project egit by eclipse.

the class ValidationUtils method getRefNameInputValidator.

/**
 * Creates and returns input validator for refNames
 *
 * @param repo
 * @param refPrefix
 * @param errorOnEmptyName
 * @return input validator for refNames
 */
public static IInputValidator getRefNameInputValidator(final Repository repo, final String refPrefix, final boolean errorOnEmptyName) {
    return new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.length() == 0) {
                if (errorOnEmptyName)
                    return UIText.ValidationUtils_PleaseEnterNameMessage;
                else
                    // ignore this
                    return null;
            }
            String testFor = refPrefix + newText;
            if (!Repository.isValidRefName(testFor))
                return NLS.bind(UIText.ValidationUtils_InvalidRefNameMessage, testFor);
            try {
                if (repo.resolve(testFor) != null)
                    return NLS.bind(UIText.ValidationUtils_RefAlreadyExistsMessage, testFor);
                RefDatabase refDatabase = repo.getRefDatabase();
                Collection<String> conflictingNames = refDatabase.getConflictingNames(testFor);
                if (!conflictingNames.isEmpty()) {
                    ArrayList<String> names = new ArrayList<>(conflictingNames);
                    Collections.sort(names);
                    // $NON-NLS-1$
                    String joined = StringUtils.join(names, ", ");
                    return NLS.bind(UIText.ValidationUtils_RefNameConflictsWithExistingMessage, joined);
                }
            } catch (IOException e) {
                Activator.logError(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, testFor), e);
                return e.getMessage();
            } catch (RevisionSyntaxException e) {
                String m = MessageFormat.format(UIText.ValidationUtils_InvalidRevision, testFor);
                Activator.logError(m, e);
                return m;
            }
            return null;
        }
    };
}
Also used : RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RefDatabase(org.eclipse.jgit.lib.RefDatabase) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 2 with RevisionSyntaxException

use of org.eclipse.jgit.errors.RevisionSyntaxException in project indy by Commonjava.

the class GitManager method getHeadCommit.

public ChangeSummary getHeadCommit(final File f) throws GitSubsystemException {
    return lockAnd(me -> {
        try {
            final ObjectId oid = repo.resolve("HEAD");
            final PlotWalk pw = new PlotWalk(repo);
            final RevCommit rc = pw.parseCommit(oid);
            pw.markStart(rc);
            final String filepath = relativize(f);
            pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));
            final PlotCommitList<PlotLane> cl = new PlotCommitList<>();
            cl.source(pw);
            cl.fillTo(1);
            final PlotCommit<PlotLane> commit = cl.get(0);
            return toChangeSummary(commit);
        } catch (RevisionSyntaxException | IOException e) {
            throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage());
        }
    });
}
Also used : PlotLane(org.eclipse.jgit.revplot.PlotLane) ObjectId(org.eclipse.jgit.lib.ObjectId) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) PlotCommitList(org.eclipse.jgit.revplot.PlotCommitList) IOException(java.io.IOException) PlotWalk(org.eclipse.jgit.revplot.PlotWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with RevisionSyntaxException

use of org.eclipse.jgit.errors.RevisionSyntaxException in project indy by Commonjava.

the class GitManager method getChangelog.

public List<ChangeSummary> getChangelog(final File f, final int start, final int length) throws GitSubsystemException {
    return lockAnd(me -> {
        if (length == 0) {
            return Collections.emptyList();
        }
        try {
            final ObjectId oid = repo.resolve(Constants.HEAD);
            final PlotWalk pw = new PlotWalk(repo);
            final RevCommit rc = pw.parseCommit(oid);
            toChangeSummary(rc);
            pw.markStart(rc);
            final String filepath = relativize(f);
            logger.info("Getting changelog for: {} (start: {}, length: {})", filepath, start, length);
            if (!isEmpty(filepath) && !filepath.equals("/")) {
                pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));
            } else {
                pw.setTreeFilter(TreeFilter.ANY_DIFF);
            }
            final List<ChangeSummary> changelogs = new ArrayList<ChangeSummary>();
            int count = 0;
            final int stop = length > 0 ? length + 1 : 0;
            RevCommit commit = null;
            while ((commit = pw.next()) != null && (stop < 1 || count < stop)) {
                if (count < start) {
                    count++;
                    continue;
                }
                // printFiles( commit );
                changelogs.add(toChangeSummary(commit));
                count++;
            }
            if (length < -1) {
                final int remove = (-1 * length) - 1;
                for (int i = 0; i < remove; i++) {
                    changelogs.remove(changelogs.size() - 1);
                }
            }
            return changelogs;
        } catch (RevisionSyntaxException | IOException e) {
            throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f, e.getMessage());
        }
    });
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) ArrayList(java.util.ArrayList) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) PlotWalk(org.eclipse.jgit.revplot.PlotWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with RevisionSyntaxException

use of org.eclipse.jgit.errors.RevisionSyntaxException in project egit by eclipse.

the class CreateTagDialog method setExistingTagFromText.

private void setExistingTagFromText(String tagName) {
    try {
        ObjectId tagObjectId = repo.resolve(Constants.R_TAGS + tagName);
        if (tagObjectId != null) {
            try (RevWalk revWalk = new RevWalk(repo)) {
                RevObject tagObject = revWalk.parseAny(tagObjectId);
                setExistingTag(tagObject);
            }
            return;
        }
    } catch (IOException e) {
    // ignore
    } catch (RevisionSyntaxException e) {
    // ignore
    }
    setNoExistingTag();
}
Also used : AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 5 with RevisionSyntaxException

use of org.eclipse.jgit.errors.RevisionSyntaxException in project egit by eclipse.

the class CommitSelectionDialog method fillContentProvider.

@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    String pattern = itemsFilter.getPattern();
    Repository[] repositories = getRepositories();
    SubMonitor progress = SubMonitor.convert(progressMonitor, repositories.length);
    progress.setTaskName(UIText.CommitSelectionDialog_TaskSearching);
    for (Repository repository : repositories) {
        try {
            ObjectId commitId;
            if (ObjectId.isId(pattern))
                commitId = ObjectId.fromString(pattern);
            else
                commitId = repository.resolve(itemsFilter.getPattern());
            if (commitId != null) {
                try (RevWalk walk = new RevWalk(repository)) {
                    walk.setRetainBody(true);
                    RevCommit commit = walk.parseCommit(commitId);
                    contentProvider.add(new RepositoryCommit(repository, commit), itemsFilter);
                }
            }
        } catch (RevisionSyntaxException ignored) {
        // Ignore and advance
        } catch (IOException ignored) {
        // Ignore and advance
        }
        progress.worked(1);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) SubMonitor(org.eclipse.core.runtime.SubMonitor) StyledString(org.eclipse.jface.viewers.StyledString) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

IOException (java.io.IOException)6 RevisionSyntaxException (org.eclipse.jgit.errors.RevisionSyntaxException)6 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 ArrayList (java.util.ArrayList)2 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)2 PlotWalk (org.eclipse.jgit.revplot.PlotWalk)2 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Nullable (org.eclipse.jgit.annotations.Nullable)1 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)1 RefDatabase (org.eclipse.jgit.lib.RefDatabase)1 Repository (org.eclipse.jgit.lib.Repository)1 PlotCommitList (org.eclipse.jgit.revplot.PlotCommitList)1 PlotLane (org.eclipse.jgit.revplot.PlotLane)1 RevObject (org.eclipse.jgit.revwalk.RevObject)1