private void QueueWants(IEnumerable <Ref> want) { var inWorkQueue = new List <ObjectId>(); foreach (Ref r in want) { ObjectId id = r.ObjectId; try { RevObject obj = _revWalk.parseAny(id); if (obj.has(COMPLETE)) { continue; } inWorkQueue.Add(id); obj.add(IN_WORK_QUEUE); _workQueue.AddLast(obj); } catch (MissingObjectException) { inWorkQueue.Add(id); _workQueue.AddLast(id); } catch (IOException e) { throw new TransportException("Cannot Read " + id.Name, e); } } }
private int MaxTimeWanted(IEnumerable <Ref> wants) { int maxTime = 0; foreach (Ref r in wants) { try { RevCommit obj = (_walk.parseAny(r.ObjectId) as RevCommit); if (obj != null) { int cTime = obj.CommitTime; if (maxTime < cTime) { maxTime = cTime; } } } catch (IOException) { } } return(maxTime); }
private int MaxTimeWanted(IEnumerable <Ref> wants) { int maxTime = 0; foreach (Ref r in wants) { try { var obj = (_walk.parseAny(r.ObjectId) as RevCommit); if (obj != null) { int cTime = obj.CommitTime; if (maxTime < cTime) { maxTime = cTime; } } } catch (IOException) { // We don't have it, but we want to fetch (thus fixing error). } } return(maxTime); }
/// <summary> /// Merge together two or more tree-ish objects. /// <para /> /// Any tree-ish may be supplied as inputs. Commits and/or tags pointing at /// trees or commits may be passed as input objects. /// </summary> /// <param name="tips"> /// source trees to be combined together. The merge base is not /// included in this set. </param> /// <returns> /// True if the merge was completed without conflicts; false if the /// merge strategy cannot handle this merge or there were conflicts /// preventing it from automatically resolving all paths. /// </returns> /// <exception cref="IncorrectObjectTypeException"> /// one of the input objects is not a commit, but the strategy /// requires it to be a commit. /// </exception> /// <exception cref="IOException"> /// one or more sources could not be read, or outputs could not /// be written to the Repository. /// </exception> public virtual bool Merge(AnyObjectId[] tips) { _sourceObjects = new RevObject[tips.Length]; for (int i = 0; i < tips.Length; i++) { _sourceObjects[i] = _walk.parseAny(tips[i]); } _sourceCommits = new RevCommit[_sourceObjects.Length]; for (int i = 0; i < _sourceObjects.Length; i++) { try { _sourceCommits[i] = _walk.parseCommit(_sourceObjects[i]); } catch (IncorrectObjectTypeException) { _sourceCommits[i] = null; } } SourceTrees = new RevTree[_sourceObjects.Length]; for (int i = 0; i < _sourceObjects.Length; i++) { SourceTrees[i] = _walk.parseTree(_sourceObjects[i]); } return(MergeImpl()); }
private void Service() { if (biDirectionalPipe) { SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(_pckOut)); } else { _refs = _refFilter.filter(_db.getAllRefs()); foreach (Ref r in _refs.Values) { try { _walk.parseAny(r.ObjectId).add(ADVERTISED); } catch (IOException) { // Skip missing/corrupt objects } } } RecvWants(); if (_wantAll.Count == 0) { return; } if (_options.Contains(OPTION_MULTI_ACK_DETAILED)) { _multiAck = BasePackFetchConnection.MultiAck.DETAILED; } else if (_options.Contains(OptionMultiAck)) { _multiAck = BasePackFetchConnection.MultiAck.CONTINUE; } else { _multiAck = BasePackFetchConnection.MultiAck.OFF; } if (Negotiate()) { SendPack(); } }
public override Ref peel(Ref @ref) { Ref leaf = @ref.getLeaf(); if (leaf.isPeeled() || leaf.getObjectId() == null) { return(@ref); } RevWalk.RevWalk rw = new RevWalk.RevWalk(getRepository()); RevObject obj = rw.parseAny(leaf.getObjectId()); ObjectIdRef newLeaf; if (obj is RevTag) { do { obj = rw.parseAny(((RevTag)obj).getObject()); } while (obj is RevTag); newLeaf = new PeeledTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId(), obj.Copy()); } else { newLeaf = new PeeledNonTag(leaf.getStorage(), leaf .getName(), leaf.getObjectId()); } // Try to remember this peeling in the cache, so we don't have to do // it again in the future, but only if the reference is unchanged. if (leaf.getStorage().IsLoose) { RefList <LooseRef> curList = looseRefs.get(); int idx = curList.find(leaf.getName()); if (0 <= idx && curList.get(idx) == leaf) { LooseRef asPeeled = ((LooseRef)leaf).peel(newLeaf); RefList <LooseRef> newList = curList.set(idx, asPeeled); looseRefs.compareAndSet(curList, newList); } } return(recreate(@ref, newLeaf)); }
private RevObject parseAnyOrNull(AnyObjectId id) { if (id == null) { return(null); } try { return(_walk.parseAny(id)); } catch (IOException) { return(null); } }
private static RevObject SafeParse(RevWalk.RevWalk rw, AnyObjectId id) { try { return(id != null?rw.parseAny(id) : null); } catch (MissingObjectException) { // We can expect some 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 IDictionary <string, RemoteRefUpdate> PrepareRemoteUpdates() { IDictionary <string, RemoteRefUpdate> result = new Dictionary <string, RemoteRefUpdate>(); foreach (RemoteRefUpdate rru in _toPush.Values) { Ref advertisedRef = _connection.GetRef(rru.RemoteName); ObjectId advertisedOld = (advertisedRef == null ? ObjectId.ZeroId : advertisedRef.ObjectId); if (rru.NewObjectId.Equals(advertisedOld)) { if (rru.IsDelete) { // ref does exist neither locally nor remotely rru.Status = RemoteRefUpdate.UpdateStatus.NON_EXISTING; } else { // same object - nothing to do rru.Status = RemoteRefUpdate.UpdateStatus.UP_TO_DATE; } continue; } // caller has explicitly specified expected old object id, while it // has been changed in the mean time - reject if (rru.IsExpectingOldObjectId && !rru.ExpectedOldObjectId.Equals(advertisedOld)) { rru.Status = RemoteRefUpdate.UpdateStatus.REJECTED_REMOTE_CHANGED; continue; } // Create ref (hasn't existed on remote side) and delete ref // are always fast-forward commands, feasible at this level if (advertisedOld.Equals(ObjectId.ZeroId) || rru.IsDelete) { rru.FastForward = true; result.put(rru.RemoteName, rru); continue; } // check for fast-forward: // - both old and new ref must point to commits, AND // - both of them must be known for us, exist in repository, AND // - old commit must be ancestor of new commit bool fastForward = true; try { RevCommit oldRev = (_walker.parseAny(advertisedOld) as RevCommit); RevCommit newRev = (_walker.parseAny(rru.NewObjectId) as RevCommit); if (oldRev == null || newRev == null || !_walker.isMergedInto(oldRev, newRev)) { fastForward = false; } } catch (MissingObjectException) { fastForward = false; } catch (Exception x) { throw new TransportException(_transport.Uri, "reading objects from local repository failed: " + x.Message, x); } rru.FastForward = fastForward; if (!fastForward && !rru.ForceUpdate) { rru.Status = RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD; } else { result.put(rru.RemoteName, rru); } } return(result); }
private void RecvWants() { bool isFirst = true; for (; ; isFirst = false) { string line; try { line = _pckIn.ReadString(); } catch (EndOfStreamException) { if (isFirst) { break; } throw; } if (line.Length == 0) { break; } if (!line.StartsWith("want ") || line.Length < 45) { throw new PackProtocolException("expected want; got " + line); } if (isFirst) { int sp = line.IndexOf(' ', 45); if (sp >= 0) { foreach (string c in line.Substring(sp + 1).Split(' ')) { _options.Add(c); } line = line.Slice(0, sp); } } string name = line.Substring(5); ObjectId id = ObjectId.FromString(name); RevObject o; try { o = _walk.parseAny(id); } catch (IOException e) { throw new PackProtocolException(name + " not valid", e); } if (!o.has(ADVERTISED)) { throw new PackProtocolException(name + " not valid"); } Want(o); } }