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;
}
};
}
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());
}
});
}
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());
}
});
}
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();
}
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);
}
}
Aggregations