Esempio n. 1
0
 private void CreateVerifyOpenPack(IEnumerable <ObjectId> interestings,
                                   IEnumerable <ObjectId> uninterestings, bool thin, bool ignoreMissingUninteresting)
 {
     _writer.Thin = thin;
     _writer.IgnoreMissingUninteresting = ignoreMissingUninteresting;
     _writer.preparePack(interestings, uninterestings);
     _writer.writePack(_cos);
     VerifyOpenPack(thin);
 }
Esempio n. 2
0
        private void writePack(IDictionary <string, RemoteRefUpdate> refUpdates, ProgressMonitor monitor)
        {
            PackWriter      writer        = new PackWriter(local, monitor);
            List <ObjectId> remoteObjects = new List <ObjectId>(Refs.Count);
            List <ObjectId> newObjects    = new List <ObjectId>(refUpdates.Count);

            foreach (Ref r in Refs)
            {
                remoteObjects.Add(r.ObjectId);
            }

            remoteObjects.AddRange(additionalHaves);
            foreach (RemoteRefUpdate r in refUpdates.Values)
            {
                if (!ObjectId.ZeroId.Equals(r.NewObjectId))
                {
                    newObjects.Add(r.NewObjectId);
                }
            }

            writer.Thin = _thinPack;
            writer.DeltaBaseAsOffset = _capableOfsDelta;
            writer.preparePack(newObjects, remoteObjects);
            writer.writePack(outStream);
        }
Esempio n. 3
0
        /**
         * Generate and write the bundle to the output stream.
         * <para />
         * This method can only be called once per BundleWriter instance.
         *
         * @param os
         *            the stream the bundle is written to. If the stream is not
         *            buffered it will be buffered by the writer. Caller is
         *            responsible for closing the stream.
         * @throws IOException
         *             an error occurred reading a local object's data to include in
         *             the bundle, or writing compressed object data to the output
         *             stream.
         */
        public void writeBundle(Stream os)
        {
            if (!(os is BufferedStream))
            {
                os = new BufferedStream(os);
            }

            var inc = new HashSet <ObjectId>();
            var exc = new HashSet <ObjectId>();

            foreach (ObjectId objectId in _include.Values)
            {
                inc.Add(objectId);
            }

            foreach (RevCommit r in _assume)
            {
                exc.Add(r.getId());
            }

            _packWriter.Thin = exc.Count > 0;
            _packWriter.preparePack(inc, exc);

            //var w = new BinaryWriter(os);
            //var w = new StreamWriter(os, Constants.CHARSET);
            var w = os;

            writeString(w, Constants.V2_BUNDLE_SIGNATURE);
            writeString(w, "\n");

            char[] tmp = new char[Constants.OBJECT_ID_LENGTH * 2];
            foreach (RevCommit a in _assume)
            {
                writeString(w, "-");
                a.CopyTo(tmp, Constants.CHARSET, w);
                if (a.RawBuffer != null)
                {
                    writeString(w, " ");
                    writeString(w, a.getShortMessage());
                }
                writeString(w, "\n");
            }

            foreach (var entry in _include)
            {
                entry.Value.CopyTo(tmp, Constants.CHARSET, w);
                writeString(w, " ");
                writeString(w, entry.Key);
                writeString(w, "\n");
            }

            writeString(w, "\n");
            w.Flush();

            _packWriter.writePack(os);
        }
        private void writePack(IDictionary<string, RemoteRefUpdate> refUpdates, ProgressMonitor monitor)
        {
            PackWriter writer = new PackWriter(local, monitor);
            List<ObjectId> remoteObjects = new List<ObjectId>(Refs.Count);
            List<ObjectId> newObjects = new List<ObjectId>(refUpdates.Count);

            foreach (Ref r in Refs)
                remoteObjects.Add(r.ObjectId);

            remoteObjects.AddRange(additionalHaves);
            foreach (RemoteRefUpdate r in refUpdates.Values)
            {
                if (!ObjectId.ZeroId.Equals(r.NewObjectId))
                    newObjects.Add(r.NewObjectId);
            }

            writer.Thin = _thinPack;
            writer.DeltaBaseAsOffset = _capableOfsDelta;
            writer.preparePack(newObjects, remoteObjects);
            long start = SystemReader.getInstance().getCurrentTime();
            writer.writePack(outStream);
            packTransferTime = SystemReader.getInstance().getCurrentTime() - start;
        }
Esempio n. 5
0
        private void sendPack()
        {
            bool thin = options.Contains(OPTION_THIN_PACK);
            bool progress = !options.Contains(OPTION_NO_PROGRESS);
            bool sideband = options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K);

            ProgressMonitor pm = new NullProgressMonitor();
            Stream packOut = stream;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (options.Contains(OPTION_SIDE_BAND_64K))
                    bufsz = SideBandOutputStream.MAX_BUF;
                bufsz -= SideBandOutputStream.HDR_SIZE;

                packOut = new BufferedStream(new SideBandOutputStream(SideBandOutputStream.CH_DATA, pckOut), bufsz);

                if (progress)
                    pm = new SideBandProgressMonitor(pckOut);
            }

            PackWriter pw;
            pw = new PackWriter(db, pm, new NullProgressMonitor());
            pw.DeltaBaseAsOffset = options.Contains(OPTION_OFS_DELTA);
            pw.Thin = thin;
            pw.preparePack(wantAll, commonBase);
            if (options.Contains(OPTION_INCLUDE_TAG))
            {
                foreach (Ref r in refs.Values)
                {
                    RevObject o;
                    try
                    {
                        o = walk.parseAny(r.ObjectId);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                    if (o.has(WANT) || !(o is RevTag))
                        continue;
                    RevTag t = (RevTag) o;
                    if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
                        pw.addObject(t);
                }
            }
            pw.writePack(packOut);

            if (sideband)
            {
                packOut.Flush();
                pckOut.End();
            }
            else
            {
                stream.Flush();
            }
        }
        private void writePack(IDictionary<string, RemoteRefUpdate> refUpdates, ProgressMonitor monitor)
        {
            PackWriter writer = new PackWriter(local, monitor);
            List<ObjectId> remoteObjects = new List<ObjectId>(Refs.Count);
            List<ObjectId> newObjects = new List<ObjectId>(refUpdates.Count);

            foreach (Ref r in Refs)
                remoteObjects.Add(r.ObjectId);

            remoteObjects.AddRange(additionalHaves);
            foreach (RemoteRefUpdate r in refUpdates.Values)
            {
                if (!ObjectId.ZeroId.Equals(r.NewObjectId))
                    newObjects.Add(r.NewObjectId);
            }

            writer.Thin = _thinPack;
            writer.DeltaBaseAsOffset = _capableOfsDelta;
            writer.preparePack(newObjects, remoteObjects);
            writer.writePack(stream);
        }
Esempio n. 7
0
        private void Sendpack(IEnumerable <RemoteRefUpdate> updates, ProgressMonitor monitor)
        {
            string pathPack = null;
            string pathIdx  = null;

            try
            {
                var pw   = new PackWriter(_local, monitor);
                var need = new List <ObjectId>();
                var have = new List <ObjectId>();

                foreach (RemoteRefUpdate r in updates)
                {
                    need.Add(r.NewObjectId);
                }

                foreach (Ref r in Refs)
                {
                    have.Add(r.ObjectId);
                    if (r.PeeledObjectId != null)
                    {
                        have.Add(r.PeeledObjectId);
                    }
                }
                pw.preparePack(need, have);

                // We don't have to continue further if the pack will
                // be an empty pack, as the remote has all objects it
                // needs to complete this change.
                //
                if (pw.getObjectsNumber() == 0)
                {
                    return;
                }

                _packNames = new Dictionary <string, string>();
                foreach (string n in _dest.getPackNames())
                {
                    _packNames.put(n, n);
                }

                string b        = "pack-" + pw.computeName().Name;
                string packName = b + IndexPack.PackSuffix;
                pathPack = "pack/" + packName;
                pathIdx  = "pack/" + b + IndexPack.IndexSuffix;

                if (_packNames.remove(packName) != null)
                {
                    // The remote already contains this pack. We should
                    // remove the index before overwriting to prevent bad
                    // offsets from appearing to clients.
                    //
                    _dest.writeInfoPacks(_packNames.Keys);
                    _dest.deleteFile(pathIdx);
                }

                // Write the pack file, then the index, as readers look the
                // other direction (index, then pack file).
                //
                string wt = "Put " + b.Slice(0, 12);
                using (Stream os = _dest.writeFile(pathPack, monitor, wt + "." + IndexPack.PackSuffix))
                {
                    pw.writePack(os);
                }

                using (Stream os = _dest.writeFile(pathIdx, monitor, wt + "." + IndexPack.IndexSuffix))
                {
                    pw.writeIndex(os);
                }

                // Record the pack at the start of the pack info list. This
                // way clients are likely to consult the newest pack first,
                // and discover the most recent objects there.
                //
                var infoPacks = new List <string> {
                    packName
                };
                infoPacks.AddRange(_packNames.Keys);
                _dest.writeInfoPacks(infoPacks);
            }
            catch (IOException err)
            {
                SafeDelete(pathIdx);
                SafeDelete(pathPack);

                throw new TransportException(_uri, "cannot store objects", err);
            }
        }
Esempio n. 8
0
        private void SendPack()
        {
            bool thin     = _options.Contains(OptionThinPack);
            bool progress = !_options.Contains(OptionNoProgress);
            bool sideband = _options.Contains(OptionSideBand) || _options.Contains(OptionSideBand64K);

            ProgressMonitor pm       = NullProgressMonitor.Instance;
            Stream          _packOut = _rawOut;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (_options.Contains(OptionSideBand64K))
                {
                    bufsz = SideBandOutputStream.MAX_BUF;
                }

                _packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, _rawOut);

                if (progress)
                {
                    pm = new SideBandProgressMonitor(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, _rawOut));
                }
            }

            var pw = new PackWriter(_db, pm, NullProgressMonitor.Instance)
            {
                DeltaBaseAsOffset = _options.Contains(OptionOfsDelta),
                Thin = thin
            };

            pw.preparePack(_wantAll, _commonBase);
            if (_options.Contains(OptionIncludeTag))
            {
                foreach (Ref r in _refs.Values)
                {
                    RevObject o;
                    try
                    {
                        o = _walk.parseAny(r.ObjectId);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                    RevTag t = (o as RevTag);
                    if (o.has(WANT) || (t == null))
                    {
                        continue;
                    }

                    if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
                    {
                        pw.addObject(t);
                    }
                }
            }

            pw.writePack(_packOut);

            if (sideband)
            {
                _packOut.Flush();
                _pckOut.End();
            }
            else
            {
                _rawOut.Flush();
            }
        }
Esempio n. 9
0
        private void SendPack()
        {
            bool thin = _options.Contains(OptionThinPack);
            bool progress = !_options.Contains(OptionNoProgress);
            bool sideband = _options.Contains(OptionSideBand) || _options.Contains(OptionSideBand64K);

            ProgressMonitor pm = NullProgressMonitor.Instance;
            Stream _packOut = _rawOut;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (_options.Contains(OptionSideBand64K))
                {
                    bufsz = SideBandOutputStream.MAX_BUF;
                }

                _packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, _rawOut);

                if (progress)
                    pm = new SideBandProgressMonitor(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, _rawOut));
            }

            var pw = new PackWriter(_db, pm, NullProgressMonitor.Instance)
                        {
                            DeltaBaseAsOffset = _options.Contains(OptionOfsDelta),
                            Thin = thin
                        };

            pw.preparePack(_wantAll, _commonBase);
            if (_options.Contains(OptionIncludeTag))
            {
                foreach (Ref r in _refs.Values)
                {
                    RevObject o;
                    try
                    {
                        o = _walk.parseAny(r.ObjectId);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                    RevTag t = (o as RevTag);
                    if (o.has(WANT) || (t == null)) continue;

                    if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
                        pw.addObject(t);
                }
            }

            pw.writePack(_packOut);

            if (sideband)
            {
                _packOut.Flush();
                _pckOut.End();
            }
            else
            {
                _rawOut.Flush();
            }
        }
Esempio n. 10
0
        private void Sendpack(IEnumerable<RemoteRefUpdate> updates, ProgressMonitor monitor)
        {
            string pathPack = null;
            string pathIdx = null;

            try
            {
                var pw = new PackWriter(_local, monitor);
                var need = new List<ObjectId>();
                var have = new List<ObjectId>();

                foreach (RemoteRefUpdate r in updates)
                {
                    need.Add(r.NewObjectId);
                }

                foreach (Ref r in Refs)
                {
                    have.Add(r.ObjectId);
                    if (r.PeeledObjectId != null)
                    {
                        have.Add(r.PeeledObjectId);
                    }
                }
                pw.preparePack(need, have);

                // We don't have to continue further if the pack will
                // be an empty pack, as the remote has all objects it
                // needs to complete this change.
                //
                if (pw.getObjectsNumber() == 0) return;

                _packNames = new Dictionary<string, string>();
                foreach (string n in _dest.getPackNames())
                {
                    _packNames.put(n, n);
                }

                string b = "pack-" + pw.computeName().Name;
                string packName = b + IndexPack.PackSuffix;
                pathPack = "pack/" + packName;
                pathIdx = "pack/" + b + IndexPack.IndexSuffix;

                if (_packNames.remove(packName) != null)
                {
                    // The remote already contains this pack. We should
                    // remove the index before overwriting to prevent bad
                    // offsets from appearing to clients.
                    //
                    _dest.writeInfoPacks(_packNames.Keys);
                    _dest.deleteFile(pathIdx);
                }

                // Write the pack file, then the index, as readers look the
                // other direction (index, then pack file).
                //
                string wt = "Put " + b.Slice(0, 12);
                using (Stream os = _dest.writeFile(pathPack, monitor, wt + "." + IndexPack.PackSuffix))
                {
                    pw.writePack(os);
                }

                using (Stream os = _dest.writeFile(pathIdx, monitor, wt + "." + IndexPack.IndexSuffix))
                {
                    pw.writeIndex(os);
                }

                // Record the pack at the start of the pack info list. This
                // way clients are likely to consult the newest pack first,
                // and discover the most recent objects there.
                //
                var infoPacks = new List<string> { packName };
                infoPacks.AddRange(_packNames.Keys);
                _dest.writeInfoPacks(infoPacks);
            }
            catch (IOException err)
            {
                SafeDelete(pathIdx);
                SafeDelete(pathPack);

                throw new TransportException(_uri, "cannot store objects", err);
            }
        }
Esempio n. 11
0
        private void Sendpack(IEnumerable<RemoteRefUpdate> updates, ProgressMonitor monitor)
        {
            string pathPack = null;
            string pathIdx = null;

            try
            {
                var pw = new PackWriter(_local, monitor);
                var need = new List<ObjectId>();
                var have = new List<ObjectId>();

                foreach (RemoteRefUpdate r in updates)
                {
                    need.Add(r.NewObjectId);
                }

                foreach (Ref r in Refs)
                {
                    have.Add(r.ObjectId);
                    if (r.PeeledObjectId != null)
                    {
                        have.Add(r.PeeledObjectId);
                    }
                }
                pw.preparePack(need, have);

                if (pw.getObjectsNumber() == 0) return;

                _packNames = new Dictionary<string, string>();
                foreach (string n in _dest.getPackNames())
                {
                    _packNames.Add(n, n);
                }

                string b = "pack-" + pw.computeName().Name;
                string packName = b + IndexPack.PackSuffix;
                pathPack = "pack/" + packName;
                pathIdx = "pack/" + b + IndexPack.IndexSuffix;

                if (_packNames.Remove(packName))
                {
                    _dest.writeInfoPacks(new List<string>(_packNames.Keys));
                    _dest.deleteFile(pathIdx);
                }

                string wt = "Put " + b.Slice(0, 12);
                Stream os = _dest.writeFile(pathPack, monitor, wt + "." + IndexPack.PackSuffix);
                try
                {
                    pw.writePack(os);
                }
                finally
                {
                    os.Close();
                }

                os = _dest.writeFile(pathIdx, monitor, wt + "..idx");
                try
                {
                    pw.writeIndex(os);
                }
                finally
                {
                    os.Close();
                }

                var infoPacks = new List<string> {packName};
                infoPacks.AddRange(_packNames.Keys);
                _dest.writeInfoPacks(infoPacks);
            }
            catch (IOException err)
            {
                SafeDelete(pathIdx);
                SafeDelete(pathPack);

                throw new TransportException(_uri, "cannot store objects", err);
            }
        }
Esempio n. 12
0
        private void Sendpack(IEnumerable <RemoteRefUpdate> updates, ProgressMonitor monitor)
        {
            string pathPack = null;
            string pathIdx  = null;

            try
            {
                var pw   = new PackWriter(_local, monitor);
                var need = new List <ObjectId>();
                var have = new List <ObjectId>();

                foreach (RemoteRefUpdate r in updates)
                {
                    need.Add(r.NewObjectId);
                }

                foreach (Ref r in Refs)
                {
                    have.Add(r.ObjectId);
                    if (r.PeeledObjectId != null)
                    {
                        have.Add(r.PeeledObjectId);
                    }
                }
                pw.preparePack(need, have);

                if (pw.getObjectsNumber() == 0)
                {
                    return;
                }

                _packNames = new Dictionary <string, string>();
                foreach (string n in _dest.getPackNames())
                {
                    _packNames.Add(n, n);
                }

                string b        = "pack-" + pw.computeName().Name;
                string packName = b + IndexPack.PackSuffix;
                pathPack = "pack/" + packName;
                pathIdx  = "pack/" + b + IndexPack.IndexSuffix;

                if (_packNames.Remove(packName))
                {
                    _dest.writeInfoPacks(new List <string>(_packNames.Keys));
                    _dest.deleteFile(pathIdx);
                }

                string wt = "Put " + b.Slice(0, 12);
                Stream os = _dest.writeFile(pathPack, monitor, wt + "." + IndexPack.PackSuffix);
                try
                {
                    pw.writePack(os);
                }
                finally
                {
                    os.Close();
                }

                os = _dest.writeFile(pathIdx, monitor, wt + "..idx");
                try
                {
                    pw.writeIndex(os);
                }
                finally
                {
                    os.Close();
                }

                var infoPacks = new List <string> {
                    packName
                };
                infoPacks.AddRange(_packNames.Keys);
                _dest.writeInfoPacks(infoPacks);
            }
            catch (IOException err)
            {
                SafeDelete(pathIdx);
                SafeDelete(pathPack);

                throw new TransportException(_uri, "cannot store objects", err);
            }
        }