Example #1
0
        ///	<summary>
        /// Create an iterator to walk the merge base of two commits.
        /// </summary>
        /// <param name="aIdx">
        /// Index of the first commit in <seealso cref="SourceObjects"/>.
        /// </param>
        /// <param name="bIdx">
        /// Index of the second commit in <seealso cref="SourceObjects"/>.
        /// </param>
        /// <returns> the new iterator </returns>
        /// <exception cref="IncorrectObjectTypeException">
        /// one of the input objects is not a commit.
        /// </exception>
        /// <exception cref="IOException">
        /// objects are missing or multiple merge bases were found.
        /// </exception>
        protected AbstractTreeIterator MergeBase(int aIdx, int bIdx)
        {
            if (_sourceCommits[aIdx] == null)
            {
                throw new IncorrectObjectTypeException(_sourceObjects[aIdx], Constants.TYPE_COMMIT);
            }

            if (_sourceCommits[bIdx] == null)
            {
                throw new IncorrectObjectTypeException(_sourceObjects[bIdx], Constants.TYPE_COMMIT);
            }

            _walk.reset();
            _walk.setRevFilter(RevFilter.MERGE_BASE);
            _walk.markStart(_sourceCommits[aIdx]);
            _walk.markStart(_sourceCommits[bIdx]);
            RevCommit base1 = _walk.next();

            if (base1 == null)
            {
                return(new EmptyTreeIterator());
            }

            RevCommit base2 = _walk.next();

            if (base2 != null)
            {
                throw new IOException("Multiple merge bases for:" + "\n  "
                                      + _sourceCommits[aIdx].Name + "\n  "
                                      + _sourceCommits[bIdx].Name + "found:" + "\n  "
                                      + base1.Name + "\n  " + base2.Name);
            }

            return(OpenTree(base1.Tree));
        }
        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
        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);
                    }
                }
            }
        }
Example #4
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(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);
                }
            }
        }
        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 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 #8
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);
                }
            }
        }