Beispiel #1
0
        /// <summary>
        /// Generate an advertisement of available refs and capabilities.
        /// </summary>
        /// <param name="adv">the advertisement formatter.</param>
        public void SendAdvertisedRefs(RefAdvertiser adv)
        {
            RevFlag advertised = walk.newFlag("ADVERTISED");

            adv.init(walk, advertised);
            adv.advertiseCapability(BasePackPushConnection.CAPABILITY_SIDE_BAND_64K);
            adv.advertiseCapability(BasePackPushConnection.CAPABILITY_DELETE_REFS);
            adv.advertiseCapability(BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            if (allowOfsDelta)
            {
                adv.advertiseCapability(BasePackPushConnection.CAPABILITY_OFS_DELTA);
            }
            refs = refFilter.filter(db.getAllRefs());
            Ref head = refs.remove(Constants.HEAD);

            adv.send(refs);
            if (head != null && !head.isSymbolic())
            {
                adv.advertiseHave(head.ObjectId);
            }
            adv.includeAdditionalHaves();
            if (adv.isEmpty())
            {
                adv.advertiseId(ObjectId.ZeroId, "capabilities^{}");
            }
            adv.end();
        }
        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>();
        }
Beispiel #3
0
 internal WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w)
 {
     NGit.Transport.Transport wt = (NGit.Transport.Transport)t;
     local    = wt.local;
     objCheck = wt.IsCheckFetchedObjects() ? new ObjectChecker() : null;
     inserter = local.NewObjectInserter();
     reader   = local.NewObjectReader();
     remotes  = new AList <WalkRemoteObjectDatabase>();
     remotes.AddItem(w);
     unfetchedPacks  = new List <WalkFetchConnection.RemotePack>();
     packsConsidered = new HashSet <string>();
     noPacksYet      = new List <WalkRemoteObjectDatabase>();
     noPacksYet.AddItem(w);
     noAlternatesYet = new List <WalkRemoteObjectDatabase>();
     noAlternatesYet.AddItem(w);
     fetchErrors = new Dictionary <ObjectId, IList <Exception> >();
     packLocks   = new AList <PackLock>(4);
     revWalk     = new RevWalk(reader);
     revWalk.SetRetainBody(false);
     treeWalk         = new TreeWalk(reader);
     COMPLETE         = revWalk.NewFlag("COMPLETE");
     IN_WORK_QUEUE    = revWalk.NewFlag("IN_WORK_QUEUE");
     LOCALLY_SEEN     = revWalk.NewFlag("LOCALLY_SEEN");
     localCommitQueue = new DateRevQueue();
     workQueue        = new List <ObjectId>();
 }
Beispiel #4
0
        /// <summary>Create a new filter that tests for a single flag.</summary>
        /// <remarks>Create a new filter that tests for a single flag.</remarks>
        /// <param name="a">the flag to test.</param>
        /// <returns>filter that selects only commits with flag <code>a</code>.</returns>
        public static RevFilter Has(RevFlag a)
        {
            RevFlagSet s = new RevFlagSet();

            s.AddItem(a);
            return(new RevFlagFilter.HasAll(s));
        }
        /// <summary>
        /// Create a new filter that tests for a single flag.
        ///	</summary>
        /// <param name="a">The flag to test.</param>
        ///	<returns>
        /// Filter that selects only commits with flag <paramref name="a"/>.
        /// </returns>
        public static RevFilter has(RevFlag a)
        {
            var s = new RevFlagSet {
                a
            };

            return(new HasAll(s));
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
        public void testRemoveRevFlag()
        {
            RevCommit a     = Commit();
            RevFlag   flag1 = rw.newFlag("flag1");
            RevFlag   flag2 = rw.newFlag("flag2");

            a.add(flag1);
            a.add(flag2);
            Assert.AreEqual(flag1.Mask | flag2.Mask, a.Flags);
            a.remove(flag2);
            Assert.AreEqual(flag1.Mask, a.Flags);
        }
Beispiel #8
0
        public void testEquals()
        {
            RevFlag flag1   = rw.newFlag("flag_1");
            RevFlag flag2   = rw.newFlag("flag_2");
            var     flagSet = new RevFlagSet();

            Assert.IsTrue(flagSet.Add(flag1));
            Assert.IsTrue(flagSet.Add(flag2));

            Assert.IsTrue(new RevFlagSet(flagSet).Equals(flagSet));
            Assert.IsTrue(new RevFlagSet(new[] { flag1, flag2 }).Equals(flagSet));
        }
Beispiel #9
0
        public virtual void testContains()
        {
            RevFlag flag1   = rw.newFlag("flag_1");
            RevFlag flag2   = rw.newFlag("flag_2");
            var     flagSet = new RevFlagSet {
                flag1
            };

            Assert.IsTrue(flagSet.Contains(flag1));
            Assert.IsFalse(flagSet.Contains(flag2));
            //Assert.IsFalse(flagSet.Contains("bob"));
        }
Beispiel #10
0
        public void testHasAnyFlag()
        {
            RevCommit a     = Commit();
            RevFlag   flag1 = rw.newFlag("flag1");
            RevFlag   flag2 = rw.newFlag("flag2");
            var       s     = new RevFlagSet {
                flag1, flag2
            };

            Assert.IsFalse(a.hasAny(s));
            a.Flags |= flag1.Mask;
            Assert.IsTrue(a.hasAny(s));
        }
Beispiel #11
0
        public void testAddTwo()
        {
            RevFlag flag1 = rw.newFlag("flag_1");
            RevFlag flag2 = rw.newFlag("flag_2");

            Assert.IsTrue((flag1.Mask & flag2.Mask) == 0);

            var flagSet = new RevFlagSet();

            Assert.IsTrue(flagSet.Add(flag1));
            Assert.IsTrue(flagSet.Add(flag2));
            Assert.AreEqual(flag1.Mask | flag2.Mask, flagSet.Mask);
            Assert.AreEqual(2, flagSet.Count);
        }
Beispiel #12
0
        public virtual void testRemove()
        {
            RevFlag flag1   = rw.newFlag("flag_1");
            RevFlag flag2   = rw.newFlag("flag_2");
            var     flagSet = new RevFlagSet();

            Assert.IsTrue(flagSet.Add(flag1));
            Assert.IsTrue(flagSet.Add(flag2));

            Assert.IsTrue(flagSet.Remove(flag1));
            Assert.IsFalse(flagSet.Remove(flag1));
            Assert.AreEqual(flag2.Mask, flagSet.Mask);
            Assert.IsFalse(flagSet.Contains(flag1));
        }
Beispiel #13
0
        public void testAddRevFlagSet()
        {
            RevCommit a     = Commit();
            RevFlag   flag1 = rw.newFlag("flag1");
            RevFlag   flag2 = rw.newFlag("flag2");
            var       s     = new RevFlagSet {
                flag1, flag2
            };

            Assert.AreEqual(0, a.Flags);

            a.add(s);
            Assert.AreEqual(flag1.Mask | flag2.Mask, a.Flags);
        }
Beispiel #14
0
        public void testRemoveRevFlagSet()
        {
            RevCommit a     = Commit();
            RevFlag   flag1 = rw.newFlag("flag1");
            RevFlag   flag2 = rw.newFlag("flag2");
            RevFlag   flag3 = rw.newFlag("flag3");
            var       s     = new RevFlagSet {
                flag1, flag2
            };

            a.add(flag3);
            a.add(s);
            Assert.AreEqual(flag1.Mask | flag2.Mask | flag3.Mask, a.Flags);
            a.remove(s);
            Assert.AreEqual(flag3.Mask, a.Flags);
        }
Beispiel #15
0
 /// <summary>Create a new pack upload for an open repository.</summary>
 /// <remarks>Create a new pack upload for an open repository.</remarks>
 /// <param name="copyFrom">the source repository.</param>
 public UploadPack(Repository copyFrom)
 {
     db   = copyFrom;
     walk = new RevWalk(db);
     walk.SetRetainBody(false);
     WANT      = walk.NewFlag("WANT");
     PEER_HAS  = walk.NewFlag("PEER_HAS");
     COMMON    = walk.NewFlag("COMMON");
     SATISFIED = walk.NewFlag("SATISFIED");
     walk.Carry(PEER_HAS);
     SAVE = new RevFlagSet();
     SAVE.AddItem(WANT);
     SAVE.AddItem(PEER_HAS);
     SAVE.AddItem(COMMON);
     SAVE.AddItem(SATISFIED);
     refFilter = RefFilter.DEFAULT;
 }
Beispiel #16
0
        ///	<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;
        }
Beispiel #17
0
        public void testContainsAll()
        {
            RevFlag flag1 = rw.newFlag("flag_1");
            RevFlag flag2 = rw.newFlag("flag_2");
            var     set1  = new RevFlagSet();

            Assert.IsTrue(set1.Add(flag1));
            Assert.IsTrue(set1.Add(flag2));

            Assert.IsTrue(set1.ContainsAll(set1));
            Assert.IsTrue(set1.ContainsAll(new[] { flag1, flag2 }));

            var set2 = new RevFlagSet {
                rw.newFlag("flag_3")
            };

            Assert.IsFalse(set1.ContainsAll(set2));
        }
Beispiel #18
0
 /// <summary>Create a new connection to fetch using the native git transport.</summary>
 /// <remarks>Create a new connection to fetch using the native git transport.</remarks>
 /// <param name="packTransport">the transport.</param>
 internal BasePackFetchConnection(PackTransport packTransport) : base(packTransport
                                                                      )
 {
     BasePackFetchConnection.FetchConfig cfg = local.GetConfig().Get(BasePackFetchConnection.FetchConfig
                                                                     .KEY);
     includeTags      = transport.GetTagOpt() != TagOpt.NO_TAGS;
     thinPack         = transport.IsFetchThin();
     allowOfsDelta    = cfg.allowOfsDelta;
     walk             = new RevWalk(local);
     reachableCommits = new RevCommitList <RevCommit>();
     REACHABLE        = walk.NewFlag("REACHABLE");
     COMMON           = walk.NewFlag("COMMON");
     STATE            = walk.NewFlag("STATE");
     ADVERTISED       = walk.NewFlag("ADVERTISED");
     walk.Carry(COMMON);
     walk.Carry(REACHABLE);
     walk.Carry(ADVERTISED);
 }
        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);
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        public void testAddOne()
        {
            const string flagName = "flag";
            RevFlag      flag     = rw.newFlag(flagName);

            Assert.IsTrue(0 != flag.Mask);
            Assert.AreSame(flagName, flag.Name);

            var flagSet = new RevFlagSet();

            Assert.IsTrue(flagSet.Add(flag));
            Assert.IsFalse(flagSet.Add(flag));
            Assert.AreEqual(flag.Mask, flagSet.Mask);
            Assert.AreEqual(1, flagSet.Count);
            var i = flagSet.GetEnumerator();

            Assert.IsTrue(i.MoveNext());
            Assert.AreSame(flag, i.Current);
            Assert.IsFalse(i.MoveNext());
        }
Beispiel #22
0
        ///	<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
            };
        }
Beispiel #23
0
 private void InitRevPool(bool reverse)
 {
     if (queue != null)
     {
         throw new InvalidOperationException();
     }
     if (revPool != null)
     {
         revPool.Release();
     }
     if (reverse)
     {
         revPool = new ReverseWalk(GetRepository());
     }
     else
     {
         revPool = new RevWalk(GetRepository());
     }
     revPool.SetRetainBody(true);
     SEEN     = revPool.NewFlag("SEEN");
     reader   = revPool.GetObjectReader();
     treeWalk = new TreeWalk(reader);
 }
 /// <param name="repo">Repository to walk</param>
 /// <param name="depth">Maximum depth to return</param>
 public ObjectWalk(Repository repo, int depth) : base(repo)
 {
     this.depth         = depth;
     this.UNSHALLOW     = NewFlag("UNSHALLOW");
     this.REINTERESTING = NewFlag("REINTERESTING");
 }
 /// <param name="or">Object Reader</param>
 /// <param name="depth">Maximum depth to return</param>
 public ObjectWalk(ObjectReader or, int depth) : base(or)
 {
     this.depth         = depth;
     this.UNSHALLOW     = NewFlag("UNSHALLOW");
     this.REINTERESTING = NewFlag("REINTERESTING");
 }
Beispiel #26
0
 internal override void Add(RevFlag flag)
 {
 }
Beispiel #27
0
 internal virtual void Add(RevFlag flag)
 {
     sourceCommit.Add(flag);
 }
 /// <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;
 }
Beispiel #29
0
 public NegotiateBeginRevFilter(RevFlag c, RevFlag a)
 {
     _common     = c;
     _advertised = a;
 }
Beispiel #30
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void VerifyPrerequisites()
        {
            if (prereqs.IsEmpty())
            {
                return;
            }
            RevWalk rw = new RevWalk(transport.local);

            try
            {
                RevFlag PREREQ = rw.NewFlag("PREREQ");
                RevFlag SEEN   = rw.NewFlag("SEEN");
                IDictionary <ObjectId, string> missing = new Dictionary <ObjectId, string>();
                IList <RevObject> commits = new AList <RevObject>();
                foreach (KeyValuePair <ObjectId, string> e in prereqs.EntrySet())
                {
                    ObjectId p = e.Key;
                    try
                    {
                        RevCommit c = rw.ParseCommit(p);
                        if (!c.Has(PREREQ))
                        {
                            c.Add(PREREQ);
                            commits.AddItem(c);
                        }
                    }
                    catch (MissingObjectException)
                    {
                        missing.Put(p, e.Value);
                    }
                    catch (IOException err)
                    {
                        throw new TransportException(transport.uri, MessageFormat.Format(JGitText.Get().cannotReadCommit
                                                                                         , 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.GetObjectId()));
                    }
                    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, JGitText.Get().cannotReadObject, 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);
                }
            }
            finally
            {
                rw.Release();
            }
        }
Beispiel #31
0
 /**
  * Create a new filter that tests for a single flag.
  *
  * @param a
  *            the flag to test.
  * @return filter that selects only commits with flag <code>a</code>.
  */
 public static RevFilter has(RevFlag a)
 {
     RevFlagSet s = new RevFlagSet();
     s.Add(a);
     return new HasAll(s);
 }
Beispiel #32
0
		/// <summary>
		/// Create a new filter that tests for a single flag.
		///	</summary>
		/// <param name="a">The flag to test.</param>
		///	<returns>
		/// Filter that selects only commits with flag <paramref name="a"/>.
		/// </returns>
		public static RevFilter has(RevFlag a)
		{
			var s = new RevFlagSet { a };
			return new HasAll(s);
		}