Example #1
0
        public void testHasRevFlag()
        {
            RevCommit a = Commit();

            Assert.IsFalse(a.has(RevFlag.UNINTERESTING));
            a.Flags |= GitSharp.Core.RevWalk.RevWalk.UNINTERESTING;
            Assert.IsTrue(a.has(RevFlag.UNINTERESTING));
        }
        private void MarkReachable(IEnumerable <ObjectId> have, int maxTime)
        {
            foreach (Ref r in local.getAllRefs().Values)
            {
                try
                {
                    RevCommit o = _walk.parseCommit(r.ObjectId);
                    o.add(REACHABLE);
                    _reachableCommits.add(o);
                }
                catch (IOException)
                {
                    // If we cannot read the value of the ref skip it.
                }
            }

            foreach (ObjectId id in have)
            {
                try
                {
                    RevCommit o = _walk.parseCommit(id);
                    o.add(REACHABLE);
                    _reachableCommits.add(o);
                }
                catch (IOException)
                {
                    // If we cannot read the value of the ref skip it.
                }
            }

            if (maxTime > 0)
            {
                // Mark reachable commits until we reach maxTime. These may
                // wind up later matching up against things we want and we
                // can avoid asking for something we already happen to have.
                //
                DateTime maxWhen = (maxTime * 1000L).MillisToUtcDateTime();
                _walk.sort(RevSort.COMMIT_TIME_DESC);
                _walk.markStart(_reachableCommits);
                _walk.setRevFilter(CommitTimeRevFilter.After(maxWhen));
                for (; ;)
                {
                    RevCommit c = _walk.next();
                    if (c == null)
                    {
                        break;
                    }
                    if (c.has(ADVERTISED) && !c.has(COMMON))
                    {
                        c.add(COMMON);
                        c.carry(COMMON);
                        _reachableCommits.add(c);
                    }
                }
            }
        }
Example #3
0
            public override bool include(GitSharp.Core.RevWalk.RevWalk walker, RevCommit cmit)
            {
                bool remoteKnowsIsCommon = cmit.has(_common);

                if (cmit.has(_advertised))
                {
                    cmit.add(_common);
                }
                return(!remoteKnowsIsCommon);
            }
Example #4
0
        private void MarkReachable(IEnumerable <ObjectId> have, int maxTime)
        {
            foreach (Ref r in local.getAllRefs().Values)
            {
                try
                {
                    RevCommit o = _walk.parseCommit(r.ObjectId);
                    o.add(REACHABLE);
                    _reachableCommits.add(o);
                }
                catch (IOException)
                {
                }
            }

            foreach (ObjectId id in have)
            {
                try
                {
                    RevCommit o = _walk.parseCommit(id);
                    o.add(REACHABLE);
                    _reachableCommits.add(o);
                }
                catch (IOException)
                {
                }
            }

            if (maxTime > 0)
            {
                DateTime maxWhen = new DateTime(1970, 1, 1) + TimeSpan.FromSeconds(maxTime);
                _walk.sort(RevSort.COMMIT_TIME_DESC);
                _walk.markStart(_reachableCommits);
                _walk.setRevFilter(CommitTimeRevFilter.After(maxWhen));
                for (; ;)
                {
                    RevCommit c = _walk.next();
                    if (c == null)
                    {
                        break;
                    }
                    if (c.has(ADVERTISED) && !c.has(COMMON))
                    {
                        c.add(COMMON);
                        c.carry(COMMON);
                        _reachableCommits.add(c);
                    }
                }
            }
        }
            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);
            }
Example #6
0
        public void testCull()
        {
            RevBlob f1 = blob("1");
            RevBlob f2 = blob("2");
            RevBlob f3 = blob("3");
            RevBlob f4 = blob("4");

            RevTree   ta = tree(File("a/1", f1), File("c/3", f3));
            RevCommit a  = Commit(ta);

            RevTree   tb = tree(File("a/1", f2), File("c/3", f3));
            RevCommit b1 = Commit(tb, a);
            RevCommit b2 = Commit(tb, b1);

            RevTree   tc = tree(File("a/1", f4));
            RevCommit c1 = Commit(tc, a);
            RevCommit c2 = Commit(tc, c1);

            MarkStart(b2);
            MarkUninteresting(c2);

            AssertCommit(b2, objw.next());
            AssertCommit(b1, objw.next());
            Assert.IsNull(objw.next());

            Assert.IsTrue(a.has(RevFlag.UNINTERESTING));
            Assert.IsTrue(ta.has(RevFlag.UNINTERESTING));
            Assert.IsTrue(f1.has(RevFlag.UNINTERESTING));
            Assert.IsTrue(f3.has(RevFlag.UNINTERESTING));

            Assert.AreSame(tb, objw.nextObject());
            Assert.AreSame(get(tb, "a"), objw.nextObject());
            Assert.AreSame(f2, objw.nextObject());
            Assert.IsNull(objw.nextObject());
        }
 private void PushLocalCommit(RevCommit p)
 {
     if (p.has(LOCALLY_SEEN))
     {
         return;
     }
     _revWalk.parseHeaders(p);
     p.add(LOCALLY_SEEN);
     p.add(COMPLETE);
     p.carry(COMPLETE);
     _localCommitQueue.add(p);
 }
Example #8
0
        private bool WantSatisfied(RevCommit want)
        {
            _walk.resetRetain(SAVE);
            _walk.markStart(want);

            while (true)
            {
                RevCommit c = _walk.next();
                if (c == null)
                {
                    break;
                }
                if (c.has(PEER_HAS))
                {
                    AddCommonBase(c);
                    return(true);
                }
            }
            return(false);
        }
        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);
                }
            }
        }
Example #10
0
        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);
                }
            }
        }