Represents a directory in the git repository.
상속: AbstractObject, ITreeNode
예제 #1
0
        public void LoadTree(Tree tree)
        {
            listView1.Clear();

            if (!tree.IsRoot)
                listView1.Items.Add(new ListViewItem("...", 3));

            foreach (Tree t in tree.Trees)
            {
                var leaves = 0;
                foreach (Leaf l in t.Leaves)
                    leaves++;
                if (leaves > 0)
                    listView1.Items.Add(new ListViewItem(t.Name, 1, folders));
                else
                    listView1.Items.Add(new ListViewItem(t.Name, 2, folders));
            }

            foreach (Leaf l in tree.Leaves)
            {
                string[] splitFilename = l.Name.Split('.');
                string extension = splitFilename[splitFilename.GetLength(0) - 1];
                if (imageExtensions.Contains(extension))
                    listView1.Items.Add(new ListViewItem(l.Name, 4, files));
                else
                    listView1.Items.Add(new ListViewItem(l.Name, 0, files));
            }

            currentTree = tree;
        }
예제 #2
0
 ///	<summary>
 /// Create a checkout class for checking out one tree, merging with the index
 ///	</summary>
 ///	<param name="repo"> </param>
 ///	<param name="root"> workdir </param>
 ///	<param name="index"> current index </param>
 ///	<param name="merge"> tree to check out </param>
 public WorkDirCheckout(Repository repo, FileSystemInfo root, GitIndex index, Tree merge)
     : this()
 {
     this._repo = repo;
     this._root = root;
     this._index = index;
     this._merge = merge;
 }
 public void StartVisitTree(Tree t)
 {
     stack.Push(currentDirectory);
     if (!t.IsRoot)
     {
         currentDirectory = new DirectoryInfo(Path.Combine(currentDirectory.FullName, t.Name));
     }
 }
예제 #4
0
 public IndexTreeWalker(GitIndex index, Tree mainTree, Tree newTree, FileSystemInfo root,
                        IndexTreeVisitor visitor)
 {
     _mainTree = mainTree;
     _newTree = newTree;
     _root = root;
     _visitor = visitor;
     _threeTrees = newTree != null;
     _indexMembers = index.Members;
 }
예제 #5
0
        public IndexDiff(Tree tree, GitIndex index)
        {
            _anyChanges = false;
            _tree = tree;
            _index = index;

            Added = new HashSet<string>();
            Changed = new HashSet<string>();
            Removed = new HashSet<string>();
            Missing = new HashSet<string>();
            Modified = new HashSet<string>();
        }
예제 #6
0
        public GitObject CreateFromContent(GitObjectStream content)
        {
            string type = ReadHeading(content);

            GitObject obj;

            if (type == "commit")
                obj = new Commit();
            else if (type == "tree")
                obj = new Tree();
            else if (type == "blob")
                obj = new Blob();
            else
                throw new NotImplementedException("Support for file type is not implemented.");

            content.Rewind();

            obj.Load(content);

            return obj;
        }
예제 #7
0
        public TreeViewModel(Repository repository, RepositoryNavigationRequest request, Tree tree)
            : base(repository, request)
        {
            PathModel = new PathViewModel(request, tree);
            Tree = tree;
            Path = tree.Path;
            IsRoot = Tree.IsRoot;

            Items = new List<ListItemViewModel>();
            foreach (var child in Tree.Children)
            {
                ListItemViewModel.ItemType type;
                AbstractTreeNode node = child as AbstractTreeNode;
                if (child is Leaf)
                {
                    type = ListItemViewModel.ItemType.Blob;
                }
                else if (child is Tree)
                {
                    type = ListItemViewModel.ItemType.Tree;
                }
                else
                {
                    throw new InvalidOperationException("Unexpected child in tree.");
                }

                Commit lastCommit = null;// node.GetLastCommitBefore(commit);
                Items.Add(new ListItemViewModel(request)
                {
                    Name = node.Name,
                    Author = lastCommit != null ? lastCommit.Author.Name : String.Empty,
                    AuthorDate = lastCommit != null ? lastCommit.AuthorDate : (DateTimeOffset?)null,
                    CommitDate = lastCommit != null ? lastCommit.CommitDate : (DateTimeOffset?)null,
                    Message = lastCommit != null ? lastCommit.Message : String.Empty,
                    Type = type,
                    Path = node.Path,
                });
            }
        }
예제 #8
0
 public IndexTreeWalker(GitIndex index, Tree mainTree, Tree newTree, DirectoryInfo root, IndexTreeVisitor visitor)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author, Author committer, DateTimeOffset time)
 {
     return(Create(message, (parent == null ? new Commit[0] : new[] { parent }), tree, author, committer, time));
 }
예제 #10
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author)
 {
     return Create(message, parent, tree, author, author, DateTimeOffset.Now);
 }
예제 #11
0
        public void test008_SubtreeInternalSorting()
        {
            Tree t = new Tree(db);
            FileTreeEntry e0 = t.AddFile("a-b");
            FileTreeEntry e1 = t.AddFile("a-");
            FileTreeEntry e2 = t.AddFile("a=b");
            Tree e3 = t.AddTree("a");
            FileTreeEntry e4 = t.AddFile("a=");

            TreeEntry[] ents = t.Members;
            Assert.AreSame(e1, ents[0]);
            Assert.AreSame(e0, ents[1]);
            Assert.AreSame(e3, ents[2]);
            Assert.AreSame(e4, ents[3]);
            Assert.AreSame(e2, ents[4]);
        }
예제 #12
0
        public void test006_addDeepTree()
        {
            Tree t = new Tree(db);

            Tree e = t.AddTree("e");
            Assert.IsNotNull(e);
            Assert.IsTrue(e.Parent == t);
            Tree f = t.AddTree("f");
            Assert.IsNotNull(f);
            Assert.IsTrue(f.Parent == t);
            Tree g = f.AddTree("g");
            Assert.IsNotNull(g);
            Assert.IsTrue(g.Parent == f);
            Tree h = g.AddTree("h");
            Assert.IsNotNull(h);
            Assert.IsTrue(h.Parent == g);

            h.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!h.IsModified);
            g.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!g.IsModified);
            f.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!f.IsModified);
            e.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!e.IsModified);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(!t.IsModified);

            Assert.AreEqual("f/g/h", h.FullName);
            Assert.IsTrue(t.findTreeMember(h.FullName) == h);
            Assert.IsTrue(t.FindBlobMember("f/z") == null);
            Assert.IsTrue(t.FindBlobMember("y/z") == null);

            FileTreeEntry i = h.AddFile("i");
            Assert.IsNotNull(i);
            Assert.AreEqual("f/g/h/i", i.FullName);
            Assert.IsTrue(t.FindBlobMember(i.FullName) == i);
            Assert.IsTrue(h.IsModified);
            Assert.IsTrue(g.IsModified);
            Assert.IsTrue(f.IsModified);
            Assert.IsTrue(!e.IsModified);
            Assert.IsTrue(t.IsModified);

            Assert.IsTrue(h.Id == null);
            Assert.IsTrue(g.Id == null);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(e.Id != null);
            Assert.IsTrue(t.Id == null);
        }
예제 #13
0
        public void test004_addTree()
        {
            Tree t = new Tree(db);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            String n = "bob";
            Tree f = t.AddTree(n);
            Assert.IsNotNull(f);
            Assert.AreEqual(n, f.Name);
            Assert.AreEqual(f.Name, Encoding.UTF8.GetString(f.NameUTF8));
            Assert.AreEqual(n, f.FullName);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(f.Parent == t);
            Assert.IsTrue(f.Repository == db);
            Assert.IsTrue(f.IsLoaded);
            Assert.IsFalse(f.Members.Length > 0);
            Assert.IsFalse(f.IsRoot);
            Assert.IsTrue(f.TreeEntry == f);
            Assert.IsTrue(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.findTreeMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsTrue(i.Length > 0);
            Assert.IsTrue(i[0] == f);
            Assert.IsTrue(i.Length == 1);
        }
예제 #14
0
 public void test001_createEmpty()
 {
     Tree t = new Tree(db);
     Assert.IsTrue(t.IsLoaded);
     Assert.IsTrue(t.IsModified);
     Assert.IsTrue(t.Parent == null);
     Assert.IsTrue(t.IsRoot);
     Assert.IsTrue(t.Name == null);
     Assert.IsTrue(t.NameUTF8 == null);
     Assert.IsTrue(t.Members != null);
     Assert.IsTrue(t.Members.Length == 0);
     Assert.AreEqual("", t.FullName);
     Assert.IsTrue(t.Id == null);
     Assert.IsTrue(t.TreeEntry == t);
     Assert.IsTrue(t.Repository == db);
     Assert.IsTrue(t.findTreeMember("foo") == null);
     Assert.IsTrue(t.FindBlobMember("foo") == null);
 }
예제 #15
0
        public ObjectId WriteTree(Tree t)
        {
            var m = new MemoryStream();
            var o = new BinaryWriter(m);
            TreeEntry[] items = t.Members;
            for (int k = 0; k < items.Length; k++)
            {
                TreeEntry e = items[k];
                ObjectId id = e.Id;

                if (id == null)
                    throw new ObjectWritingException("object at path \""
                            + e.FullName + "\" does not have an id assigned."
                            + "  All object ids must be assigned prior"
                            + " to writing a tree.");

                e.Mode.CopyTo(m);
                o.Write((byte)' ');
                o.Write(e.NameUTF8);
                o.Write((byte)0);
                id.copyRawTo(m);
            }
            return WriteCanonicalTree(m.ToArray());
        }
예제 #16
0
 public ObjectId WriteTree(Tree t)
 {
     var output = new MemoryStream();
     var writer = new BinaryWriter(output);
     foreach (TreeEntry entry in t.Members)
     {
         ObjectId id = entry.Id;
         if (id == null)
         {
             throw new ObjectWritingException("object at path \"" + entry.FullName +
                                              "\" does not have an id assigned.  All object ids must be assigned prior to writing a tree.");
         }
         entry.Mode.CopyTo(output);
         writer.Write((byte) 0x20);
         writer.Write(entry.NameUTF8);
         writer.Write((byte) 0);
         id.copyRawTo(output);
     }
     return WriteCanonicalTree(output.ToArray());
 }
 void IndexTreeVisitor.FinishVisitTree(Tree tree, int i, string curDir)
 {
     FinishVisitTreeByIndexDelegate handler = this.FinishVisitTreeByIndex;
     if (handler != null)
         handler(tree, i, curDir);
 }
 void IndexTreeVisitor.FinishVisitTree(Tree tree, Tree auxTree, string curDir)
 {
     FinishVisitTreeDelegate handler = this.FinishVisitTree;
     if (handler != null)
         handler(tree, auxTree, curDir);
 }
예제 #19
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author, Author committer, DateTimeOffset time)
 {
     if (string.IsNullOrEmpty(message))
         throw new ArgumentException("message must not be null or empty");
     if (tree == null)
         throw new ArgumentException("tree must not be null");
     var repo = tree.Repository;
     var corecommit = new CoreCommit(repo._internal_repo);
     if (parent != null)
         corecommit.ParentIds = new GitSharp.Core.ObjectId[] { parent._id };
     corecommit.Author = new GitSharp.Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
     corecommit.Committer = new GitSharp.Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
     corecommit.Message = message;
     corecommit.TreeEntry = tree.InternalTree;
     corecommit.Encoding = ExtractOverridenEncodingCommitFromConfig(repo);
     corecommit.Save();
     return new Commit(repo, corecommit);
 }
예제 #20
0
 public IndexDiff(Repository repository)
 {
     this._tree = repository.MapTree("HEAD");
     this._index = repository.Index;
 }
예제 #21
0
 public IndexDiff(Tree tree, GitIndex index)
 {
     this._tree = tree;
     this._index = index;
 }
예제 #22
0
 public FileTreeEntry(Tree parent, ObjectId id, byte[] nameUTF8, bool execute)
     : base(parent,id, nameUTF8)
 {
     this.SetExecutable(execute);
 }
예제 #23
0
        public void test002_addFile()
        {
            Tree t = new Tree(db);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            String n = "bob";
            FileTreeEntry f = t.AddFile(n);
            Assert.IsNotNull(f);
            Assert.AreEqual(n, f.Name);
            Assert.AreEqual(f.Name, Encoding.UTF8.GetString(f.NameUTF8));
            Assert.AreEqual(n, f.FullName);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.FindBlobMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsNotNull(i);
            Assert.IsTrue(i != null && i.Length > 0);
            Assert.IsTrue(i != null && i[0] == f);
            Assert.IsTrue(i != null && i.Length == 1);
        }
 public virtual void EndVisitTree(Tree t)
 {
     currentDirectory = stack.Pop();
 }
예제 #25
0
 public void test005_addRecursiveTree()
 {
     Tree t = new Tree(db);
     Tree f = t.AddTree("a/b/c");
     Assert.IsNotNull(f);
     Assert.AreEqual(f.Name, "c");
     Assert.AreEqual(f.Parent.Name, "b");
     Assert.AreEqual(f.Parent.Parent.Name, "a");
     Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent");
 }
예제 #26
0
 public void AttachParent(Tree p)
 {
     this.Parent = p;
 }
예제 #27
0
 public void test007_manyFileLookup()
 {
     Tree t = new Tree(db);
     var files = new List<FileTreeEntry>(26 * 26);
     for (char level1 = 'a'; level1 <= 'z'; level1++)
     {
         for (char level2 = 'a'; level2 <= 'z'; level2++)
         {
             String n = "." + level1 + level2 + "9";
             FileTreeEntry f = t.AddFile(n);
             Assert.IsNotNull(f, "File " + n + " added.");
             Assert.AreEqual(n, f.Name);
             files.Add(f);
         }
     }
     Assert.AreEqual(files.Count, t.MemberCount);
     TreeEntry[] ents = t.Members;
     Assert.IsNotNull(ents);
     Assert.AreEqual(files.Count, ents.Length);
     for (int k = 0; k < ents.Length; k++)
     {
         Assert.IsTrue(files[k] == ents[k], "File " + files[k].Name + " is at " + k + ".");
     }
 }
예제 #28
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author)
 {
     return(Create(message, parent, tree, author, author, DateTimeOffset.Now));
 }
예제 #29
0
 // Methods
 public IndexTreeWalker(GitIndex index, Tree mainTree, FileSystemInfo root, IndexTreeVisitor visitor)
     : this(index, mainTree, null, root, visitor)
 {
 }
예제 #30
0
 public static Commit Create(string message, Commit parent, Tree tree)
 {
     if (tree==null)
         throw new ArgumentException("tree must not be null");
     var repo=tree.Repository;
     var author=new Author(repo.Config["user.name"], repo.Config["user.email"]);
     return Create(message, parent, tree, author, author, DateTimeOffset.Now);
 }
예제 #31
0
 public TreeEntry(Tree myParent, ObjectId id, byte[] nameUTF8)
 {
     this.NameUTF8 = nameUTF8;
     this.Parent = myParent;
     this._id = id;
 }
예제 #32
0
        private void Walk(Tree tree, Tree auxTree)
        {
            var mi = new TreeIterator(tree, TreeIterator.Order.POSTORDER);
            var ai = new TreeIterator(auxTree, TreeIterator.Order.POSTORDER);
            TreeEntry m = mi.hasNext() ? mi.next() : null;
            TreeEntry a = ai.hasNext() ? ai.next() : null;
            int curIndexPos = IndexCounter;
            GitIndex.Entry entry = (IndexCounter < _indexMembers.Length) ? _indexMembers[IndexCounter++] : null;
            while (((m != null) || (a != null)) || (entry != null))
            {
                int cmpma = Compare(m, a);
                int cmpmi = Compare(m, entry);
                int cmpai = Compare(a, entry);
                TreeEntry pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m : null;
                TreeEntry pa = ((cmpma >= 0) && (cmpai <= 0)) ? a : null;
                GitIndex.Entry pi = ((cmpmi >= 0) && (cmpai >= 0)) ? entry : null;

                if (pi != null)
                {
                    VisitEntry(pm, pa, pi);
                }
                else
                {
                    FinishVisitTree(pm, pa, curIndexPos);
                }

                if (pm != null)
                {
                    m = mi.hasNext() ? mi.next() : null;
                }

                if (pa != null)
                {
                    a = ai.hasNext() ? ai.next() : null;
                }

                if (pi != null)
                {
                    entry = (IndexCounter < _indexMembers.Length) ? _indexMembers[IndexCounter++] : null;
                }
            }
        }