/// <exception cref="System.IO.IOException"></exception> private void MarkLocalObjComplete(RevObject obj) { while (obj.Type == Constants.OBJ_TAG) { obj.Add(COMPLETE); obj = ((RevTag)obj).GetObject(); revWalk.ParseHeaders(obj); } switch (obj.Type) { case Constants.OBJ_BLOB: { obj.Add(COMPLETE); break; } case Constants.OBJ_COMMIT: { PushLocalCommit((RevCommit)obj); break; } case Constants.OBJ_TREE: { MarkTreeComplete((RevTree)obj); break; } } }
/// <exception cref="System.IO.IOException"></exception> private bool WantSatisfied(RevObject want) { if (want.Has(SATISFIED)) { return(true); } walk.ResetRetain(SAVE); walk.MarkStart((RevCommit)want); if (oldestTime != 0) { walk.SetRevFilter(CommitTimeRevFilter.After(oldestTime * 1000L)); } for (; ;) { RevCommit c = walk.Next(); if (c == null) { break; } if (c.Has(PEER_HAS)) { AddCommonBase(c); want.Add(SATISFIED); return(true); } } return(false); }
private void ProcessTag(RevObject obj) { RevTag tag = (RevTag)obj; Needs(tag.GetObject()); obj.Add(COMPLETE); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void QueueWants(ICollection <Ref> want) { HashSet <ObjectId> inWorkQueue = new HashSet <ObjectId>(); foreach (Ref r in want) { ObjectId id = r.GetObjectId(); try { RevObject obj = revWalk.ParseAny(id); if (obj.Has(COMPLETE)) { continue; } if (inWorkQueue.AddItem(id)) { obj.Add(IN_WORK_QUEUE); workQueue.AddItem(obj); } } catch (MissingObjectException) { if (inWorkQueue.AddItem(id)) { workQueue.AddItem(id); } } catch (IOException e) { throw new TransportException(MessageFormat.Format(JGitText.Get().cannotRead, id.Name ), e); } } }
/// <summary> /// Mark an element which used to be shallow in the client, but which /// should now be considered a full commit. /// </summary> /// <remarks> /// Mark an element which used to be shallow in the client, but which /// should now be considered a full commit. Any ancestors of this commit /// should be included in the walk, even if they are the ancestor of an /// uninteresting commit. /// </remarks> /// <param name="c">Commit to mark</param> /// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException /// </exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException">NGit.Errors.IncorrectObjectTypeException /// </exception> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void MarkUnshallow(RevObject c) { if (c is RevCommit) { c.Add(UNSHALLOW); } base.MarkStart(c); }
private void AddCommonBase(RevObject o) { if (!o.Has(COMMON)) { o.Add(COMMON); commonBase.AddItem(o); okToGiveUp = null; } }
// We probably just do not have this object locally. /// <exception cref="System.IO.IOException"></exception> private void MarkCommon(RevObject obj, PacketLineIn.AckNackResult anr) { if (statelessRPC && anr == PacketLineIn.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 is RevCommit) { ((RevCommit)obj).Carry(COMMON); } }
private void Needs(RevObject obj) { if (obj.Has(COMPLETE)) { return; } if (!obj.Has(IN_WORK_QUEUE)) { obj.Add(IN_WORK_QUEUE); workQueue.AddItem(obj); } }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ProcessCommit(RevObject obj) { RevCommit commit = (RevCommit)obj; MarkLocalCommitsComplete(commit.CommitTime); Needs(commit.Tree); foreach (RevCommit p in commit.Parents) { Needs(p); } obj.Add(COMPLETE); }
/// <exception cref="System.IO.IOException"></exception> private void MarkTreeComplete(RevTree tree) { if (tree.Has(COMPLETE)) { return; } tree.Add(COMPLETE); treeWalk.Reset(tree); while (treeWalk.Next()) { FileMode mode = treeWalk.GetFileMode(0); int sType = mode.GetObjectType(); switch (sType) { case Constants.OBJ_BLOB: { treeWalk.GetObjectId(idBuffer, 0); revWalk.LookupAny(idBuffer, sType).Add(COMPLETE); continue; goto case Constants.OBJ_TREE; } case Constants.OBJ_TREE: { treeWalk.GetObjectId(idBuffer, 0); RevObject o = revWalk.LookupAny(idBuffer, sType); if (!o.Has(COMPLETE)) { o.Add(COMPLETE); treeWalk.EnterSubtree(); } continue; goto default; } default: { if (FileMode.GITLINK.Equals(mode)) { continue; } treeWalk.GetObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3 , mode, idBuffer.Name, treeWalk.PathString, tree.Name)); } } } }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ProcessBlob(RevObject obj) { 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); } }
/// <exception cref="NGit.Errors.TransportException"></exception> private void ProcessTree(RevObject obj) { try { treeWalk.Reset(obj); while (treeWalk.Next()) { FileMode mode = treeWalk.GetFileMode(0); int sType = mode.GetObjectType(); switch (sType) { case Constants.OBJ_BLOB: case Constants.OBJ_TREE: { treeWalk.GetObjectId(idBuffer, 0); Needs(revWalk.LookupAny(idBuffer, sType)); continue; goto default; } default: { if (FileMode.GITLINK.Equals(mode)) { continue; } treeWalk.GetObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().invalidModeFor , mode, idBuffer.Name, treeWalk.PathString, obj.Id.Name)); } } } } catch (IOException ioe) { throw new TransportException(MessageFormat.Format(JGitText.Get().cannotReadTree, obj.Name), ioe); } obj.Add(COMPLETE); }
/// <exception cref="System.IO.IOException"></exception> private ObjectId ProcessHaveLines(IList <ObjectId> peerHas, ObjectId last) { if (peerHas.IsEmpty()) { return(last); } IList <ObjectId> toParse = peerHas; HashSet <ObjectId> peerHasSet = null; bool needMissing = false; if (wantAll.IsEmpty() && !wantIds.IsEmpty()) { // We have not yet parsed the want list. Parse it now. peerHasSet = new HashSet <ObjectId>(peerHas); int cnt = wantIds.Count + peerHasSet.Count; toParse = new AList <ObjectId>(cnt); Sharpen.Collections.AddAll(toParse, wantIds); Sharpen.Collections.AddAll(toParse, peerHasSet); needMissing = true; } AsyncRevObjectQueue q = walk.ParseAny(toParse.AsIterable(), needMissing); try { for (; ;) { RevObject obj; try { obj = q.Next(); } catch (MissingObjectException notFound) { ObjectId id = notFound.GetObjectId(); if (wantIds.Contains(id)) { string msg = MessageFormat.Format(JGitText.Get().wantNotValid, id.Name); pckOut.WriteString("ERR " + msg); throw new PackProtocolException(msg, notFound); } continue; } if (obj == null) { break; } // If the object is still found in wantIds, the want // list wasn't parsed earlier, and was done in this batch. // if (wantIds.Remove(obj)) { if (!advertised.Contains(obj)) { string msg = MessageFormat.Format(JGitText.Get().wantNotValid, obj.Name); pckOut.WriteString("ERR " + msg); throw new PackProtocolException(msg); } if (!obj.Has(WANT)) { obj.Add(WANT); wantAll.AddItem(obj); } if (!(obj is RevCommit)) { obj.Add(SATISFIED); } if (obj is RevTag) { RevObject target = walk.Peel(obj); if (target is RevCommit) { if (!target.Has(WANT)) { target.Add(WANT); wantAll.AddItem(target); } } } if (!peerHasSet.Contains(obj)) { continue; } } last = obj; if (obj is RevCommit) { RevCommit c = (RevCommit)obj; if (oldestTime == 0 || c.CommitTime < oldestTime) { oldestTime = c.CommitTime; } } if (obj.Has(PEER_HAS)) { continue; } obj.Add(PEER_HAS); if (obj is RevCommit) { ((RevCommit)obj).Carry(PEER_HAS); } AddCommonBase(obj); switch (multiAck) { case BasePackFetchConnection.MultiAck.OFF: { // If both sides have the same object; let the client know. // if (commonBase.Count == 1) { pckOut.WriteString("ACK " + obj.Name + "\n"); } break; } case BasePackFetchConnection.MultiAck.CONTINUE: { pckOut.WriteString("ACK " + obj.Name + " continue\n"); break; } case BasePackFetchConnection.MultiAck.DETAILED: { pckOut.WriteString("ACK " + obj.Name + " common\n"); break; } } } } finally { q.Release(); } // If we don't have one of the objects but we're also willing to // create a pack at this point, let the client know so it stops // telling us about its history. // bool didOkToGiveUp = false; for (int i = peerHas.Count - 1; i >= 0; i--) { ObjectId id = peerHas[i]; if (walk.LookupOrNull(id) == null) { didOkToGiveUp = true; if (OkToGiveUp()) { switch (multiAck) { case BasePackFetchConnection.MultiAck.OFF: { break; } case BasePackFetchConnection.MultiAck.CONTINUE: { pckOut.WriteString("ACK " + id.Name + " continue\n"); break; } case BasePackFetchConnection.MultiAck.DETAILED: { pckOut.WriteString("ACK " + id.Name + " ready\n"); break; } } } break; } } if (multiAck == BasePackFetchConnection.MultiAck.DETAILED && !didOkToGiveUp && OkToGiveUp ()) { ObjectId id = peerHas[peerHas.Count - 1]; pckOut.WriteString("ACK " + id.Name + " ready\n"); } peerHas.Clear(); return(last); }