WriteBlob() public method

Write a blob with the data in the specified file
public WriteBlob ( FileInfo fileInfo ) : ObjectId
fileInfo System.IO.FileInfo A file containing blob data.
return ObjectId
Ejemplo n.º 1
0
        public void testNonRecursiveFiltering()
        {
            var ow = new ObjectWriter(db);
            ObjectId aSth = ow.WriteBlob("a.sth".getBytes());
            ObjectId aTxt = ow.WriteBlob("a.txt".getBytes());
            DirCache dc = DirCache.read(db);
            DirCacheBuilder builder = dc.builder();
            var aSthEntry = new DirCacheEntry("a.sth");
            aSthEntry.setFileMode(FileMode.RegularFile);
            aSthEntry.setObjectId(aSth);
            var aTxtEntry = new DirCacheEntry("a.txt");
            aTxtEntry.setFileMode(FileMode.RegularFile);
            aTxtEntry.setObjectId(aTxt);
            builder.add(aSthEntry);
            builder.add(aTxtEntry);
            builder.finish();
            ObjectId treeId = dc.writeTree(ow);


            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
            tw.setFilter(PathSuffixFilter.create(".txt"));
            tw.addTree(treeId);

            var paths = new LinkedList<string>();
            while (tw.next())
            {
                paths.AddLast(tw.getPathString());
            }

            var expected = new LinkedList<string>();
            expected.AddLast("a.txt");

            Assert.AreEqual(expected, paths);
        }
Ejemplo n.º 2
0
            ///	<summary>
            /// Update this index entry with stat and SHA-1 information if it looks
            /// like the file has been modified in the workdir.
            /// </summary>
            /// <param name="f">file in work dir</param>
            /// <returns> true if a change occurred </returns>
            /// <exception cref="IOException"></exception>
            public bool update(FileInfo f)
            {
                long lm       = f.lastModified() * 1000000L;
                bool modified = Mtime != lm;

                Mtime = lm;

                if (_size != f.Length)
                {
                    modified = true;
                }

                if (ConfigFileMode)
                {
                    if (FileCanExecute(f) != FileMode.ExecutableFile.Equals(Mode))
                    {
                        Mode     = FileMode.ExecutableFile.Bits;
                        modified = true;
                    }
                }

                if (modified)
                {
                    _size = (int)f.Length;
                    var      writer  = new ObjectWriter(Repository);
                    ObjectId newsha1 = ObjectId = writer.WriteBlob(f);

                    modified = !newsha1.Equals(ObjectId);
                    ObjectId = newsha1;
                }

                return(modified);
            }
Ejemplo n.º 3
0
            internal Entry(Repository repository, byte[] key, FileInfo f, int stage, byte[] newContent)
                : this(repository)
            {
                if (newContent == null && f == null)
                {
                    throw new ArgumentException("either file or newContent must be non-null");
                }
                if (f == null)
                {
                    Ctime = DateTime.Now.ToMillisecondsSinceEpoch() * 1000000L;
                }
                else
                {
                    Ctime = f.LastWriteTime.ToMillisecondsSinceEpoch() * 1000000L;
                }
                Mtime = Ctime; // we use same here
                _dev  = -1;
                _ino  = -1;

                if (ConfigFilemode(Repository) && FileCanExecute(f))
                {
                    Mode = FileMode.ExecutableFile.Bits;
                }
                else
                {
                    Mode = FileMode.RegularFile.Bits;
                }

                _uid  = -1;
                _gid  = -1;
                _size = ((newContent == null || newContent.Length == 0) && f != null) ? (int)(f).Length : newContent.Length;
                var writer = new ObjectWriter(Repository);
                if ((newContent == null || newContent.Length == 0) && f != null)
                {
                    ObjectId = writer.WriteBlob(f);
                }
                else
                {
                    ObjectId = writer.WriteBlob(newContent);
                }
                _name  = key;
                _flags = (short)((stage << 12) | _name.Length); // TODO: fix _flags
            }
Ejemplo n.º 4
0
            ///	<summary>
            /// Update this index entry with stat and SHA-1 information if it looks
            /// like the file has been modified in the workdir.
            /// </summary>
            /// <param name="f">file in work dir</param>
            /// <param name="newContent">the new content of the file </param>
            /// <returns> true if a change occurred </returns>
            /// <exception cref="IOException"></exception>
            public bool update(FileInfo f, byte[] newContent)             //[henon] TODO: remove parameter f as it is useless
            {
                bool modified = false;

                _size = newContent.Length;
                var      writer  = new ObjectWriter(Repository);
                ObjectId newsha1 = ObjectId = writer.WriteBlob(newContent);

                if (!newsha1.Equals(ObjectId))
                {
                    modified = true;
                }

                ObjectId = newsha1;
                return(modified);
            }
Ejemplo n.º 5
0
 public string HashAndInsertObject(Stream file)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(file.Length, file);
     return objectId.ToString();
 }
Ejemplo n.º 6
0
 public string HashAndInsertObject(string filename)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(new FileInfo(filename));
     return objectId.ToString();
 }
Ejemplo n.º 7
0
 public string HashAndInsertObject(Stream file, long length)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(length, file);
     return objectId.Name;
 }
Ejemplo n.º 8
0
        public void testMissingSubtree_DetectFileAdded_FileModified()
        {
            var ow = new ObjectWriter(db);
            ObjectId aFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("a"));
            ObjectId bFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("b"));
            ObjectId cFileId1 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-1"));
            ObjectId cFileId2 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-2"));

            // Create sub-a/empty, sub-c/empty = hello.
            Func<ObjectId> oldTree = () =>
                                     	{
                                            var root = new Core.Tree(db);

                                            Core.Tree subA = root.AddTree("sub-a");
                                     		subA.AddFile("empty").Id = aFileId;
                                     		subA.Id = ow.WriteTree(subA);

                                            Core.Tree subC = root.AddTree("sub-c");
                                     		subC.AddFile("empty").Id = cFileId1;
                                     		subC.Id = ow.WriteTree(subC);

                                     		return ow.WriteTree(root);
                                     	};

            // Create sub-a/empty, sub-b/empty, sub-c/empty.
            Func<ObjectId> newTree = () =>
                                     	{
                                            var root = new Core.Tree(db);

                                            Core.Tree subA = root.AddTree("sub-a");
                                     		subA.AddFile("empty").Id = aFileId;
                                     		subA.Id = ow.WriteTree(subA);

                                            Core.Tree subB = root.AddTree("sub-b");
                                     		subB.AddFile("empty").Id = bFileId;
                                     		subB.Id = ow.WriteTree(subB);

                                            Core.Tree subC = root.AddTree("sub-c");
                                     		subC.AddFile("empty").Id = cFileId2;
                                     		subC.Id = ow.WriteTree(subC);

                                     		return ow.WriteTree(root);
                                     	};

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
            tw.reset(new[] { oldTree.Invoke(), newTree.Invoke() });
            tw.Recursive = true;
            tw.setFilter(TreeFilter.ANY_DIFF);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("sub-b/empty", tw.getPathString());
            Assert.AreEqual(FileMode.Missing, tw.getFileMode(0));
            Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
            Assert.AreEqual(ObjectId.ZeroId, tw.getObjectId(0));
            Assert.AreEqual(bFileId, tw.getObjectId(1));

            Assert.IsTrue(tw.next());
            Assert.AreEqual("sub-c/empty", tw.getPathString());
            Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(0));
            Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
            Assert.AreEqual(cFileId1, tw.getObjectId(0));
            Assert.AreEqual(cFileId2, tw.getObjectId(1));

            Assert.IsFalse(tw.next());
        }
Ejemplo n.º 9
0
 private void addFile(Tree t, FileInfo f, ObjectWriter objectWriter)
 {
     ObjectId id = objectWriter.WriteBlob(f);
     t.AddEntry(new FileTreeEntry(t, id, f.Name.getBytes("UTF-8"), false));
 }
Ejemplo n.º 10
0
 private static string HashWithGitSharp(Stream file)
 {
     var repository = new Repository(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ".git")));
     var writer = new ObjectWriter(repository);
     return writer.WriteBlob(file.Length, file).ToString();
 }
Ejemplo n.º 11
0
        private RevObject WriteBlob(Core.Repository repo, string data)
        {
            var revWalk = new GitSharp.Core.RevWalk.RevWalk(repo);
            byte[] bytes = Constants.encode(data);
            var ow = new ObjectWriter(repo);
            ObjectId id = ow.WriteBlob(bytes);
            try
            {
                Parse(id);
                Assert.Fail("Object " + id.Name + " should not exist in test repository");
            }
            catch (MissingObjectException)
            {
                // Ok
            }

            return revWalk.lookupBlob(id);
        }
Ejemplo n.º 12
0
 public override void VisitFile(FileTreeEntry f)
 {
     f.Id = ow.WriteBlob(PathUtil.CombineFilePath(GetCurrentDirectory(), f.Name));
 }
Ejemplo n.º 13
0
 private static string HashWithGitSharp(Stream file)
 {
     var repository = new Repository(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, GitHelpers.ResolveRepositoryLocation().FullName)));
     var writer = new ObjectWriter(repository);
     return writer.WriteBlob(file.Length, file).ToString();
 }