Example #1
0
        public void ShouldBeAbleToReadAuthorDate()
        {
            var expectedDate = new DateTimeOffset();

            try
            {
                expectedDate = DateTimeOffset.Parse("2005-04-07 15:32:13 -07:00");
            }
            catch (NotImplementedException)
            {
                Assert.Ignore("Doesn't pass on Mono because of 'System.NotImplementedException : The requested feature is not implemented.at System.DateTimeOffset.Parse'.");
            }

            var repos = new Repository(db);
            var commit = new Commit(repos, KnownCommit);

            Assert.AreEqual(expectedDate, commit.AuthorDate);
        }
Example #2
0
 private static void CollectAncestorIdsRecursive(Commit commit, IDictionary<ObjectId, Commit> ancestors)
 {
     foreach (var parent in commit.InternalCommit.ParentIds.Where(id => !ancestors.ContainsKey(id)).Select(id => new Commit(commit._repo, id)))
     {
         var parentCommit = parent;
         ancestors[parentCommit._id] = parentCommit;
         CollectAncestorIdsRecursive(parentCommit, ancestors);
     }
 }
Example #3
0
        //public class Diff
        //{
        //    public List<AbstractObject> Modified = new List<AbstractObject>();
        //    public List<AbstractObject> Added = new List<AbstractObject>();
        //    public List<AbstractObject> Deleted = new List<AbstractObject>();
        //    public List<AbstractObject> TypeChanged = new List<AbstractObject>();
        //}
        /// <summary>
        /// Compares this commit against another one and returns all changes between the two.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public IEnumerable<Change> CompareAgainst(Commit other)
        {
            var changes = new List<Change>();
            var db = _repo._internal_repo;
            var pathFilter = TreeFilter.ALL;
            var walk = new TreeWalk(db);
            walk.reset(new GitSharp.Core.AnyObjectId[] { this.Tree._id, other.Tree._id });
            walk.Recursive = true;
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
            Debug.Assert(walk.getTreeCount() == 2);
            while (walk.next())
            {
                //for (int i = 1; i < nTree; i++)
                //    out.print(':');
                //for (int i = 0; i < nTree; i++) {
                //     var m = walk.getFileMode(i);
                //     String s = m.toString();
                //    for (int pad = 6 - s.length(); pad > 0; pad--)
                //        out.print('0');
                //    out.print(s);
                //    out.print(' ');
                //}

                //for (int i = 0; i < nTree; i++) {
                //    out.print(walk.getObjectId(i).name());
                //    out.print(' ');
                //}

                //char chg = 'M';
                int m0 = walk.getRawMode(0);
                int m1 = walk.getRawMode(1);
                var change = new Change()
                {
                    ReferenceCommit = this,
                    ComparedCommit = other,
                    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));
                }
            }
            return changes;
        }
Example #4
0
        public void ShouldBeAbleToReadCommitDate()
        {
            var repos = new Repository(db);
            var commit = new Commit(repos, KnownCommit);

            Assert.AreEqual(_expectedDate, commit.CommitDate);
        }
Example #5
0
        public static IObject CreateObject(string path)
        {
            logger.Trace("creating new Object from path {0}", path);            

            string digestString = Path.GetFileName(Path.GetDirectoryName(path)) + Path.GetFileName(path);
            logger.Trace("filename indicates digest of: {0}", digestString);
            byte[] digest = Encoding.ASCII.GetBytes(digestString.ToCharArray());
            
            byte[] buffer = new byte[MaxHeaderLength];
            using (ZlibStream input = new ZlibStream(File.Open(path, FileMode.Open, FileAccess.Read), CompressionMode.Decompress))
            {
                logger.Trace("reading {0} bytes", MaxHeaderLength);
                input.Read(buffer, 0, MaxHeaderLength);
            }

            string[] header = null;
            for (int i = 0; i < buffer.Length; i++)
            {
                if (buffer[i] == 0)
                {
                    header = new String(Encoding.ASCII.GetChars(buffer, 0, i)).Split(' ');
                    break;
                }   
            }

            logger.Trace("got header: {0} {1}", header[0], header[1]);           
            

            logger.Debug("got object of type {0}", header[0]);
            // TODO use header to create appropriate object
            Object result = null;            

            switch (header[0])
            {
                case "blob":
                    var blob = new Blob();                    
                    blob.m_Type = ObjectType.Blob;                    
                    result = blob;
                    break;
                case "tree":
                    var tree = new Tree();                    
                    tree.m_Type = ObjectType.Tree;                    
                    result = tree;
                    break;
                case "commit":
                    var commit = new Commit();
                    commit.m_Type = ObjectType.Commit;                    
                    result = commit;
                    break;
                case "tag":
                    break;
                default:
                    break;
            }

            result.m_Path = path;
            result.m_Digest = digest;
            result.m_Size = Convert.ToUInt64(header[1]);
            result.m_HeaderLen = header[0].Length + header[1].Length + 2; // + 2 to account for the ' ' and '\0'.
   
            return result;
        }
Example #6
0
 public void Init(Commit c1, Commit c2)
 {
     m_title.Content = "Differences between commits " + c1.ShortHash + " and " + c2.ShortHash;
     var changes=c1.CompareAgainst(c2);
     m_treediff.ItemsSource = changes;
 }
Example #7
0
 public void CommitConstructorTest()
 {
     Commit target = new Commit();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }