List of usage examples for org.eclipse.jgit.lib ObjectId fromString
public static ObjectId fromString(String str)
From source file:org.webcat.core.git.http.GitWebContext.java
License:Open Source License
public GitWebContext(EOBase originator, GitRepository repository, String repositoryName, GitWebMode mode, String pathSuffix) {// w ww. j av a 2 s . c om this(originator, repository, repositoryName, mode); ObjectId id = null; try { id = ObjectId.fromString(pathSuffix); } catch (Exception e) { int firstSlash = pathSuffix.indexOf('/'); if (firstSlash == -1) { setHeadName(pathSuffix); } else { setHeadName(pathSuffix.substring(0, firstSlash)); path = pathSuffix.substring(firstSlash + 1); } id = repository.resolve(headObjectId.getName() + ":" + path); } objectId = id; }
From source file:org.webcat.core.git.http.GitWebContext.java
License:Open Source License
public static GitWebContext parse(EOBase originator, GitRepository repository, String repositoryName, String path) {/* w w w .ja v a2 s . c om*/ GitWebContext newContext = null; if (path == null || path.length() == 0) { return new GitWebContext(originator, repository, repositoryName, GitWebMode.TREE, Constants.MASTER); } String typeString = null; String remainder = null; int firstSlash = path.indexOf('/'); if (firstSlash == -1) { typeString = path; } else { typeString = path.substring(0, firstSlash); remainder = path.substring(firstSlash + 1); } GitWebMode type = GitWebMode.valueOf(typeString.toUpperCase()); if (type != null) { switch (type) { case TREE: case COMMITS: case BLOB: case RAW: newContext = new GitWebContext(originator, repository, repositoryName, type, remainder); break; case BRANCHES: newContext = new GitWebContext(originator, repository, repositoryName, type); break; case COMMIT: newContext = new GitWebContext(originator, repository, repositoryName, type); newContext.headObjectId = ObjectId.fromString(remainder); break; case COMPARE: // TODO implement break; } } return newContext; }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void isATag_shouldProperlyDetectIfACommitIsATag() throws Exception { // given//from w w w . j a v a 2s . co m String tagName = "v1"; String commitHash = "de4db35917b268089c81c9ab1b52541bb778f5a0"; ObjectId oid = ObjectId.fromString(commitHash); // when boolean isATag = DescribeCommand.hasTags(oid, ImmutableMap.of(oid, singletonList(tagName))); // then assertThat(isATag).isTrue(); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void isATag_shouldProperlyDetectIfACommitIsANotTag() throws Exception { // given//from w w w.ja v a 2s . c o m String tagName = "v1"; String tagHash = "de4db35917b268089c81c9ab1b52541bb778f5a0"; ObjectId tagOid = ObjectId.fromString(tagHash); String commitHash = "de4db35917b268089c81c9ab1b52541bb778f5a0"; ObjectId oid = ObjectId.fromString(commitHash); // when boolean isATag = DescribeCommand.hasTags(oid, ImmutableMap.of(tagOid, singletonList(tagName))); // then assertThat(isATag).isTrue(); }
From source file:svnserver.replay.ReplayTest.java
License:GNU General Public License
@NotNull private RevCommit getCommit(@NotNull Repository git, @NotNull SVNPropertyValue hash) throws IOException { return new RevWalk(git).parseCommit(ObjectId.fromString(new String(hash.getBytes()))); }
From source file:svnserver.repository.git.cache.CacheRevision.java
License:GNU General Public License
private static Kryo createKryo() { final Kryo kryo = new Kryo(); kryo.register(ObjectId.class, new Serializer<ObjectId>() { @Override/* w w w .j a v a 2 s . c om*/ public void write(@NotNull Kryo kryo, @NotNull Output output, @Nullable ObjectId object) { output.writeString(object != null ? object.name() : null); } @Override public ObjectId read(Kryo kryo, Input input, Class<ObjectId> type) { final String id = input.readString(); return id != null ? ObjectId.fromString(id) : null; } }); return kryo; }
From source file:uk.ac.cam.cl.dtg.segue.database.GitDb.java
License:Apache License
/** * Check that a commit sha exists within the git repository. * //from w ww.j a va 2 s.c om * @param sha * - the version that the treewalk should be configured to search within. * @return True if we have found the git sha false if not. */ public boolean verifyCommitExists(final String sha) { if (null == sha) { log.warn("Null version provided. Unable to verify commit exists."); return false; } // we need to check that the local remote is up to date in order to // determine if the commit exists or not. this.fetchLatestFromRemote(); try { Iterable<RevCommit> logs = gitHandle.log().add(ObjectId.fromString(this.getHeadSha())).call(); for (RevCommit rev : logs) { if (rev.getName().equals(sha)) { return true; } } } catch (NoHeadException e) { log.error("Git returned a no head exception. Unable to list all commits."); e.printStackTrace(); } catch (GitAPIException e) { log.error("Git returned an API exception. Unable to list all commits."); e.printStackTrace(); } catch (IOException e) { log.error("Git returned an IO exception. Unable to list all commits."); e.printStackTrace(); } log.debug("Commit " + sha + " does not exist"); return false; }
From source file:uk.ac.cam.cl.dtg.segue.database.GitDb.java
License:Apache License
/** * Get the time of the commit specified. * //from ww w .j a v a 2 s. c o m * @param sha * - to search for. * @return integer value representing time since epoch. * @throws NotFoundException * - if we cannot find the commit requested. */ public synchronized int getCommitTime(final String sha) throws NotFoundException { Validate.notBlank(sha); try { Iterable<RevCommit> logs = gitHandle.log().add(ObjectId.fromString(this.getHeadSha())).call(); for (RevCommit rev : logs) { if (rev.getName().equals(sha)) { return rev.getCommitTime(); } } } catch (NoHeadException e) { log.error("Git returned a no head exception. Unable to list all commits."); e.printStackTrace(); } catch (GitAPIException e) { log.error("Git returned an API exception. Unable to list all commits."); e.printStackTrace(); } catch (IOException e) { log.error("Git returned an IO exception. Unable to list all commits."); e.printStackTrace(); } log.warn("Commit " + sha + " does not exist"); throw new NotFoundException("Commit " + sha + " does not exist"); }
From source file:uk.ac.cam.cl.dtg.segue.database.GitDb.java
License:Apache License
/** * Gets a complete list of commits with the most recent commit first. * /*from w w w .j a v a 2 s.co m*/ * Will return null if there is a problem and will write a log to the configured logger with the stack trace. * * @return List of the commit shas we have found in the git repository. */ public synchronized List<RevCommit> listCommits() { List<RevCommit> logList = null; try { Iterable<RevCommit> logs = gitHandle.log().add(ObjectId.fromString(this.getHeadSha())).call(); logList = new ArrayList<RevCommit>(); for (RevCommit rev : logs) { logList.add(rev); } } catch (GitAPIException e) { log.error("Git returned an API exception. While trying to to list all commits.", e); } catch (IOException e) { log.error("Git returned an IO exception. While trying to to list all commits.", e); } return logList; }