示例#1
0
 /// <summary>
 /// Find a Blob or Tree by traversing the tree along the given path. You can access not only direct children
 /// of the tree but any descendant of this tree.
 /// <para/>
 /// The path's directory seperators may be both forward or backslash, it is converted automatically to the internal representation.
 /// <para/>
 /// Throws IOException.
 /// </summary>
 /// <param name="path">Relative path to a file or directory in the git tree. For directories a trailing slash is allowed</param>
 /// <returns>A tree or blob object representing the referenced object</returns>
 public AbstractObject this[string path]
 {
     get
     {
         if (path == "")
         {
             return(this);
         }
         var tree_entry = _internal_tree.FindBlobMember(path);
         if (tree_entry == null)
         {
             tree_entry = _internal_tree.findTreeMember(path);
         }
         if (tree_entry == null)
         {
             return(null);
         }
         if (tree_entry.IsTree)
         {
             return(new Tree(_repo, tree_entry as CoreTree));
         }
         else if (tree_entry.IsBlob)
         {
             return(new Leaf(_repo, tree_entry as FileTreeEntry));
         }
         else                 // if (tree_entry.IsCommit || tree_entry.IsTag)
         {
             return(AbstractObject.Wrap(_repo, tree_entry.Id));
         }
     }
 }
示例#2
0
文件: Ref.cs 项目: kkl713/GitSharp
        /// <summary>
        /// Updates this ref by forwarding it to the given object.
        /// </summary>
        /// <param name="other">The ref this object shall reference.</param>
        public void Update(AbstractObject reference)
        {
            var db        = _repo._internal_repo;
            var updateRef = db.UpdateRef(this.Name);

            updateRef.NewObjectId   = reference._id;
            updateRef.IsForceUpdate = true;
            updateRef.Update();
            //db.WriteSymref(Name, other.Name);
        }
示例#3
0
文件: Commit.cs 项目: kkl713/GitSharp
        /// <summary>
        /// Compare reference commit against compared commit. You may pass in a null commit (i.e. for getting the changes of the first commit)
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="compared"></param>
        /// <returns></returns>
        public static IEnumerable <Change> CompareCommits(Commit reference, Commit compared)
        {
            var changes = new List <Change>();

            if (reference == null && compared == null)
            {
                return(changes);
            }
            var repo = (reference ?? compared).Repository;

            if (compared.Repository.Directory != repo.Directory)
            {
                throw new InvalidOperationException("Can not compare commits from different repositories");
            }
            var ref_tree      = (reference != null ? reference.Tree._id : ObjectId.ZeroId);
            var compared_tree = (compared != null ? compared.Tree._id : ObjectId.ZeroId);
            var db            = repo._internal_repo;
            var pathFilter    = TreeFilter.ALL;
            var walk          = new TreeWalk(db);

            //new GitSharp.Core.ObjectWriter(repo).WriteTree( new CoreTree(repo)); // <--- writing an empty tree object. very ugly hack that is necessary to get an empty tree into the treewalker.
            if (reference == null || compared == null)
            {
                walk.reset((reference ?? compared).Tree._id);
            }
            else
            {
                walk.reset(new GitSharp.Core.AnyObjectId[] { ref_tree, compared_tree });
            }
            //if (ref_tree == ObjectId.ZeroId)
            //    walk.addTree(new EmptyTreeIterator());
            //else
            //    walk.addTree(ref_tree);
            //if (compared_tree == ObjectId.ZeroId)
            //    walk.addTree(new EmptyTreeIterator());
            //else
            //    walk.addTree(compared_tree);
            walk.Recursive = true;
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));

            while (walk.next())
            {
                if (walk.getTreeCount() == 2)
                {
                    int m0     = walk.getRawMode(0);
                    int m1     = walk.getRawMode(1);
                    var change = new Change()
                    {
                        ReferenceCommit      = reference,
                        ComparedCommit       = compared,
                        ReferencePermissions = walk.getFileMode(0).Bits,
                        ComparedPermissions  = walk.getFileMode(1).Bits,
                        Name = walk.getNameString(),
                        Path = walk.getPathString(),
                    };
                    changes.Add(change);
                    if (m0 == 0 && m1 != 0)
                    {
                        change.ChangeType     = ChangeType.Added;
                        change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
                    }
                    else if (m0 != 0 && m1 == 0)
                    {
                        change.ChangeType      = ChangeType.Deleted;
                        change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
                    }
                    else if (m0 != m1 && walk.idEqual(0, 1))
                    {
                        change.ChangeType      = ChangeType.TypeChanged;
                        change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
                        change.ComparedObject  = AbstractObject.Wrap(repo, walk.getObjectId(1));
                    }
                    else
                    {
                        change.ChangeType      = ChangeType.Modified;
                        change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
                        change.ComparedObject  = AbstractObject.Wrap(repo, walk.getObjectId(1));
                    }
                }
                else
                {
                    var change = new Change()
                    {
                        ReferenceCommit = reference,
                        ComparedCommit  = compared,
                        Name            = walk.getNameString(),
                        Path            = walk.getPathString(),
                    };
                    changes.Add(change);
                    if (reference != null)
                    {
                        change.ReferencePermissions = walk.getFileMode(0).Bits;
                        change.ChangeType           = ChangeType.Deleted;
                        change.ReferenceObject      = AbstractObject.Wrap(repo, walk.getObjectId(0));
                    }
                    else
                    {
                        change.ComparedPermissions = walk.getFileMode(0).Bits;
                        change.ChangeType          = ChangeType.Added;
                        change.ComparedObject      = AbstractObject.Wrap(repo, walk.getObjectId(0));
                    }
                }
            }
            return(changes);
        }
示例#4
0
文件: Ref.cs 项目: dev218/GitSharp
 /// <summary>
 /// Updates this ref by forwarding it to the given object.
 /// </summary>
 /// <param name="reference">The ref this object shall reference.</param>
 public void Update(AbstractObject reference)
 {
     var db = _repo._internal_repo;
     var updateRef = db.UpdateRef(RefName);
     updateRef.NewObjectId = reference._id;
     updateRef.IsForceUpdate = true;
     updateRef.update();
     //db.WriteSymref(Name, other.Name);
 }
示例#5
0
文件: Ref.cs 项目: dev218/GitSharp
 public static void Update(string name, AbstractObject reference)
 {
     new Ref(reference.Repository, name).Update(reference);
 }
示例#6
0
 public Diff Diff(AbstractObject other)
 {
 }
示例#7
0
 public Diff Diff(AbstractObject other)
 {
 }
示例#8
0
 internal AbstractObject Get(ObjectId id)
 {
     return(AbstractObject.Wrap(this, id));
 }
示例#9
0
文件: Ref.cs 项目: kkl713/GitSharp
 public static void Update(string name, AbstractObject reference)
 {
     new Ref(reference.Repository, name).Update(reference);
 }