private static RevObject safeParseOld(RevWalk rw, AnyObjectId oldId) throws IOException { try { return oldId != null ? rw.parseAny(oldId) : null; } catch (MissingObjectException e) { // We can expect some old objects to be missing, like if we are trying to // force a deletion of a branch and the object it points to has been // pruned from the database due to freak corruption accidents (it happens // with 'git new-work-dir'). return null; } }
private void markAdvertised(AnyObjectId id) { try { walk.parseAny(id).add(ADVERTISED); } catch (IOException readError) { // We probably just do not have this object locally. } }
private static boolean isMissing(RevWalk walk, ObjectId id) throws IOException { if (id.equals(ObjectId.zeroId())) { return false; // Explicit add or delete is not missing. } try { walk.parseAny(id); return false; } catch (MissingObjectException e) { return true; } }
private static RevObject safeParseNew(RevWalk rw, AnyObjectId newId) throws IOException { if (newId == null || ObjectId.zeroId().equals(newId)) { return null; } return rw.parseAny(newId); }
@Nullable private RevObject parseSimple(RevWalk rw, String revstr) throws IOException { ObjectId id = resolveSimple(revstr); return id != null ? rw.parseAny(id) : null; }
private int maxTimeWanted(Collection<Ref> wants) { int maxTime = 0; for (Ref r : wants) { try { final RevObject obj = walk.parseAny(r.getObjectId()); if (obj instanceof RevCommit) { final int cTime = ((RevCommit) obj).getCommitTime(); if (maxTime < cTime) maxTime = cTime; } } catch (IOException error) { // We don't have it, but we want to fetch (thus fixing error). } } return maxTime; }
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); }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // a RevWalk allows to retrieve information from the repository try (RevWalk walk = new RevWalk(repository)) { // a simple tag that is not annotated Ref simpleTag = repository.findRef("initialtag"); RevObject any = walk.parseAny(simpleTag.getObjectId()); System.out.println("Commit: " + any); // an annotated tag Ref annotatedTag = repository.findRef("secondtag"); any = walk.parseAny(annotatedTag.getObjectId()); System.out.println("Tag: " + any); // finally try to print out the tag-content System.out.println("\nTag-Content: \n"); ObjectLoader loader = repository.open(annotatedTag.getObjectId()); loader.copyTo(System.out); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // a RevWalk allows to retrieve information from the repository try (RevWalk walk = new RevWalk(repository)) { // a simple tag that is not annotated Ref simpleTag = repository.findRef("initialtag"); RevObject any = walk.parseAny(simpleTag.getObjectId()); System.out.println("Commit: " + any); // an annotated tag Ref annotatedTag = repository.findRef("secondtag"); any = walk.parseAny(annotatedTag.getObjectId()); System.out.println("Tag: " + any); // finally try to print out the tag-content System.out.println("\nTag-Content: \n"); ObjectLoader loader = repository.open(annotatedTag.getObjectId()); loader.copyTo(System.out); walk.dispose(); } } } }
private int minCommitTime() throws IOException { int min = Integer.MAX_VALUE; for (ObjectId id : revs) { RevObject o = walk.parseAny(id); while (o instanceof RevTag) { o = ((RevTag) o).getObject(); walk.parseHeaders(o); } if (o instanceof RevCommit) { RevCommit c = (RevCommit) o; if (c.getCommitTime() < min) min = c.getCommitTime(); } } return min; }
private void addRef(Ref ref, Map<ObjectId, String> nonCommits, FIFORevQueue pending) throws IOException { if (ref.getObjectId() == null) return; RevObject o = walk.parseAny(ref.getObjectId()); while (o instanceof RevTag) { RevTag t = (RevTag) o; nonCommits.put(o, ref.getName()); o = t.getObject(); walk.parseHeaders(o); } if (o instanceof NameRevCommit) { NameRevCommit c = (NameRevCommit) o; if (c.tip == null) c.tip = ref.getName(); pending.add(c); } else if (!nonCommits.containsKey(o)) nonCommits.put(o, ref.getName()); }
private void markLocalRefsComplete(Set<ObjectId> have) throws TransportException { List<Ref> refs; try { refs = local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(e.getMessage(), e); } for (Ref r : refs) { try { markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } for (ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError); } } }
private void reduceObjects(List<ReceiveCommand> cmds, List<RevCommit> commits, Repository git, Set<ObjectId> newObjs) throws IOException { try (RevWalk rw = new RevWalk(git)) { rw.setRetainBody(false); for (ObjectId id : newObjs) { RevObject obj = rw.parseAny(id); if (obj instanceof RevCommit) { rw.markStart((RevCommit) obj); } else { stage(cmds, id); } } for (RevCommit c; (c = rw.next()) != null;) { commits.add(c); rw.markUninteresting(c); } } }
private boolean checkObjectExistence(RevWalk walk, List<ReceiveCommand> commands) throws IOException { for (ReceiveCommand cmd : commands) { try { if (!cmd.getNewId().equals(ObjectId.zeroId())) { walk.parseAny(cmd.getNewId()); } } catch (MissingObjectException e) { // ReceiveCommand#setResult(Result) converts REJECTED to // REJECTED_NONFASTFORWARD, even though that result is also used for a // missing object. Eagerly handle this case so we can set the right // result. reject(cmd, ReceiveCommand.Result.REJECTED_MISSING_OBJECT, commands); return false; } } return true; }
private boolean checkObjectExistence(RevWalk rw, List<ReceiveCommand> pending) throws IOException { for (ReceiveCommand cmd : pending) { try { if (!cmd.getNewId().equals(ObjectId.zeroId())) { rw.parseAny(cmd.getNewId()); } } catch (MissingObjectException e) { // ReceiveCommand#setResult(Result) converts REJECTED to // REJECTED_NONFASTFORWARD, even though that result is also // used for a missing object. Eagerly handle this case so we // can set the right result. cmd.setResult(REJECTED_MISSING_OBJECT); ReceiveCommand.abort(pending); return false; } } return true; }
private static Ref peeledRef(RevWalk walk, ReceiveCommand cmd) throws IOException { ObjectId newId = cmd.getNewId().copy(); RevObject obj = walk.parseAny(newId); if (obj instanceof RevTag) { return new ObjectIdRef.PeeledTag( Ref.Storage.PACKED, cmd.getRefName(), newId, walk.peel(obj).copy()); } return new ObjectIdRef.PeeledNonTag( Ref.Storage.PACKED, cmd.getRefName(), newId); }
private ObjectIdRef doPeel(Ref leaf) throws MissingObjectException, IOException { try (RevWalk rw = new RevWalk(getRepository())) { RevObject obj = rw.parseAny(leaf.getObjectId()); if (obj instanceof RevTag) { return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId(), rw.peel(obj).copy()); } else { return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId()); } } }
/** {@inheritDoc} */ @Override public Ref peel(Ref ref) throws IOException { Ref i = ref.getLeaf(); ObjectId id = i.getObjectId(); if (i.isPeeled() || id == null) { return ref; } try (RevWalk rw = new RevWalk(repo)) { RevObject obj = rw.parseAny(id); if (obj instanceof RevTag) { ObjectId p = rw.peel(obj).copy(); i = new ObjectIdRef.PeeledTag(PACKED, i.getName(), id, p); } else { i = new ObjectIdRef.PeeledNonTag(PACKED, i.getName(), id); } } return recreate(ref, i); }
Ref doPeel(Ref leaf) throws MissingObjectException, IOException { try (RevWalk rw = new RevWalk(repository)) { RevObject obj = rw.parseAny(leaf.getObjectId()); if (obj instanceof RevTag) { return new ObjectIdRef.PeeledTag( leaf.getStorage(), leaf.getName(), leaf.getObjectId(), rw.peel(obj).copy()); } else { return new ObjectIdRef.PeeledNonTag( leaf.getStorage(), leaf.getName(), leaf.getObjectId()); } } }
static Ref toRef(RevWalk rw, ObjectId id, @Nullable String target, String name, boolean mustExist) throws MissingObjectException, IOException { if (target != null) { return new SymbolicRef(name, new ObjectIdRef.Unpeeled(NETWORK, target, id)); } else if (ObjectId.zeroId().equals(id)) { return null; } try { RevObject o = rw.parseAny(id); if (o instanceof RevTag) { RevObject p = rw.peel(o); return new ObjectIdRef.PeeledTag(NETWORK, name, id, p.copy()); } return new ObjectIdRef.PeeledNonTag(NETWORK, name, id); } catch (MissingObjectException e) { if (mustExist) { throw e; } return new ObjectIdRef.Unpeeled(NETWORK, name, id); } }