TrackingRefUpdate( boolean canForceUpdate, String remoteName, String localName, AnyObjectId oldValue, AnyObjectId newValue) { this.remoteName = remoteName; this.localName = localName; this.forceUpdate = canForceUpdate; this.oldObjectId = oldValue.copy(); this.newObjectId = newValue.copy(); }
private RefUpdate.Result decode(ReceiveCommand.Result status) { switch (status) { case OK: if (AnyObjectId.equals(oldObjectId, newObjectId)) return RefUpdate.Result.NO_CHANGE; switch (getType()) { case CREATE: return RefUpdate.Result.NEW; case UPDATE: return RefUpdate.Result.FAST_FORWARD; case DELETE: case UPDATE_NONFASTFORWARD: default: return RefUpdate.Result.FORCED; } case REJECTED_NOCREATE: case REJECTED_NODELETE: case REJECTED_NONFASTFORWARD: return RefUpdate.Result.REJECTED; case REJECTED_CURRENT_BRANCH: return RefUpdate.Result.REJECTED_CURRENT_BRANCH; case REJECTED_MISSING_OBJECT: return RefUpdate.Result.IO_FAILURE; case LOCK_FAILURE: case NOT_ATTEMPTED: case REJECTED_OTHER_REASON: default: return RefUpdate.Result.LOCK_FAILURE; } }
/** * Obtain a unique abbreviation (prefix) of an object SHA-1. * * <p>The returned abbreviation would expand back to the argument ObjectId when passed to {@link * #resolve(AbbreviatedObjectId)}, assuming no new objects are added to this repository between * calls. * * <p>The default implementation of this method abbreviates the id to the minimum length, then * resolves it to see if there are multiple results. When multiple results are found, the length * is extended by 1 and resolve is tried again. * * @param objectId object identity that needs to be abbreviated. * @param len minimum length of the abbreviated string. Must be in the range [2, {@value * Constants#OBJECT_ID_STRING_LENGTH}]. * @return SHA-1 abbreviation. If no matching objects exist in the repository, the abbreviation * will match the minimum length. * @throws IOException the object store cannot be read. */ public AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len) throws IOException { if (len == Constants.OBJECT_ID_STRING_LENGTH) return AbbreviatedObjectId.fromObjectId(objectId); AbbreviatedObjectId abbrev = objectId.abbreviate(len); Collection<ObjectId> matches = resolve(abbrev); while (1 < matches.size() && len < Constants.OBJECT_ID_STRING_LENGTH) { abbrev = objectId.abbreviate(++len); List<ObjectId> n = new ArrayList<ObjectId>(8); for (ObjectId candidate : matches) { if (abbrev.prefixCompare(candidate) == 0) n.add(candidate); } if (1 < n.size()) matches = n; else matches = resolve(abbrev); } return abbrev; }
/** * Add a parent onto the end of the parent list. * * @param additionalParent new parent to add onto the end of the current parent list. */ public void addParentId(AnyObjectId additionalParent) { if (parentIds.length == 0) { setParentId(additionalParent); } else { ObjectId[] newParents = new ObjectId[parentIds.length + 1]; for (int i = 0; i < parentIds.length; i++) newParents[i] = parentIds[i]; newParents[parentIds.length] = additionalParent.copy(); parentIds = newParents; commitId = null; } }
private static boolean isReachable(Repository repo, AnyObjectId id) throws IOException { try (RevWalk rw = new RevWalk(repo)) { for (Ref ref : repo.getAllRefs().values()) { rw.markStart(rw.parseCommit(ref.getObjectId())); } for (RevCommit next; (next = rw.next()) != null; ) { if (AnyObjectId.equals(next, id)) { return true; } } } return false; }
/** * Push a candidate object onto the generator's traversal stack. * * <p>Candidates should be pushed in history order from oldest-to-newest. Applications should push * the starting commit first, then the index revision (if the index is interesting), and finally * the working tree copy (if the working tree is interesting). * * @param description description of the blob revision, such as "Working Tree". * @param id may be a commit or a blob. * @return {@code this} * @throws IOException the repository cannot be read. */ public BlameGenerator push(String description, AnyObjectId id) throws IOException { ObjectLoader ldr = reader.open(id); if (ldr.getType() == OBJ_BLOB) { if (description == null) description = JGitText.get().blameNotCommittedYet; BlobCandidate c = new BlobCandidate(description, resultPath); c.sourceBlob = id.toObjectId(); c.sourceText = new RawText(ldr.getCachedBytes(Integer.MAX_VALUE)); c.regionList = new Region(0, 0, c.sourceText.size()); remaining = c.sourceText.size(); push(c); return this; } RevCommit commit = revPool.parseCommit(id); if (!find(commit, resultPath)) return this; Candidate c = new Candidate(commit, resultPath); c.sourceBlob = idBuf.toObjectId(); c.loadText(reader); c.regionList = new Region(0, 0, c.sourceText.size()); remaining = c.sourceText.size(); push(c); return this; }
/** * Set the parents of this commit. * * @param parent1 the first parent of this commit. Typically this is the current value of the * {@code HEAD} reference and is thus the current branch's position in history. * @param parent2 the second parent of this merge commit. Usually this is the branch being merged * into the current branch. */ public void setParentIds(AnyObjectId parent1, AnyObjectId parent2) { parentIds = new ObjectId[] {parent1.copy(), parent2.copy()}; commitId = null; }
/** * Set the parent of this commit. * * @param newParent the single parent for the commit. */ public void setParentId(AnyObjectId newParent) { parentIds = new ObjectId[] {newParent.copy()}; commitId = null; }
/** * Set the tree id for this commit object * * @param id the tree identity. */ public void setTreeId(AnyObjectId id) { treeId = id.copy(); commitId = null; }
/** * Configure the generator to compute reverse blame (history of deletes). * * <p>This method is expensive as it immediately runs a RevWalk over the history spanning the * expression {@code start..end} (end being more recent than start) and then performs the * equivalent operation as {@link #push(String, AnyObjectId)} to begin blame traversal from the * commit named by {@code start} walking forwards through history until {@code end} blaming line * deletions. * * <p>A reverse blame may produce multiple sources for the same result line, each of these is a * descendant commit that removed the line, typically this occurs when the same deletion appears * in multiple side branches such as due to a cherry-pick. Applications relying on reverse should * use {@link BlameResult} as it filters these duplicate sources and only remembers the first * (oldest) deletion. * * @param start oldest commit to traverse from. The result file will be loaded from this commit's * tree. * @param end most recent commit to stop traversal at. Usually an active branch tip, tag, or HEAD. * @return {@code this} * @throws IOException the repository cannot be read. */ public BlameGenerator reverse(AnyObjectId start, AnyObjectId end) throws IOException { return reverse(start, Collections.singleton(end.toObjectId())); }