Exemplo n.º 1
0
 /// <exception cref="System.IO.IOException"></exception>
 private bool WantSatisfied(RevObject want)
 {
     if (want.Has(SATISFIED))
     {
         return(true);
     }
     walk.ResetRetain(SAVE);
     walk.MarkStart((RevCommit)want);
     if (oldestTime != 0)
     {
         walk.SetRevFilter(CommitTimeRevFilter.After(oldestTime * 1000L));
     }
     for (; ;)
     {
         RevCommit c = walk.Next();
         if (c == null)
         {
             break;
         }
         if (c.Has(PEER_HAS))
         {
             AddCommonBase(c);
             want.Add(SATISFIED);
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Find the list of branches a given commit is reachable from when following
        /// parent.s
        /// <p>
        /// Note that this method calls
        /// <see cref="RevWalk.Reset()">RevWalk.Reset()</see>
        /// at the beginning.
        /// <p>
        /// In order to improve performance this method assumes clock skew among
        /// committers is never larger than 24 hours.
        /// </summary>
        /// <param name="commit">the commit we are looking at</param>
        /// <param name="revWalk">The RevWalk to be used.</param>
        /// <param name="refs">the set of branches we want to see reachability from</param>
        /// <returns>the list of branches a given commit is reachable from</returns>
        /// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
        ///     </exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException">NGit.Errors.IncorrectObjectTypeException
        ///     </exception>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static IList <Ref> FindBranchesReachableFrom(RevCommit commit, RevWalk revWalk
                                                            , ICollection <Ref> refs)
        {
            IList <Ref> result = new AList <Ref>();

            // searches from branches can be cut off early if any parent of the
            // search-for commit is found. This is quite likely, so optimize for this.
            revWalk.MarkStart(Arrays.AsList(commit.Parents));
            ObjectIdSubclassMap <ObjectId> cutOff = new ObjectIdSubclassMap <ObjectId>();
            int SKEW = 24 * 3600;

            // one day clock skew
            foreach (Ref @ref in refs)
            {
                RevObject maybehead = revWalk.ParseAny(@ref.GetObjectId());
                if (!(maybehead is RevCommit))
                {
                    continue;
                }
                RevCommit headCommit = (RevCommit)maybehead;
                // if commit is in the ref branch, then the tip of ref should be
                // newer than the commit we are looking for. Allow for a large
                // clock skew.
                if (headCommit.CommitTime + SKEW < commit.CommitTime)
                {
                    continue;
                }
                IList <ObjectId> maybeCutOff = new AList <ObjectId>(cutOff.Size());
                // guess rough size
                revWalk.ResetRetain();
                revWalk.MarkStart(headCommit);
                RevCommit current;
                Ref       found = null;
                while ((current = revWalk.Next()) != null)
                {
                    if (AnyObjectId.Equals(current, commit))
                    {
                        found = @ref;
                        break;
                    }
                    if (cutOff.Contains(current))
                    {
                        break;
                    }
                    maybeCutOff.AddItem(current.ToObjectId());
                }
                if (found != null)
                {
                    result.AddItem(@ref);
                }
                else
                {
                    foreach (ObjectId id in maybeCutOff)
                    {
                        cutOff.AddIfAbsent(id);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Find the list of branches a given commit is reachable from when following
		/// parent.s
		/// <p>
		/// Note that this method calls
		/// <see cref="RevWalk.Reset()">RevWalk.Reset()</see>
		/// at the beginning.
		/// <p>
		/// In order to improve performance this method assumes clock skew among
		/// committers is never larger than 24 hours.
		/// </summary>
		/// <param name="commit">the commit we are looking at</param>
		/// <param name="revWalk">The RevWalk to be used.</param>
		/// <param name="refs">the set of branches we want to see reachability from</param>
		/// <returns>the list of branches a given commit is reachable from</returns>
		/// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
		/// 	</exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">NGit.Errors.IncorrectObjectTypeException
		/// 	</exception>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public static IList<Ref> FindBranchesReachableFrom(RevCommit commit, RevWalk revWalk
			, ICollection<Ref> refs)
		{
			IList<Ref> result = new AList<Ref>();
			// searches from branches can be cut off early if any parent of the
			// search-for commit is found. This is quite likely, so optimize for this.
			revWalk.MarkStart(Arrays.AsList(commit.Parents));
			ObjectIdSubclassMap<ObjectId> cutOff = new ObjectIdSubclassMap<ObjectId>();
			int SKEW = 24 * 3600;
			// one day clock skew
			foreach (Ref @ref in refs)
			{
				RevObject maybehead = revWalk.ParseAny(@ref.GetObjectId());
				if (!(maybehead is RevCommit))
				{
					continue;
				}
				RevCommit headCommit = (RevCommit)maybehead;
				// if commit is in the ref branch, then the tip of ref should be
				// newer than the commit we are looking for. Allow for a large
				// clock skew.
				if (headCommit.CommitTime + SKEW < commit.CommitTime)
				{
					continue;
				}
				IList<ObjectId> maybeCutOff = new AList<ObjectId>(cutOff.Size());
				// guess rough size
				revWalk.ResetRetain();
				revWalk.MarkStart(headCommit);
				RevCommit current;
				Ref found = null;
				while ((current = revWalk.Next()) != null)
				{
					if (AnyObjectId.Equals(current, commit))
					{
						found = @ref;
						break;
					}
					if (cutOff.Contains(current))
					{
						break;
					}
					maybeCutOff.AddItem(current.ToObjectId());
				}
				if (found != null)
				{
					result.AddItem(@ref);
				}
				else
				{
					foreach (ObjectId id in maybeCutOff)
					{
						cutOff.AddIfAbsent(id);
					}
				}
			}
			return result;
		}