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);
                    }
                }
            }
        }
Exemple #2
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);
                    }
                }
            }
        }
Exemple #3
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));
        }