/** * Remove all entries from a map which key is the id of an object referenced * by the given ObjectWalk * * @param id2File * @param w * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws IOException */ private void removeReferenced(Map<ObjectId, File> id2File, ObjectWalk w) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevObject ro = w.next(); while (ro != null) { checkCancelled(); if (id2File.remove(ro.getId()) != null && id2File.isEmpty()) { return; } ro = w.next(); } ro = w.nextObject(); while (ro != null) { checkCancelled(); if (id2File.remove(ro.getId()) != null && id2File.isEmpty()) { return; } ro = w.nextObject(); } }
/** {@inheritDoc} */ @Override public String toString() { final StringBuilder s = new StringBuilder(); s.append(Constants.typeString(getType())); s.append(' '); s.append(name()); s.append(' '); appendCoreFlags(s); return s.toString(); }
private void markCommon(RevObject obj, AckNackResult anr) throws IOException { if (statelessRPC && anr == AckNackResult.ACK_COMMON && !obj.has(STATE)) { StringBuilder s; s = new StringBuilder(6 + Constants.OBJECT_ID_STRING_LENGTH); s.append("have "); //$NON-NLS-1$ s.append(obj.name()); s.append('\n'); pckState.writeString(s.toString()); obj.add(STATE); } obj.add(COMMON); if (obj instanceof RevCommit) ((RevCommit) obj).carry(COMMON); }
/** * Set the object this tag refers to, and infer its type. * * @param obj * the object the tag will refer to. */ public void setObjectId(RevObject obj) { setObjectId(obj, obj.getType()); }
private void processTree(RevObject obj) throws TransportException { try { treeWalk.reset(obj); while (treeWalk.next()) { final FileMode mode = treeWalk.getFileMode(0); final int sType = mode.getObjectType(); switch (sType) { case Constants.OBJ_BLOB: case Constants.OBJ_TREE: treeWalk.getObjectId(idBuffer, 0); needs(revWalk.lookupAny(idBuffer, sType)); continue; default: if (FileMode.GITLINK.equals(mode)) continue; treeWalk.getObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.format(JGitText.get().invalidModeFor , mode, idBuffer.name(), treeWalk.getPathString(), obj.getId().name())); } } } catch (IOException ioe) { throw new TransportException(MessageFormat.format(JGitText.get().cannotReadTree, obj.name()), ioe); } obj.add(COMPLETE); }
@Override protected void run() throws Exception { ObjectReader reader = db.newObjectReader(); RevObject obj = new RevWalk(reader).parseAny(objectId); byte[] delta = getDelta(reader, obj); // We're crossing our fingers that this will be a delta. Double // check the size field in the header, it should match. // long size = reader.getObjectSize(obj, obj.getType()); try { if (BinaryDelta.getResultSize(delta) != size) throw die("Object " + obj.name() + " is not a delta"); } catch (ArrayIndexOutOfBoundsException bad) { throw die("Object " + obj.name() + " is not a delta"); } outw.println(BinaryDelta.format(delta)); }
haveObjs.add(o); if (want.contains(o)) { o.add(include); wantObjs.add(o); if (o instanceof RevTag) RevObject obj = walker.lookupOrNull(id); if (obj instanceof RevCommit && obj.has(include) && !obj.has(RevFlag.UNINTERESTING) && !obj.has(added)) { obj.add(added); addObject(obj, 0); RevObject o; while ((o = walker.nextObject()) != null) { if (o.has(RevFlag.UNINTERESTING)) continue; if (exclude(o)) byte[] pathBuf = walker.getPathBuffer(); int pathLen = walker.getPathLength(); bases.addBase(o.getType(), pathBuf, pathLen, pathHash); filterAndAddObject(o, o.getType(), pathHash, want); countingMonitor.update(1); RevObject o; while ((o = walker.nextObject()) != null) { if (o.has(RevFlag.UNINTERESTING))
private void markLocalObjComplete(RevObject obj) throws IOException { while (obj.getType() == Constants.OBJ_TAG) { obj.add(COMPLETE); obj = ((RevTag) obj).getObject(); revWalk.parseHeaders(obj); } switch (obj.getType()) { case Constants.OBJ_BLOB: obj.add(COMPLETE); break; case Constants.OBJ_COMMIT: pushLocalCommit((RevCommit) obj); break; case Constants.OBJ_TREE: markTreeComplete((RevTree) obj); break; } }
private void processBlob(RevObject obj) throws TransportException { try { if (reader.has(obj, Constants.OBJ_BLOB)) obj.add(COMPLETE); else throw new TransportException(MessageFormat.format(JGitText .get().cannotReadBlob, obj.name()), new MissingObjectException(obj, Constants.TYPE_BLOB)); } catch (IOException error) { throw new TransportException(MessageFormat.format( JGitText.get().cannotReadBlob, obj.name()), error); } }
private Ref newRef(String name, ObjectId id) throws MissingObjectException, IOException { RevObject o = rw.parseAny(id); if (o instanceof RevTag) { RevObject p = rw.peel(o); return new ObjectIdRef.PeeledTag(LOOSE, name, id, p.copy()); } return new ObjectIdRef.PeeledNonTag(LOOSE, name, id); }
@Override protected void show(final ObjectWalk ow, final RevObject obj) throws Exception { if (obj.has(RevFlag.UNINTERESTING)) outw.print('-'); obj.getId().copyTo(outbuffer, outw); final String path = ow.getPathString(); if (path != null) { outw.print(' '); outw.print(path); } else if (obj instanceof RevTree) outw.print(' '); outw.println(); } }
private void verifyClientShallow(Set<ObjectId> shallowCommits) throws IOException, PackProtocolException { AsyncRevObjectQueue q = walk.parseAny(shallowCommits, true); try { for (;;) { try { // Shallow objects named by the client must be commits. RevObject o = q.next(); if (o == null) { break; } if (!(o instanceof RevCommit)) { throw new PackProtocolException( MessageFormat.format( JGitText.get().invalidShallowObject, o.name())); } } catch (MissingObjectException notCommit) { // shallow objects not known at the server are ignored // by git-core upload-pack, match that behavior. shallowCommits.remove(notCommit.getObjectId()); continue; } } } finally { q.release(); } }
private void markAdvertised(AnyObjectId id) { try { walk.parseAny(id).add(ADVERTISED); } catch (IOException readError) { // We probably just do not have this object locally. } }
private List<ObjectIdWithOffset> toInclude(DfsPackFile src, DfsReader ctx) throws IOException { PackIndex srcIdx = src.getPackIndex(ctx); List<ObjectIdWithOffset> want = new BlockList<>( (int) srcIdx.getObjectCount()); SCAN: for (PackIndex.MutableEntry ent : srcIdx) { ObjectId id = ent.toObjectId(); RevObject obj = rw.lookupOrNull(id); if (obj != null && (obj.has(added) || obj.has(isBase))) continue; for (ObjectIdSet e : exclude) if (e.contains(id)) continue SCAN; want.add(new ObjectIdWithOffset(id, ent.getOffset())); } Collections.sort(want, new Comparator<ObjectIdWithOffset>() { @Override public int compare(ObjectIdWithOffset a, ObjectIdWithOffset b) { return Long.signum(a.offset - b.offset); } }); return want; }
/** * Ensure the object's full body content is available. * <p> * This method only returns successfully if the object exists and was parsed * without error. * * @param obj * the object the caller needs to be parsed. * @throws org.eclipse.jgit.errors.MissingObjectException * the supplied does not exist. * @throws java.io.IOException * a pack file or loose object could not be read. */ public void parseBody(RevObject obj) throws MissingObjectException, IOException { obj.parseBody(this); }
/** * Ensure the object's critical headers have been parsed. * <p> * This method only returns successfully if the object exists and was parsed * without error. * * @param obj * the object the caller needs to be parsed. * @throws org.eclipse.jgit.errors.MissingObjectException * the supplied does not exist. * @throws java.io.IOException * a pack file or loose object could not be read. */ public void parseHeaders(RevObject obj) throws MissingObjectException, IOException { if ((obj.flags & PARSED) == 0) obj.parseHeaders(this); }
private void addObject(RevObject object, int pathHashCode) { addObject(object, object.getType(), pathHashCode); }