Exemplo n.º 1
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 private bool AskForIsComplete()
 {
     try
     {
         ObjectWalk ow = new ObjectWalk(transport.local);
         try
         {
             foreach (ObjectId want in askFor.Keys)
             {
                 ow.MarkStart(ow.ParseAny(want));
             }
             foreach (Ref @ref in transport.local.GetAllRefs().Values)
             {
                 ow.MarkUninteresting(ow.ParseAny(@ref.GetObjectId()));
             }
             ow.CheckConnectivity();
         }
         finally
         {
             ow.Release();
         }
         return(true);
     }
     catch (MissingObjectException)
     {
         return(false);
     }
     catch (IOException e)
     {
         throw new TransportException(JGitText.Get().unableToCheckConnectivity, e);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Remove all entries from a map which key is the id of an object referenced
        /// by the given ObjectWalk
        /// </summary>
        /// <param name="id2File"></param>
        /// <param name="w"></param>
        /// <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>
        private void RemoveReferenced(IDictionary <ObjectId, FilePath> id2File, ObjectWalk
                                      w)
        {
            RevObject ro = w.Next();

            while (ro != null)
            {
                if (Sharpen.Collections.Remove(id2File, ro.Id) != null)
                {
                    if (id2File.IsEmpty())
                    {
                        return;
                    }
                }
                ro = w.Next();
            }
            ro = w.NextObject();
            while (ro != null)
            {
                if (Sharpen.Collections.Remove(id2File, ro.Id) != null)
                {
                    if (id2File.IsEmpty())
                    {
                        return;
                    }
                }
                ro = w.NextObject();
            }
        }
Exemplo n.º 3
0
 private bool askForIsComplete()
 {
     try
     {
         using (ObjectWalk ow = new ObjectWalk(_transport.Local))
         {
             foreach (ObjectId want in _askFor.Keys)
             {
                 ow.markStart(ow.parseAny(want));
             }
             foreach (Ref @ref in _transport.Local.getAllRefs().Values)
             {
                 ow.markUninteresting(ow.parseAny(@ref.ObjectId));
             }
             ow.checkConnectivity();
             return(true);
         }
     }
     catch (MissingObjectException)
     {
         return(false);
     }
     catch (IOException e)
     {
         throw new TransportException("Unable to check connectivity.", e);
     }
 }
Exemplo n.º 4
0
 public void preparePack <T>(IEnumerable <T> interestingObjects, IEnumerable <T> uninterestingObjects)
     where T : ObjectId
 {
     using (ObjectWalk walker = SetUpWalker(interestingObjects, uninterestingObjects))
     {
         FindObjectsToPack(walker);
     }
 }
Exemplo n.º 5
0
        private void FindObjectsToPack(ObjectWalk walker)
        {
            _initMonitor.BeginTask(COUNTING_OBJECTS_PROGRESS, ProgressMonitor.UNKNOWN);
            RevObject o;

            while ((o = walker.next()) != null)
            {
                addObject(o);
                _initMonitor.Update(1);
            }

            while ((o = walker.nextObject()) != null)
            {
                addObject(o);
                _initMonitor.Update(1);
            }
            _initMonitor.EndTask();
        }
Exemplo n.º 6
0
        private ObjectWalk SetUpWalker <T>(IEnumerable <T> interestingObjects, IEnumerable <T> uninterestingObjects)
            where T : ObjectId
        {
            var walker = new ObjectWalk(_db);

            walker.sort(RevSort.Strategy.TOPO);
            walker.sort(RevSort.Strategy.COMMIT_TIME_DESC, true);

            if (Thin)
            {
                walker.sort(RevSort.Strategy.BOUNDARY, true);
            }

            foreach (T id in interestingObjects)
            {
                RevObject o = walker.parseAny(id);
                walker.markStart(o);
            }

            if (uninterestingObjects != null)
            {
                foreach (T id in uninterestingObjects)
                {
                    RevObject o;

                    try
                    {
                        o = walker.parseAny(id);
                    }
                    catch (MissingObjectException)
                    {
                        if (IgnoreMissingUninteresting)
                        {
                            continue;
                        }
                        throw;
                    }

                    walker.markUninteresting(o);
                }
            }

            return(walker);
        }
Exemplo n.º 7
0
        public static void ObjectWalk(ObjectWalk P)
        {
            MapObject Temp;

            for (int I = 0; I < MapLayer.ObjectList.Count; I++)
            {
                if ((Temp = MapLayer.ObjectList[I]) == MapObject.User)
                {
                    continue;
                }

                if (Temp.ObjectID == P.ObjectID)
                {
                    Temp.QueueAction(MirAction.Walking, P.Location);
                    Temp.ActualLocation = P.Location;
                    return;
                }
            }
        }
Exemplo n.º 8
0
 private void CheckConnectivity()
 {
     using (var ow = new ObjectWalk(db))
     {
         foreach (ReceiveCommand cmd in commands)
         {
             if (cmd.getResult() != ReceiveCommand.Result.NOT_ATTEMPTED)
             {
                 continue;
             }
             if (cmd.getType() == ReceiveCommand.Type.DELETE)
             {
                 continue;
             }
             ow.markStart(ow.parseAny(cmd.getNewId()));
         }
         foreach (Ref @ref in refs.Values)
         {
             ow.markUninteresting(ow.parseAny(@ref.ObjectId));
         }
         ow.checkConnectivity();
     }
 }
Exemplo n.º 9
0
        /// <exception cref="System.IO.IOException"></exception>
        private void SendPack()
        {
            bool sideband = options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K
                                                                                   );
            ProgressMonitor      pm      = NullProgressMonitor.INSTANCE;
            OutputStream         packOut = rawOut;
            SideBandOutputStream msgOut  = null;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (options.Contains(OPTION_SIDE_BAND_64K))
                {
                    bufsz = SideBandOutputStream.MAX_BUF;
                }
                packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut);
                if (!options.Contains(OPTION_NO_PROGRESS))
                {
                    msgOut = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, rawOut
                                                      );
                    pm = new SideBandProgressMonitor(msgOut);
                }
            }
            PackConfig cfg = packConfig;

            if (cfg == null)
            {
                cfg = new PackConfig(db);
            }
            PackWriter pw = new PackWriter(cfg, walk.GetObjectReader());

            try
            {
                pw.SetUseCachedPacks(true);
                pw.SetReuseDeltaCommits(true);
                pw.SetDeltaBaseAsOffset(options.Contains(OPTION_OFS_DELTA));
                pw.SetThin(options.Contains(OPTION_THIN_PACK));
                pw.SetReuseValidatingObjects(false);
                if (commonBase.IsEmpty())
                {
                    ICollection <ObjectId> tagTargets = new HashSet <ObjectId>();
                    foreach (Ref @ref in refs.Values)
                    {
                        if (@ref.GetPeeledObjectId() != null)
                        {
                            tagTargets.AddItem(@ref.GetPeeledObjectId());
                        }
                        else
                        {
                            if (@ref.GetObjectId() == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (@ref.GetName().StartsWith(Constants.R_HEADS))
                                {
                                    tagTargets.AddItem(@ref.GetObjectId());
                                }
                            }
                        }
                    }
                    pw.SetTagTargets(tagTargets);
                }
                RevWalk rw = walk;
                if (wantAll.IsEmpty())
                {
                    pw.PreparePack(pm, wantIds, commonBase);
                }
                else
                {
                    walk.Reset();
                    ObjectWalk ow = walk.ToObjectWalkWithSameObjects();
                    pw.PreparePack(pm, ow, wantAll, commonBase);
                    rw = ow;
                }
                if (options.Contains(OPTION_INCLUDE_TAG))
                {
                    foreach (Ref vref in refs.Values)
                    {
                        Ref      @ref     = vref;
                        ObjectId objectId = @ref.GetObjectId();
                        // If the object was already requested, skip it.
                        if (wantAll.IsEmpty())
                        {
                            if (wantIds.Contains(objectId))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            RevObject obj = rw.LookupOrNull(objectId);
                            if (obj != null && obj.Has(WANT))
                            {
                                continue;
                            }
                        }
                        if ([email protected]())
                        {
                            @ref = db.Peel(@ref);
                        }
                        ObjectId peeledId = @ref.GetPeeledObjectId();
                        if (peeledId == null)
                        {
                            continue;
                        }
                        objectId = @ref.GetObjectId();
                        if (pw.WillInclude(peeledId) && !pw.WillInclude(objectId))
                        {
                            pw.AddObject(rw.ParseAny(objectId));
                        }
                    }
                }
                pw.WritePack(pm, NullProgressMonitor.INSTANCE, packOut);
                statistics = pw.GetStatistics();
                if (msgOut != null)
                {
                    string msg = pw.GetStatistics().GetMessage() + '\n';
                    msgOut.Write(Constants.Encode(msg));
                    msgOut.Flush();
                }
            }
            finally
            {
                pw.Release();
            }
            if (sideband)
            {
                pckOut.End();
            }
            if (logger != null && statistics != null)
            {
                logger.OnPackStatistics(statistics);
            }
        }
Exemplo n.º 10
0
 protected override global::GitSharp.Core.RevWalk.RevWalk createRevWalk()
 {
     return(objw = new ObjectWalk(db));
 }
Exemplo n.º 11
0
        /// <exception cref="System.IO.IOException"></exception>
        private void SendPack()
        {
            bool sideband = options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K
                                                                                   );

            if (!biDirectionalPipe)
            {
                // Ensure the request was fully consumed. Any remaining input must
                // be a protocol error. If we aren't at EOF the implementation is broken.
                int eof = rawIn.Read();
                if (0 <= eof)
                {
                    throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().expectedEOFReceived
                                                                          , "\\x" + Sharpen.Extensions.ToHexString(eof)));
                }
            }
            ProgressMonitor      pm      = NullProgressMonitor.INSTANCE;
            OutputStream         packOut = rawOut;
            SideBandOutputStream msgOut  = null;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (options.Contains(OPTION_SIDE_BAND_64K))
                {
                    bufsz = SideBandOutputStream.MAX_BUF;
                }
                packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut);
                if (!options.Contains(OPTION_NO_PROGRESS))
                {
                    msgOut = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, rawOut
                                                      );
                    pm = new SideBandProgressMonitor(msgOut);
                }
            }
            try
            {
                if (wantAll.IsEmpty())
                {
                    preUploadHook.OnSendPack(this, wantIds, commonBase);
                }
                else
                {
                    preUploadHook.OnSendPack(this, wantAll, commonBase);
                }
            }
            catch (UploadPackMayNotContinueException noPack)
            {
                if (sideband && noPack.Message != null)
                {
                    noPack.SetOutput();
                    SideBandOutputStream err = new SideBandOutputStream(SideBandOutputStream.CH_ERROR
                                                                        , SideBandOutputStream.SMALL_BUF, rawOut);
                    err.Write(Constants.Encode(noPack.Message));
                    err.Flush();
                }
                throw;
            }
            PackConfig cfg = packConfig;

            if (cfg == null)
            {
                cfg = new PackConfig(db);
            }
            PackWriter pw = new PackWriter(cfg, walk.GetObjectReader());

            try
            {
                pw.SetUseCachedPacks(true);
                pw.SetReuseDeltaCommits(true);
                pw.SetDeltaBaseAsOffset(options.Contains(OPTION_OFS_DELTA));
                pw.SetThin(options.Contains(OPTION_THIN_PACK));
                pw.SetReuseValidatingObjects(false);
                if (commonBase.IsEmpty())
                {
                    ICollection <ObjectId> tagTargets = new HashSet <ObjectId>();
                    foreach (Ref @ref in refs.Values)
                    {
                        if (@ref.GetPeeledObjectId() != null)
                        {
                            tagTargets.AddItem(@ref.GetPeeledObjectId());
                        }
                        else
                        {
                            if (@ref.GetObjectId() == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (@ref.GetName().StartsWith(Constants.R_HEADS))
                                {
                                    tagTargets.AddItem(@ref.GetObjectId());
                                }
                            }
                        }
                    }
                    pw.SetTagTargets(tagTargets);
                }
                RevWalk rw = walk;
                if (wantAll.IsEmpty())
                {
                    pw.PreparePack(pm, wantIds, commonBase);
                }
                else
                {
                    walk.Reset();
                    ObjectWalk ow = walk.ToObjectWalkWithSameObjects();
                    pw.PreparePack(pm, ow, wantAll, commonBase);
                    rw = ow;
                }
                if (options.Contains(OPTION_INCLUDE_TAG))
                {
                    foreach (Ref vref in refs.Values)
                    {
                        Ref      @ref     = vref;
                        ObjectId objectId = @ref.GetObjectId();
                        // If the object was already requested, skip it.
                        if (wantAll.IsEmpty())
                        {
                            if (wantIds.Contains(objectId))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            RevObject obj = rw.LookupOrNull(objectId);
                            if (obj != null && obj.Has(WANT))
                            {
                                continue;
                            }
                        }
                        if ([email protected]())
                        {
                            @ref = db.Peel(@ref);
                        }
                        ObjectId peeledId = @ref.GetPeeledObjectId();
                        if (peeledId == null)
                        {
                            continue;
                        }
                        objectId = @ref.GetObjectId();
                        if (pw.WillInclude(peeledId) && !pw.WillInclude(objectId))
                        {
                            pw.AddObject(rw.ParseAny(objectId));
                        }
                    }
                }
                pw.WritePack(pm, NullProgressMonitor.INSTANCE, packOut);
                statistics = pw.GetStatistics();
                if (msgOut != null)
                {
                    string msg = pw.GetStatistics().GetMessage() + '\n';
                    msgOut.Write(Constants.Encode(msg));
                    msgOut.Flush();
                }
            }
            finally
            {
                pw.Release();
            }
            if (sideband)
            {
                pckOut.End();
            }
            if (logger != null && statistics != null)
            {
                logger.OnPackStatistics(statistics);
            }
        }
Exemplo n.º 12
0
 // Do nothing by default, most readers don't want or need advice.
 /// <summary>
 /// Advice from an
 /// <see cref="NGit.Revwalk.ObjectWalk">NGit.Revwalk.ObjectWalk</see>
 /// that trees will be traversed.
 /// </summary>
 /// <param name="ow">the object pool that is using this reader.</param>
 /// <param name="min">the first commit whose root tree will be read.</param>
 /// <param name="max">the last commit whose root tree will be read.</param>
 /// <exception cref="System.IO.IOException">the reader cannot initialize itself to support the walk.
 ///     </exception>
 public virtual void WalkAdviceBeginTrees(ObjectWalk ow, RevCommit min, RevCommit
                                          max)
 {
 }
Exemplo n.º 13
0
        /// <summary>
        /// Like "git prune" this method tries to prune all loose objects which are
        /// unreferenced.
        /// </summary>
        /// <remarks>
        /// Like "git prune" this method tries to prune all loose objects which are
        /// unreferenced. If certain objects can't be pruned (e.g. because the
        /// filesystem delete operation fails) this is silently ignored.
        /// </remarks>
        /// <param name="objectsToKeep">a set of objects which should explicitly not be pruned
        ///     </param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        /// <exception cref="Sharpen.ParseException">
        /// If the configuration parameter "gc.pruneexpire" couldn't be
        /// parsed
        /// </exception>
        public virtual void Prune(ICollection <ObjectId> objectsToKeep)
        {
            long expireDate = long.MaxValue;

            if (expire == null && expireAgeMillis == -1)
            {
                string pruneExpireStr = ((FileBasedConfig)repo.GetConfig()).GetString(ConfigConstants
                                                                                      .CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_PRUNEEXPIRE);
                if (pruneExpireStr == null)
                {
                    pruneExpireStr = PRUNE_EXPIRE_DEFAULT;
                }
                expire          = GitDateParser.Parse(pruneExpireStr, null);
                expireAgeMillis = -1;
            }
            if (expire != null)
            {
                expireDate = expire.Value.GetTime();
            }
            if (expireAgeMillis != -1)
            {
                expireDate = Runtime.CurrentTimeMillis() - expireAgeMillis;
            }
            // Collect all loose objects which are old enough, not referenced from
            // the index and not in objectsToKeep
            IDictionary <ObjectId, FilePath> deletionCandidates = new Dictionary <ObjectId, FilePath
                                                                                  >();
            ICollection <ObjectId> indexObjects = null;
            FilePath objects = repo.ObjectsDirectory;

            string[] fanout = objects.List();
            if (fanout != null && fanout.Length > 0)
            {
                pm.BeginTask(JGitText.Get().pruneLooseUnreferencedObjects, fanout.Length);
                try
                {
                    foreach (string d in fanout)
                    {
                        pm.Update(1);
                        if (d.Length != 2)
                        {
                            continue;
                        }
                        FilePath[] entries = new FilePath(objects, d).ListFiles();
                        if (entries == null)
                        {
                            continue;
                        }
                        foreach (FilePath f in entries)
                        {
                            string fName = f.GetName();
                            if (fName.Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
                            {
                                continue;
                            }
                            if (f.LastModified() >= expireDate)
                            {
                                continue;
                            }
                            try
                            {
                                ObjectId id = ObjectId.FromString(d + fName);
                                if (objectsToKeep.Contains(id))
                                {
                                    continue;
                                }
                                if (indexObjects == null)
                                {
                                    indexObjects = ListNonHEADIndexObjects();
                                }
                                if (indexObjects.Contains(id))
                                {
                                    continue;
                                }
                                deletionCandidates.Put(id, f);
                            }
                            catch (ArgumentException)
                            {
                                // ignoring the file that does not represent loose
                                // object
                                continue;
                            }
                        }
                    }
                }
                finally
                {
                    pm.EndTask();
                }
            }
            if (deletionCandidates.IsEmpty())
            {
                return;
            }
            // From the set of current refs remove all those which have been handled
            // during last repack(). Only those refs will survive which have been
            // added or modified since the last repack. Only these can save existing
            // loose refs from being pruned.
            IDictionary <string, Ref> newRefs;

            if (lastPackedRefs == null || lastPackedRefs.IsEmpty())
            {
                newRefs = GetAllRefs();
            }
            else
            {
                newRefs = new Dictionary <string, Ref>();
                for (Iterator <KeyValuePair <string, Ref> > i = GetAllRefs().EntrySet().Iterator();
                     i.HasNext();)
                {
                    KeyValuePair <string, Ref> newEntry = i.Next();
                    Ref old = lastPackedRefs.Get(newEntry.Key);
                    if (!Equals(newEntry.Value, old))
                    {
                        newRefs.Put(newEntry.Key, newEntry.Value);
                    }
                }
            }
            if (!newRefs.IsEmpty())
            {
                // There are new/modified refs! Check which loose objects are now
                // referenced by these modified refs (or their reflogentries).
                // Remove these loose objects
                // from the deletionCandidates. When the last candidate is removed
                // leave this method.
                ObjectWalk w = new ObjectWalk(repo);
                try
                {
                    foreach (Ref cr in newRefs.Values)
                    {
                        w.MarkStart(w.ParseAny(cr.GetObjectId()));
                    }
                    if (lastPackedRefs != null)
                    {
                        foreach (Ref lpr in lastPackedRefs.Values)
                        {
                            w.MarkUninteresting(w.ParseAny(lpr.GetObjectId()));
                        }
                    }
                    RemoveReferenced(deletionCandidates, w);
                }
                finally
                {
                    w.Dispose();
                }
            }
            if (deletionCandidates.IsEmpty())
            {
                return;
            }
            // Since we have not left the method yet there are still
            // deletionCandidates. Last chance for these objects not to be pruned is
            // that they are referenced by reflog entries. Even refs which currently
            // point to the same object as during last repack() may have
            // additional reflog entries not handled during last repack()
            ObjectWalk w_1 = new ObjectWalk(repo);

            try
            {
                foreach (Ref ar in GetAllRefs().Values)
                {
                    foreach (ObjectId id in ListRefLogObjects(ar, lastRepackTime))
                    {
                        w_1.MarkStart(w_1.ParseAny(id));
                    }
                }
                if (lastPackedRefs != null)
                {
                    foreach (Ref lpr in lastPackedRefs.Values)
                    {
                        w_1.MarkUninteresting(w_1.ParseAny(lpr.GetObjectId()));
                    }
                }
                RemoveReferenced(deletionCandidates, w_1);
            }
            finally
            {
                w_1.Dispose();
            }
            if (deletionCandidates.IsEmpty())
            {
                return;
            }
            // delete all candidates which have survived: these are unreferenced
            // loose objects
            foreach (FilePath f_1 in deletionCandidates.Values)
            {
                f_1.Delete();
            }
            ((ObjectDirectory)repo.ObjectDatabase).Close();
        }