Пример #1
0
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 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);
 }
Пример #2
0
 /// <exception cref="System.IO.IOException"></exception>
 private void MarkReachable(ICollection <ObjectId> have, int maxTime)
 {
     foreach (Ref r in local.GetAllRefs().Values)
     {
         try
         {
             RevCommit o = walk.ParseCommit(r.GetObjectId());
             o.Add(REACHABLE);
             reachableCommits.AddItem(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.AddItem(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 = Sharpen.Extensions.CreateDate(maxTime * 1000L);
         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))
             {
                 // This is actually going to be a common commit, but
                 // our peer doesn't know that fact yet.
                 //
                 c.Add(COMMON);
                 c.Carry(COMMON);
                 reachableCommits.AddItem(c);
             }
         }
     }
 }
Пример #3
0
 /// <exception cref="System.IO.IOException"></exception>
 private void MarkReachable(ICollection <ObjectId> have, int maxTime)
 {
     foreach (Ref r in local.GetAllRefs().Values)
     {
         ObjectId id = r.GetPeeledObjectId();
         if (id == null)
         {
             id = r.GetObjectId();
         }
         if (id == null)
         {
             continue;
         }
         ParseReachable(id);
     }
     foreach (ObjectId id_1 in local.GetAdditionalHaves())
     {
         ParseReachable(id_1);
     }
     foreach (ObjectId id_2 in have)
     {
         ParseReachable(id_2);
     }
     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 = Sharpen.Extensions.CreateDate(maxTime * 1000L);
         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))
             {
                 // This is actually going to be a common commit, but
                 // our peer doesn't know that fact yet.
                 //
                 c.Add(COMMON);
                 c.Carry(COMMON);
                 reachableCommits.AddItem(c);
             }
         }
     }
 }
Пример #4
0
            public override bool Include(RevWalk walker, RevCommit c)
            {
                bool remoteKnowsIsCommon = c.Has(this._enclosing.COMMON);

                if (c.Has(this._enclosing.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.
                    //
                    c.Add(this._enclosing.COMMON);
                }
                return(!remoteKnowsIsCommon);
            }
Пример #5
0
 private void ParseReachable(ObjectId id)
 {
     try
     {
         RevCommit o = walk.ParseCommit(id);
         if (!o.Has(REACHABLE))
         {
             o.Add(REACHABLE);
             reachableCommits.AddItem(o);
         }
     }
     catch (IOException)
     {
     }
 }
Пример #6
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();
            }
        }