if (buildByBranchName.getValue().getSHA1().equals(ObjectId.fromString(scmRevisionHash))) { addGitLabBranchBuild(result, scmRevisionHash, buildData.getRemoteUrls(), environment, gitLabClient);
private void parseShallow(String idStr) throws PackProtocolException { ObjectId id; try { id = ObjectId.fromString(idStr); } catch (InvalidObjectIdException e) { throw new PackProtocolException(e.getMessage(), e); } clientShallowCommits.add(id); }
private static RevCommit buildRevCommit(Repository repository, String commit) throws IOException { // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk revWalk = new RevWalk(repository)) { return revWalk.parseCommit(ObjectId.fromString(commit)); } }
private static RevCommit buildRevCommit(Repository repository, String commit) throws IOException { // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk revWalk = new RevWalk(repository)) { return revWalk.parseCommit(ObjectId.fromString(commit)); } }
private void readBundleV2() throws IOException { final byte[] hdrbuf = new byte[1024]; final LinkedHashMap<String, Ref> avail = new LinkedHashMap<>(); for (;;) { String line = readLine(hdrbuf); if (line.length() == 0) break; if (line.charAt(0) == '-') { ObjectId id = ObjectId.fromString(line.substring(1, 41)); String shortDesc = null; if (line.length() > 42) shortDesc = line.substring(42); prereqs.put(id, shortDesc); continue; } final String name = line.substring(41, line.length()); final ObjectId id = ObjectId.fromString(line.substring(0, 40)); final Ref prior = avail.put(name, new ObjectIdRef.Unpeeled( Ref.Storage.NETWORK, name, id)); if (prior != null) throw duplicateAdvertisement(name); } available(avail); }
@Override Set<ObjectId> getShallowCommits() throws IOException { if (shallowFile == null || !shallowFile.isFile()) return Collections.emptySet(); if (shallowFileSnapshot == null || shallowFileSnapshot.isModified(shallowFile)) { shallowCommitsIds = new HashSet<>(); try (BufferedReader reader = open(shallowFile)) { String line; while ((line = reader.readLine()) != null) { try { shallowCommitsIds.add(ObjectId.fromString(line)); } catch (IllegalArgumentException ex) { throw new IOException(MessageFormat .format(JGitText.get().badShallowLine, line)); } } } shallowFileSnapshot = FileSnapshot.save(shallowFile); } return shallowCommitsIds; }
private ObjectIdOwnerMap<UnpackedObjectId> scanLoose() { ObjectIdOwnerMap<UnpackedObjectId> m = new ObjectIdOwnerMap<>(); File objects = wrapped.getDirectory(); String[] fanout = objects.list(); if (fanout == null) return m; for (String d : fanout) { if (d.length() != 2) continue; String[] entries = new File(objects, d).list(); if (entries == null) continue; for (String e : entries) { if (e.length() != Constants.OBJECT_ID_STRING_LENGTH - 2) continue; try { ObjectId id = ObjectId.fromString(d + e); m.add(new UnpackedObjectId(id)); } catch (IllegalArgumentException notAnObject) { // ignoring the file that does not represent loose object } } } return m; }
ReflogEntryImpl(byte[] raw, int pos) { oldId = ObjectId.fromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') throw new IllegalArgumentException( JGitText.get().rawLogMessageDoesNotParseAsLogEntry); newId = ObjectId.fromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new IllegalArgumentException( JGitText.get().rawLogMessageDoesNotParseAsLogEntry); } who = RawParseUtils.parsePersonIdentOnly(raw, pos); int p0 = RawParseUtils.next(raw, pos, '\t'); if (p0 >= raw.length) comment = ""; // personident has no \t, no comment present //$NON-NLS-1$ else { int p1 = RawParseUtils.nextLF(raw, p0); comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : ""; //$NON-NLS-1$ } }
if (last == null) throw new TransportException(JGitText.get().peeledLineBeforeRef); final ObjectId id = ObjectId.fromString(line.substring(1)); last = new ObjectIdRef.PeeledTag(Ref.Storage.PACKED, last .getName(), last.getObjectId(), id); if (sp < 0) throw new TransportException(MessageFormat.format(JGitText.get().unrecognizedRef, line)); final ObjectId id = ObjectId.fromString(line.substring(0, sp)); final String name = line.substring(sp + 1); if (peeled)
static ReceiveCommand parseCommand(String line) throws PackProtocolException { if (line == null || line.length() < 83) { throw new PackProtocolException( JGitText.get().errorInvalidProtocolWantedOldNewRef); } String oldStr = line.substring(0, 40); String newStr = line.substring(41, 81); ObjectId oldId, newId; try { oldId = ObjectId.fromString(oldStr); newId = ObjectId.fromString(newStr); } catch (InvalidObjectIdException e) { throw new PackProtocolException( JGitText.get().errorInvalidProtocolWantedOldNewRef, e); } String name = line.substring(82); if (!Repository.isValidRefName(name)) { throw new PackProtocolException( JGitText.get().errorInvalidProtocolWantedOldNewRef); } return new ReceiveCommand(oldId, newId, name); }
id = ObjectId.fromString(line.substring(0, tab)); if (name.endsWith("^{}")) { //$NON-NLS-1$ name = name.substring(0, name.length() - 3);
private List<RevCommit> getNewParents(RevCommit commitToPick) throws IOException { List<RevCommit> newParents = new ArrayList<>(); for (int p = 0; p < commitToPick.getParentCount(); p++) { String parentHash = commitToPick.getParent(p).getName(); if (!new File(rebaseState.getRewrittenDir(), parentHash).exists()) newParents.add(commitToPick.getParent(p)); else { String newParent = RebaseState.readFile( rebaseState.getRewrittenDir(), parentHash); if (newParent.length() == 0) newParents.add(walk.parseCommit(repo .resolve(Constants.HEAD))); else newParents.add(walk.parseCommit(ObjectId .fromString(newParent))); } } return newParents; }
private void expandSingle(RefSpec spec, Set<Ref> matched) throws TransportException { String want = spec.getSource(); if (ObjectId.isId(want)) { want(ObjectId.fromString(want)); return; } Ref src = conn.getRef(want); if (src == null) { throw new TransportException(MessageFormat.format(JGitText.get().remoteDoesNotHaveSpec, want)); } if (matched.add(src)) { want(src, spec); } }
/** * Return the information stored in the file $GIT_DIR/MERGE_HEAD. In this * file operations triggering a merge will store the IDs of all heads which * should be merged together with HEAD. * * @return a list of commits which IDs are listed in the MERGE_HEAD file or * {@code null} if this file doesn't exist. Also if the file exists * but is empty {@code null} will be returned * @throws java.io.IOException * @throws org.eclipse.jgit.errors.NoWorkTreeException * if this is bare, which implies it has no working directory. * See {@link #isBare()}. */ @Nullable public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException { if (isBare() || getDirectory() == null) throw new NoWorkTreeException(); byte[] raw = readGitDirectoryFile(Constants.MERGE_HEAD); if (raw == null) return null; LinkedList<ObjectId> heads = new LinkedList<>(); for (int p = 0; p < raw.length;) { heads.add(ObjectId.fromString(raw, p)); p = RawParseUtils .nextLF(raw, p + Constants.OBJECT_ID_STRING_LENGTH); } return heads; }
@Nullable private ObjectId resolveSimple(String revstr) throws IOException { if (ObjectId.isId(revstr)) return ObjectId.fromString(revstr); if (Repository.isValidRefName("x/" + revstr)) { //$NON-NLS-1$ Ref r = getRefDatabase().getRef(revstr); if (r != null) return r.getObjectId(); } if (AbbreviatedObjectId.isId(revstr)) return resolveAbbreviation(revstr); int dashg = revstr.indexOf("-g"); //$NON-NLS-1$ if ((dashg + 5) < revstr.length() && 0 <= dashg && isHex(revstr.charAt(dashg + 2)) && isHex(revstr.charAt(dashg + 3)) && isAllHex(revstr, dashg + 4)) { // Possibly output from git describe? String s = revstr.substring(dashg + 2); if (AbbreviatedObjectId.isId(s)) return resolveAbbreviation(s); } return null; }
/** * Return the information stored in the file $GIT_DIR/ORIG_HEAD. * * @return object id from ORIG_HEAD file or {@code null} if this file * doesn't exist. Also if the file exists but is empty {@code null} * will be returned * @throws java.io.IOException * @throws org.eclipse.jgit.errors.NoWorkTreeException * if this is bare, which implies it has no working directory. * See {@link #isBare()}. */ @Nullable public ObjectId readOrigHead() throws IOException, NoWorkTreeException { if (isBare() || getDirectory() == null) throw new NoWorkTreeException(); byte[] raw = readGitDirectoryFile(Constants.ORIG_HEAD); return raw != null ? ObjectId.fromString(raw, 0) : null; }
/** * Return the information stored in the file $GIT_DIR/REVERT_HEAD. * * @return object id from REVERT_HEAD file or {@code null} if this file * doesn't exist. Also if the file exists but is empty {@code null} * will be returned * @throws java.io.IOException * @throws org.eclipse.jgit.errors.NoWorkTreeException * if this is bare, which implies it has no working directory. * See {@link #isBare()}. */ @Nullable public ObjectId readRevertHead() throws IOException, NoWorkTreeException { if (isBare() || getDirectory() == null) throw new NoWorkTreeException(); byte[] raw = readGitDirectoryFile(Constants.REVERT_HEAD); if (raw == null) return null; return ObjectId.fromString(raw, 0); }
/** * Return the information stored in the file $GIT_DIR/CHERRY_PICK_HEAD. * * @return object id from CHERRY_PICK_HEAD file or {@code null} if this file * doesn't exist. Also if the file exists but is empty {@code null} * will be returned * @throws java.io.IOException * @throws org.eclipse.jgit.errors.NoWorkTreeException * if this is bare, which implies it has no working directory. * See {@link #isBare()}. */ @Nullable public ObjectId readCherryPickHead() throws IOException, NoWorkTreeException { if (isBare() || getDirectory() == null) throw new NoWorkTreeException(); byte[] raw = readGitDirectoryFile(Constants.CHERRY_PICK_HEAD); if (raw == null) return null; return ObjectId.fromString(raw, 0); }
private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException { // from the commit we can build the tree which allows us to construct the TreeParser //noinspection Duplicates try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(ObjectId.fromString(objectId)); RevTree tree = walk.parseTree(commit.getTree().getId()); CanonicalTreeParser treeParser = new CanonicalTreeParser(); try (ObjectReader reader = repository.newObjectReader()) { treeParser.reset(reader, tree.getId()); } walk.dispose(); return treeParser; } } }
private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException { // from the commit we can build the tree which allows us to construct the TreeParser //noinspection Duplicates try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(ObjectId.fromString(objectId)); RevTree tree = walk.parseTree(commit.getTree().getId()); CanonicalTreeParser treeParser = new CanonicalTreeParser(); try (ObjectReader reader = repository.newObjectReader()) { treeParser.reset(reader, tree.getId()); } walk.dispose(); return treeParser; } } }