/// <summary> /// Delete the ref. /// </summary> /// <param name="walk"> /// a RevWalk instance this delete command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns>the result status of the delete.</returns> public RefUpdateResult delete(RevWalk.RevWalk walk) { string myName = Ref.getLeaf().getName(); if (myName.StartsWith(Constants.R_HEADS)) { Ref head = getRefDatabase().getRef(Constants.HEAD); while (head.isSymbolic()) { head = head.getTarget(); if (myName.Equals(head.getName())) { return(result = RefUpdateResult.REJECTED_CURRENT_BRANCH); } } } try { return(result = updateImpl(walk, new DeleteStore(this))); } catch (IOException) { result = RefUpdateResult.IO_FAILURE; throw; } }
private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef) { string name = localRef.Name; try { TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted"); result.Add(u); if (_transport.DryRun) { return; } u.Delete(walk); switch (u.Result) { case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.NO_CHANGE: case RefUpdate.RefUpdateResult.FAST_FORWARD: case RefUpdate.RefUpdateResult.FORCED: break; default: throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + Enum.GetName(typeof(RefUpdate.RefUpdateResult), u.Result)); } } catch (IOException e) { throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e); } }
private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef) { string name = localRef.Name; try { TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted"); result.Add(u); if (_transport.DryRun) { return; } u.Delete(walk); switch (u.Result) { case RefUpdate.RefUpdateResult.New: case RefUpdate.RefUpdateResult.NoChange: case RefUpdate.RefUpdateResult.FastForward: case RefUpdate.RefUpdateResult.Forced: break; default: throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + u.Result.ToString()); } } catch (System.IO.IOException e) { throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e); } }
public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w) { var wt = (Transport)t; _local = wt.Local; _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null; _remotes = new List <WalkRemoteObjectDatabase> { w }; _unfetchedPacks = new LinkedList <RemotePack>(); _packsConsidered = new List <string>(); _noPacksYet = new LinkedList <WalkRemoteObjectDatabase>(); _noPacksYet.AddLast(w); _noAlternatesYet = new LinkedList <WalkRemoteObjectDatabase>(); _noAlternatesYet.AddLast(w); _fetchErrors = new Dictionary <ObjectId, List <Exception> >(); _packLocks = new List <PackLock>(4); _revWalk = new RevWalk.RevWalk(_local); _revWalk.setRetainBody(false); _treeWalk = new TreeWalk.TreeWalk(_local); COMPLETE = _revWalk.newFlag("COMPLETE"); IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE"); LOCALLY_SEEN = _revWalk.newFlag("LOCALLY_SEEN"); _localCommitQueue = new DateRevQueue(); _workQueue = new LinkedList <ObjectId>(); }
private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store) { if (isNameConflicting()) { return(RefUpdateResult.LockFailure); } var @lock = new LockFile(_looseFile); if ([email protected]()) { return(RefUpdateResult.LockFailure); } try { OldObjectId = _db.IdOf(Name); if (_expValue != null) { ObjectId o = OldObjectId ?? ObjectId.ZeroId; if (!AnyObjectId.equals(_expValue, o)) { return(RefUpdateResult.LockFailure); } } if (OldObjectId == null) { return(store.Store(@lock, RefUpdateResult.New)); } RevObject newObj = SafeParse(walk, _newValue); RevObject oldObj = SafeParse(walk, OldObjectId); if (newObj == oldObj) { return(store.Store(@lock, RefUpdateResult.NoChange)); } RevCommit newCom = (newObj as RevCommit); RevCommit oldCom = (oldObj as RevCommit); if (newCom != null && oldCom != null) { if (walk.isMergedInto(oldCom, newCom)) { return(store.Store(@lock, RefUpdateResult.FastForward)); } } if (IsForceUpdate) { return(store.Store(@lock, RefUpdateResult.Forced)); } return(RefUpdateResult.Rejected); } finally { @lock.Unlock(); } }
public override void Source(RevWalk.RevWalk walker) { if (!(walker is PlotWalk)) { throw new ArgumentException("Not a " + typeof(PlotWalk).FullName); } base.Source(walker); }
private RefUpdateResult updateImpl(RevWalk.RevWalk walk, Store store) { RevObject newObj; RevObject oldObj; if (getRefDatabase().isNameConflicting(Name)) { return(RefUpdateResult.LOCK_FAILURE); } try { if (!tryLock(true)) { return(RefUpdateResult.LOCK_FAILURE); } if (expValue != null) { ObjectId o; o = oldValue != null ? oldValue : ObjectId.ZeroId; if (!AnyObjectId.equals(expValue, o)) { return(RefUpdateResult.LOCK_FAILURE); } } if (oldValue == null) { return(store.execute(RefUpdateResult.NEW)); } newObj = safeParse(walk, newValue); oldObj = safeParse(walk, oldValue); if (newObj == oldObj) { return(store.execute(RefUpdateResult.NO_CHANGE)); } if (newObj is RevCommit && oldObj is RevCommit) { if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj)) { return(store.execute(RefUpdateResult.FAST_FORWARD)); } } if (IsForceUpdate) { return(store.execute(RefUpdateResult.FORCED)); } return(RefUpdateResult.REJECTED); } finally { unlock(); } }
protected internal void updateTrackingRef(RevWalk.RevWalk walk) { if (IsDelete) { TrackingRefUpdate.Delete(walk); } else { TrackingRefUpdate.Update(walk); } }
public RefAdvertiser(PacketLineOut o, RevWalk.RevWalk protoWalk, RevFlag advertisedFlag) { _tmpLine = new StringBuilder(100); _tmpId = new char[2 * Constants.OBJECT_ID_LENGTH]; _capabilities = new List<string>(); _first = true; _pckOut = o; _walk = protoWalk; ADVERTISED = advertisedFlag; }
public RefAdvertiser(PacketLineOut o, RevWalk.RevWalk protoWalk, RevFlag advertisedFlag) { _tmpLine = new StringBuilder(100); _tmpId = new char[2 * Constants.OBJECT_ID_LENGTH]; _capabilities = new List <string>(); _first = true; _pckOut = o; _walk = protoWalk; ADVERTISED = advertisedFlag; }
/// <summary> /// Gracefully update the ref to the new value. /// </summary> /// <param name="walk"> /// A <see cref="RevWalk"/> instance this update command can borrow to /// perform the merge test. The walk will be reset to perform the test. /// </param> /// <returns>The result status of the update.</returns> public RefUpdateResult Update(RevWalk.RevWalk walk) { RequireCanDoUpdate(); try { return(Result = UpdateImpl(walk, new UpdateStore(this))); } catch (IOException) { Result = RefUpdateResult.IOFailure; throw; } }
/// <summary> /// Gracefully update the ref to the new value. /// <para/> /// Merge test will be performed according to <see cref="IsForceUpdate"/>. /// </summary> /// <param name="walk"> /// a RevWalk instance this update command can borrow to perform /// the merge test. The walk will be reset to perform the test. /// </param> /// <returns> /// the result status of the update. /// </returns> public RefUpdateResult update(RevWalk.RevWalk walk) { requireCanDoUpdate(); try { return(result = updateImpl(walk, new UpdateStore(this))); } catch (IOException x) { result = RefUpdateResult.IO_FAILURE; throw x; } }
public ReceivePack(Repository into) { db = into; walk = new RevWalk.RevWalk(db); RepositoryConfig cfg = db.Config; checkReceivedObjects = cfg.getBoolean("receive", "fsckobjects", false); allowCreates = true; allowDeletes = !cfg.getBoolean("receive", "denydeletes", false); allowNonFastForwards = !cfg.getBoolean("receive", "denynonfastforwards", false); allowOfsDelta = cfg.getBoolean("repack", "usedeltabaseoffset", true); preReceive = PreReceiveHook.NULL; postReceive = PostReceiveHook.NULL; }
public override bool include(RevWalk.RevWalk walker, RevCommit cmit) { bool remoteKnowsIsCommon = cmit.has(_common); if (cmit.has(_advertised)) { // Remote advertised this, and we have it, hence common. // Whether or not the remote knows that fact is tested // before we added the flag. If the remote doesn't know // we have to still send them this object. // cmit.add(_common); } return(!remoteKnowsIsCommon); }
/// <summary> * Create process for specified transport and refs updates specification. /// * </summary> /// * <param name="transport"> /// * transport between remote and local repository, used to Create /// * connection. </param> /// * <param name="toPush"> /// * specification of refs updates (and local tracking branches). </param> /// * <exception cref="TransportException"> </exception> public PushProcess(Transport transport, IEnumerable <RemoteRefUpdate> toPush) { _walker = new RevWalk.RevWalk(transport.Local); _transport = transport; _toPush = new Dictionary <string, RemoteRefUpdate>(); foreach (RemoteRefUpdate rru in toPush) { if (_toPush.ContainsKey(rru.RemoteName)) { throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName); } _toPush.Add(rru.RemoteName, rru); } }
public PushProcess(Transport transport, List<RemoteRefUpdate> toPush) { walker = new RevWalk.RevWalk(transport.Local); this.transport = transport; foreach (RemoteRefUpdate rru in toPush) { if (this.toPush.ContainsKey(rru.RemoteName)) { throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName); } else { this.toPush.Add(rru.RemoteName, rru); } } }
public UploadPack(Repository copyFrom) { db = copyFrom; walk = new RevWalk.RevWalk(db); ADVERTISED = walk.newFlag("ADVERTISED"); WANT = walk.newFlag("WANT"); PEER_HAS = walk.newFlag("PEER_HAS"); COMMON = walk.newFlag("COMMON"); walk.carry(PEER_HAS); SAVE = new RevFlagSet(); SAVE.Add(ADVERTISED); SAVE.Add(WANT); SAVE.Add(PEER_HAS); }
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); } }
/// <summary> /// Create a new pack receive for an open repository. /// </summary> /// <param name="into">the destination repository.</param> public ReceivePack(Repository into) { db = into; walk = new RevWalk.RevWalk(db); ReceiveConfig cfg = db.Config.get(ReceiveConfig.KEY); checkReceivedObjects = cfg._checkReceivedObjects; allowCreates = cfg._allowCreates; allowDeletes = cfg._allowDeletes; allowNonFastForwards = cfg._allowNonFastForwards; allowOfsDelta = cfg._allowOfsDelta; refFilter = RefFilterContants.DEFAULT; preReceive = PreReceiveHook.NULL; postReceive = PostReceiveHook.NULL; }
public BasePackFetchConnection(IPackTransport packTransport) : base(packTransport) { RepositoryConfig cfg = local.Config; includeTags = transport.TagOpt != TagOpt.NO_TAGS; thinPack = transport.FetchThin; allowOfsDelta = cfg.GetBoolean("repack", "usedeltabaseoffset", true); walk = new RevWalk.RevWalk(local); reachableCommits = new RevCommitList<RevCommit>(); REACHABLE = walk.newFlag("REACHABLE"); COMMON = walk.newFlag("COMMON"); ADVERTISED = walk.newFlag("ADVERTISED"); walk.carry(COMMON); walk.carry(REACHABLE); walk.carry(ADVERTISED); }
/// <summary> /// Create a new pack upload for an open repository. /// </summary> /// <param name="copyFrom">the source repository.</param> public UploadPack(Repository copyFrom) { _db = copyFrom; _walk = new RevWalk.RevWalk(_db); _walk.setRetainBody(false); ADVERTISED = _walk.newFlag("ADVERTISED"); WANT = _walk.newFlag("WANT"); PEER_HAS = _walk.newFlag("PEER_HAS"); COMMON = _walk.newFlag("COMMON"); _walk.carry(PEER_HAS); SAVE = new RevFlagSet { ADVERTISED, WANT, PEER_HAS }; _refFilter = RefFilterContants.DEFAULT; }
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)); }
/// <summary> /// Create process for specified transport and refs updates specification. /// </summary> /// <param name="transport"> /// transport between remote and local repository, used to Create /// connection. </param> /// <param name="toPush"> /// specification of refs updates (and local tracking branches). /// </param> /// <exception cref="TransportException"> </exception> public PushProcess(Transport transport, IEnumerable<RemoteRefUpdate> toPush) { if (transport == null) throw new ArgumentNullException("transport"); if (toPush == null) throw new ArgumentNullException("toPush"); _walker = new RevWalk.RevWalk(transport.Local); _transport = transport; _toPush = new Dictionary<string, RemoteRefUpdate>(); foreach (RemoteRefUpdate rru in toPush) { if (_toPush.put(rru.RemoteName, rru) != null) { throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName); } } }
public BasePackFetchConnection(IPackTransport packTransport) : base(packTransport) { FetchConfig cfg = local.Config.get(FetchConfig.KEY); _includeTags = transport.TagOpt != TagOpt.NO_TAGS; _thinPack = transport.FetchThin; _allowOfsDelta = cfg.AllowOfsDelta; _walk = new RevWalk.RevWalk(local); _reachableCommits = new RevCommitList <RevCommit>(); REACHABLE = _walk.newFlag("REACHABLE"); COMMON = _walk.newFlag("COMMON"); ADVERTISED = _walk.newFlag("ADVERTISED"); _walk.carry(COMMON); _walk.carry(REACHABLE); _walk.carry(ADVERTISED); }
public BasePackFetchConnection(IPackTransport packTransport) : base(packTransport) { RepositoryConfig cfg = local.Config; _includeTags = transport.TagOpt != TagOpt.NO_TAGS; _thinPack = transport.FetchThin; _allowOfsDelta = cfg.getBoolean("repack", "usedeltabaseoffset", true); _walk = new RevWalk.RevWalk(local); _reachableCommits = new RevCommitList <RevCommit>(); REACHABLE = _walk.newFlag("REACHABLE"); COMMON = _walk.newFlag("COMMON"); ADVERTISED = _walk.newFlag("ADVERTISED"); _walk.carry(COMMON); _walk.carry(REACHABLE); _walk.carry(ADVERTISED); }
private void deleteStaleTrackingRefs(FetchResult result, RevWalk.RevWalk walk) { Repository db = _transport.Local; foreach (Ref @ref in db.getAllRefs().Values) { string refname = @ref.Name; foreach (RefSpec spec in _toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.Source) == null) { deleteTrackingRef(result, db, walk, s, @ref); } } } } }
/// <summary> /// Create a new pack upload for an open repository. /// </summary> /// <param name="copyFrom">the source repository.</param> public UploadPack(Repository copyFrom) { _options = new List <string>(); _wantAll = new List <RevObject>(); _wantCommits = new List <RevCommit>(); _commonBase = new List <RevObject>(); _db = copyFrom; _walk = new RevWalk.RevWalk(_db); _walk.setRetainBody(false); ADVERTISED = _walk.newFlag("ADVERTISED"); WANT = _walk.newFlag("WANT"); PEER_HAS = _walk.newFlag("PEER_HAS"); COMMON = _walk.newFlag("COMMON"); _walk.carry(PEER_HAS); SAVE = new RevFlagSet { ADVERTISED, WANT, PEER_HAS }; }
/// <summary> /// Delete the ref. /// </summary> /// <param name="walk"> /// A <see cref="RevWalk"/> instance this Delete command can borrow to /// perform the merge test. The walk will be reset to perform the test. /// </param> /// <returns>The result status of the Delete.</returns> public RefUpdateResult Delete(RevWalk.RevWalk walk) { if (Name.StartsWith(Constants.R_HEADS)) { Ref head = _db.ReadRef(Constants.HEAD); if (head != null && Name.Equals(head.Name)) { return(Result = RefUpdateResult.RejectedCurrentBranch); } } try { return(Result = UpdateImpl(walk, new DeleteStore(this))); } catch (IOException) { Result = RefUpdateResult.IOFailure; throw; } }
/// <summary> /// Create process for specified transport and refs updates specification. /// </summary> /// <param name="transport"> /// transport between remote and local repository, used to Create /// connection. </param> /// <param name="toPush"> /// specification of refs updates (and local tracking branches). /// </param> /// <exception cref="TransportException"> </exception> public PushProcess(Transport transport, IEnumerable <RemoteRefUpdate> toPush) { if (transport == null) { throw new ArgumentNullException("transport"); } if (toPush == null) { throw new ArgumentNullException("toPush"); } _walker = new RevWalk.RevWalk(transport.Local); _transport = transport; _toPush = new Dictionary <string, RemoteRefUpdate>(); foreach (RemoteRefUpdate rru in toPush) { if (_toPush.put(rru.RemoteName, rru) != null) { throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName); } } }
/// <summary> /// Create a new merge instance for a repository. /// </summary> /// <param name="local"> /// the repository this merger will read and write data on. /// </param> protected Merger(Repository local) { _db = local; _walk = new RevWalk.RevWalk(_db); }
private void verifyPrerequisites() { if (_prereqs.isEmpty()) return; using (var rw = new RevWalk.RevWalk(_transport.Local)) { RevFlag PREREQ = rw.newFlag("PREREQ"); RevFlag SEEN = rw.newFlag("SEEN"); IDictionary<ObjectId, string> missing = new Dictionary<ObjectId, string>(); var commits = new List<RevObject>(); foreach (KeyValuePair<ObjectId, string> e in _prereqs) { ObjectId p = e.Key; try { RevCommit c = rw.parseCommit(p); if (!c.has(PREREQ)) { c.add(PREREQ); commits.Add(c); } } catch (MissingObjectException) { missing.put(p, e.Value); } catch (IOException err) { throw new TransportException(_transport.Uri, "Cannot Read commit " + p.Name, err); } } if (!missing.isEmpty()) throw new MissingBundlePrerequisiteException(_transport.Uri, missing); foreach (Ref r in _transport.Local.getAllRefs().Values) { try { rw.markStart(rw.parseCommit(r.ObjectId)); } catch (IOException) { // If we cannot read the value of the ref skip it. } } int remaining = commits.Count; try { RevCommit c; while ((c = rw.next()) != null) { if (c.has(PREREQ)) { c.add(SEEN); if (--remaining == 0) break; } } } catch (IOException err) { throw new TransportException(_transport.Uri, "Cannot Read object", err); } if (remaining > 0) { foreach (RevObject o in commits) { if (!o.has(SEEN)) missing.put(o, _prereqs.get(o)); } throw new MissingBundlePrerequisiteException(_transport.Uri, missing); } } }
private void executeImp(ProgressMonitor monitor, FetchResult result) { _connection = _transport.openFetch(); try { result.SetAdvertisedRefs(_transport.Uri, _connection.RefsMap); HashSet<Ref> matched = new HashSet<Ref>(); foreach (RefSpec spec in _toFetch) { if (spec.Source == null) throw new TransportException("Source ref not specified for refspec: " + spec); if (spec.Wildcard) { expandWildcard(spec, matched); } else { expandSingle(spec, matched); } } ICollection<Ref> additionalTags = new Collection<Ref>(); TagOpt tagopt = _transport.TagOpt; if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = expandAutoFollowTags(); } else if (tagopt == TagOpt.FETCH_TAGS) { expandFetchTags(); } bool includedTags; if (_askFor.Count != 0 && !askForIsComplete()) { fetchObjects(monitor); includedTags = _connection.DidFetchIncludeTags; // Connection was used for object transfer. If we // do another fetch we must open a new connection. // closeConnection(); } else { includedTags = false; } if (tagopt == TagOpt.AUTO_FOLLOW && additionalTags.Count != 0) { // There are more tags that we want to follow, but // not all were asked for on the initial request. foreach(ObjectId key in _askFor.Keys) { _have.Add(key); } _askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.PeeledObjectId; if (id == null || _transport.Local.HasObject(id)) { wantTag(r); } } if (_askFor.Count != 0 && (!includedTags || !askForIsComplete())) { reopenConnection(); if (_askFor.Count != 0) { fetchObjects(monitor); } } } } finally { closeConnection(); } RevWalk.RevWalk walk = new RevWalk.RevWalk(_transport.Local); if (_transport.RemoveDeletedRefs) { deleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in _localUpdates) { try { u.Update(walk); result.Add(u); } catch (IOException err) { throw new TransportException("Failure updating tracking ref " + u.LocalName + ": " + err.Message, err); } } if (_fetchHeadUpdates.Count != 0) { try { updateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException("Failure updating FETCH_HEAD: " + err.Message, err); } } }
protected override RefUpdate.RefUpdateResult doRename() { if (source.getRef().isSymbolic()) { return(RefUpdate.RefUpdateResult.IO_FAILURE); // not supported } var rw = new RevWalk.RevWalk(_refdb.getRepository()); _objId = source.getOldObjectId(); _updateHead = needToUpdateHEAD(); _tmp = _refdb.newTemporaryUpdate(); try { // First backup the source so its never unreachable. _tmp.setNewObjectId(_objId); _tmp.setForceUpdate(true); _tmp.disableRefLog(); switch (_tmp.update(rw)) { case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.FORCED: case RefUpdate.RefUpdateResult.NO_CHANGE: break; default: return(_tmp.getResult()); } // Save the source's log under the temporary name, we must do // this before we delete the source, otherwise we lose the log. if (!renameLog(source, _tmp)) { return(RefUpdate.RefUpdateResult.IO_FAILURE); } // If HEAD has to be updated, link it now to destination. // We have to link before we delete, otherwise the delete // fails because its the current branch. RefUpdate dst = destination; if (_updateHead) { if (!linkHEAD(destination)) { renameLog(_tmp, source); return(RefUpdate.RefUpdateResult.LOCK_FAILURE); } // Replace the update operation so HEAD will log the rename. dst = _refdb.newUpdate(Constants.HEAD, false); dst.setRefLogIdent(destination.getRefLogIdent()); dst.setRefLogMessage(destination.getRefLogMessage(), false); } // Delete the source name so its path is free for replacement. source.setExpectedOldObjectId(_objId); source.setForceUpdate(true); source.disableRefLog(); if (source.delete(rw) != RefUpdate.RefUpdateResult.FORCED) { renameLog(_tmp, source); if (_updateHead) { linkHEAD(source); } return(source.getResult()); } // Move the log to the destination. if (!renameLog(_tmp, destination)) { renameLog(_tmp, source); source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) { linkHEAD(source); } return(RefUpdate.RefUpdateResult.IO_FAILURE); } // Create the destination, logging the rename during the creation. dst.setExpectedOldObjectId(ObjectId.ZeroId); dst.setNewObjectId(_objId); if (dst.update(rw) != RefUpdate.RefUpdateResult.NEW) { // If we didn't create the destination we have to undo // our work. Put the log back and restore source. if (renameLog(destination, _tmp)) { renameLog(_tmp, source); } source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) { linkHEAD(source); } return(dst.getResult()); } return(RefUpdate.RefUpdateResult.RENAMED); } finally { // Always try to free the temporary name. try { _refdb.delete(_tmp); } catch (IOException) { _refdb.fileFor(_tmp.getName()).Delete(); } } }
public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w) { _idBuffer = new MutableObjectId(); _objectDigest = Constants.newMessageDigest(); var wt = (Transport)t; _local = wt.Local; _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null; _remotes = new List<WalkRemoteObjectDatabase> { w }; _unfetchedPacks = new LinkedList<RemotePack>(); _packsConsidered = new List<string>(); _noPacksYet = new LinkedList<WalkRemoteObjectDatabase>(); _noPacksYet.AddFirst(w); _noAlternatesYet = new LinkedList<WalkRemoteObjectDatabase>(); _noAlternatesYet.AddFirst(w); _fetchErrors = new Dictionary<ObjectId, List<Exception>>(); _packLocks = new List<PackLock>(4); _revWalk = new RevWalk.RevWalk(_local); _treeWalk = new TreeWalk.TreeWalk(_local); COMPLETE = _revWalk.newFlag("COMPLETE"); IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE"); LOCALLY_SEEN = _revWalk.newFlag("LOCALLY_SEEN"); _localCommitQueue = new DateRevQueue(); _workQueue = new LinkedList<ObjectId>(); }
/** * Create a new merge instance for a repository. * * @param local * the repository this merger will read and write data on. */ protected Merger(Repository local) { Db = local; Walk = new RevWalk.RevWalk(Db); }
public void Delete(RevWalk.RevWalk walk) { update.delete(walk); }
protected override RefUpdate.RefUpdateResult doRename() { if (source.getRef().isSymbolic()) return RefUpdate.RefUpdateResult.IO_FAILURE; // not supported var rw = new RevWalk.RevWalk(_refdb.getRepository()); _objId = source.getOldObjectId(); _updateHead = needToUpdateHEAD(); _tmp = _refdb.newTemporaryUpdate(); try { // First backup the source so its never unreachable. _tmp.setNewObjectId(_objId); _tmp.setForceUpdate(true); _tmp.disableRefLog(); switch (_tmp.update(rw)) { case RefUpdate.RefUpdateResult.NEW: case RefUpdate.RefUpdateResult.FORCED: case RefUpdate.RefUpdateResult.NO_CHANGE: break; default: return _tmp.getResult(); } // Save the source's log under the temporary name, we must do // this before we delete the source, otherwise we lose the log. if (!renameLog(source, _tmp)) return RefUpdate.RefUpdateResult.IO_FAILURE; // If HEAD has to be updated, link it now to destination. // We have to link before we delete, otherwise the delete // fails because its the current branch. RefUpdate dst = destination; if (_updateHead) { if (!linkHEAD(destination)) { renameLog(_tmp, source); return RefUpdate.RefUpdateResult.LOCK_FAILURE; } // Replace the update operation so HEAD will log the rename. dst = _refdb.newUpdate(Constants.HEAD, false); dst.setRefLogIdent(destination.getRefLogIdent()); dst.setRefLogMessage(destination.getRefLogMessage(), false); } // Delete the source name so its path is free for replacement. source.setExpectedOldObjectId(_objId); source.setForceUpdate(true); source.disableRefLog(); if (source.delete(rw) != RefUpdate.RefUpdateResult.FORCED) { renameLog(_tmp, source); if (_updateHead) linkHEAD(source); return source.getResult(); } // Move the log to the destination. if (!renameLog(_tmp, destination)) { renameLog(_tmp, source); source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) linkHEAD(source); return RefUpdate.RefUpdateResult.IO_FAILURE; } // Create the destination, logging the rename during the creation. dst.setExpectedOldObjectId(ObjectId.ZeroId); dst.setNewObjectId(_objId); if (dst.update(rw) != RefUpdate.RefUpdateResult.NEW) { // If we didn't create the destination we have to undo // our work. Put the log back and restore source. if (renameLog(destination, _tmp)) renameLog(_tmp, source); source.setExpectedOldObjectId(ObjectId.ZeroId); source.setNewObjectId(_objId); source.update(rw); if (_updateHead) linkHEAD(source); return dst.getResult(); } return RefUpdate.RefUpdateResult.RENAMED; } finally { // Always try to free the temporary name. try { _refdb.delete(_tmp); } catch (IOException) { _refdb.fileFor(_tmp.getName()).Delete(); } } }
private void executeImp(ProgressMonitor monitor, FetchResult result) { _connection = _transport.openFetch(); try { result.SetAdvertisedRefs(_transport.Uri, _connection.RefsMap); HashSet <Ref> matched = new HashSet <Ref>(); foreach (RefSpec spec in _toFetch) { if (spec.Source == null) { throw new TransportException("Source ref not specified for refspec: " + spec); } if (spec.Wildcard) { expandWildcard(spec, matched); } else { expandSingle(spec, matched); } } ICollection <Ref> additionalTags = new Collection <Ref>(); TagOpt tagopt = _transport.TagOpt; if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = expandAutoFollowTags(); } else if (tagopt == TagOpt.FETCH_TAGS) { expandFetchTags(); } bool includedTags; if (_askFor.Count != 0 && !askForIsComplete()) { fetchObjects(monitor); includedTags = _connection.DidFetchIncludeTags; // Connection was used for object transfer. If we // do another fetch we must open a new connection. // closeConnection(); } else { includedTags = false; } if (tagopt == TagOpt.AUTO_FOLLOW && additionalTags.Count != 0) { // There are more tags that we want to follow, but // not all were asked for on the initial request. foreach (ObjectId key in _askFor.Keys) { _have.Add(key); } _askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.PeeledObjectId; if (id == null || _transport.Local.HasObject(id)) { wantTag(r); } } if (_askFor.Count != 0 && (!includedTags || !askForIsComplete())) { reopenConnection(); if (_askFor.Count != 0) { fetchObjects(monitor); } } } } finally { closeConnection(); } using (RevWalk.RevWalk walk = new RevWalk.RevWalk(_transport.Local)) { if (_transport.RemoveDeletedRefs) { deleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in _localUpdates) { try { u.Update(walk); result.Add(u); } catch (IOException err) { throw new TransportException("Failure updating tracking ref " + u.LocalName + ": " + err.Message, err); } } } if (_fetchHeadUpdates.Count != 0) { try { updateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException("Failure updating FETCH_HEAD: " + err.Message, err); } } }
/// <summary> /// Initialize a new advertisement formatter. /// </summary> /// <param name="protoWalk">the RevWalk used to parse objects that are advertised.</param> /// <param name="advertisedFlag"> /// flag marked on any advertised objects parsed out of the /// <paramref name="protoWalk"/>'s object pool, permitting the caller to /// later quickly determine if an object was advertised (or not). /// </param> public void init(RevWalk.RevWalk protoWalk, RevFlag advertisedFlag) { _walk = protoWalk; ADVERTISED = advertisedFlag; }
public void Update(RevWalk.RevWalk walk) { update.update(walk); }
/// <summary> * Create process for specified transport and refs updates specification. /// * </summary> /// * <param name="transport"> /// * transport between remote and local repository, used to Create /// * connection. </param> /// * <param name="toPush"> /// * specification of refs updates (and local tracking branches). </param> /// * <exception cref="TransportException"> </exception> public PushProcess(Transport transport, IEnumerable<RemoteRefUpdate> toPush) { _walker = new RevWalk.RevWalk(transport.Local); _transport = transport; _toPush = new Dictionary<string, RemoteRefUpdate>(); foreach (RemoteRefUpdate rru in toPush) { if (_toPush.ContainsKey(rru.RemoteName)) { throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName); } _toPush.Add(rru.RemoteName, rru); } }
private void verifyPrerequisites() { if (prereqs.isEmpty()) return; using(RevWalk.RevWalk rw = new RevWalk.RevWalk(transport.Local)) { RevFlag PREREQ = rw.newFlag("PREREQ"); RevFlag SEEN = rw.newFlag("SEEN"); List<ObjectId> missing = new List<ObjectId>(); List<RevObject> commits = new List<RevObject>(); foreach (ObjectId p in prereqs) { try { RevCommit c = rw.parseCommit(p); if (!c.has(PREREQ)) { c.add(PREREQ); commits.Add(c); } } catch (MissingObjectException) { missing.Add(p); } catch (IOException err) { throw new TransportException(transport.Uri, "Cannot Read commit " + p.Name, err); } } if (!missing.isEmpty()) throw new MissingBundlePrerequisiteException(transport.Uri, missing); foreach (Ref r in transport.Local.getAllRefs().Values) { try { rw.markStart(rw.parseCommit(r.ObjectId)); } catch (IOException) { } } int remaining = commits.Count; try { RevCommit c; while ((c = rw.next()) != null) { if (c.has(PREREQ)) { c.add(SEEN); if (--remaining == 0) break; } } } catch (IOException err) { throw new TransportException(transport.Uri, "Cannot Read object", err); } if (remaining > 0) { foreach (RevObject o in commits) { if (!o.has(SEEN)) missing.Add(o); } throw new MissingBundlePrerequisiteException(transport.Uri, missing); } } }
/// <summary> /// Create a new pack upload for an open repository. /// </summary> /// <param name="copyFrom">the source repository.</param> public UploadPack(Repository copyFrom) { _options = new List<string>(); _wantAll = new List<RevObject>(); _wantCommits = new List<RevCommit>(); _commonBase = new List<RevObject>(); _db = copyFrom; _walk = new RevWalk.RevWalk(_db); _walk.setRetainBody(false); ADVERTISED = _walk.newFlag("ADVERTISED"); WANT = _walk.newFlag("WANT"); PEER_HAS = _walk.newFlag("PEER_HAS"); COMMON = _walk.newFlag("COMMON"); _walk.carry(PEER_HAS); SAVE = new RevFlagSet { ADVERTISED, WANT, PEER_HAS }; }