Exemple #1
0
        public void testWriteIndex()
        {
            _writer.setIndexVersion(2);
            WriteVerifyPack4(false);

            // Validate that IndexPack came up with the right CRC32 value.
            PackIndex idx1 = PackIndex.Open(_indexFile);

            Assert.IsTrue(idx1 is PackIndexV2);
            Assert.AreEqual(0x4743F1E4L, idx1.FindCRC32(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));

            // Validate that an index written by PackWriter is the same.
            FileInfo idx2File = new FileInfo(_indexFile.FullName + ".2");

            using (var @is = new FileStream(idx2File.FullName, System.IO.FileMode.CreateNew))
            {
                _writer.writeIndex(@is);
            }

            PackIndex idx2 = PackIndex.Open(idx2File);

#pragma warning disable 0612
            Assert.IsInstanceOfType(typeof(PackIndexV2), idx2); // [henon] IsInstanceOfType is obsolete
#pragma warning restore 0612
            Assert.AreEqual(idx1.ObjectCount, idx2.ObjectCount);
            Assert.AreEqual(idx1.Offset64Count, idx2.Offset64Count);

            for (int i = 0; i < idx1.ObjectCount; i++)
            {
                ObjectId id = idx1.GetObjectId(i);
                Assert.AreEqual(id, idx2.GetObjectId(i));
                Assert.AreEqual(idx1.FindOffset(id), idx2.FindOffset(id));
                Assert.AreEqual(idx1.FindCRC32(id), idx2.FindCRC32(id));
            }
        }
Exemple #2
0
        private static void Write(FileInfo[] files, PackWriter pw)
        {
            FileInfo file  = files[0];
            long     begin = file.Directory.LastWriteTime.Ticks;

            using (var stream = file.Create())
            {
                pw.writePack(stream);
            }

            file = files[1];
            using (var stream = file.Create())
            {
                pw.writeIndex(stream);
            }

            Touch(begin, files[0].Directory);
        }
Exemple #3
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);
            }
        }
        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);
            }
        }
        private static void Write(FileInfo[] files, PackWriter pw)
        {
            FileInfo file = files[0];
            long begin = file.Directory.lastModified();

            using (var stream = file.Create())
            {

                    pw.writePack(stream);

            }

            file = files[1];
            using (var stream = file.Create())
            {

                    pw.writeIndex(stream);
   
            }

            Touch(begin, files[0].Directory);
        }
        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);
            }
        }
        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);
            }
        }