Represents a revision of the content tracked in the repository.
Inheritance: AbstractObject
 public CommitInformation(Commit commit, IInterestedContentExtractingStrategy strategy)
 {
     this.authorEmail = commit.Author.EmailAddress;
     this.committerEmail = commit.Committer.EmailAddress;
     this.commitDate = commit.CommitDate;
     this.strategy = strategy;
     this.sourceFileChanges = GetSourceChanges(commit, strategy);
 }
示例#2
0
 //private void SelectConfiguration(object obj)
 //{
 //    if (obj is Entry)
 //    {
 //        var entry = obj as dotGit.Config.Entry;
 //        m_config_name.Content = entry.FullName;
 //        if (entry.Value != null)
 //            m_config_value.Text = entry.Value;
 //    }
 //}
 private void DisplayCommit(Commit commit, string info)
 {
     if (commit == null)
         return;
     var list = commit.Ancestors.ToList();
     list.Insert(0, commit);
     m_commits.ItemsSource = list;
     m_commits.SelectedIndex = 0;
     m_commit_title.Text = "Commit history for " + info;
 }
 public CommitViewModel(Repository repository, RepositoryNavigationRequest request, Commit commit, bool fillParents)
     : base(new RepositoryNavigationRequest(request) { Treeish = commit.Hash })
 {
     if (fillParents)
     {
         Parents = new List<CommitViewModel>(commit.Parents.Select(x =>
             new CommitViewModel(repository, request, x, false)));
     }
     Tree = new TreeNodeViewModel(repository, request, commit.Tree);
     Commit = commit;
 }
示例#4
0
        public GitObject CreateFromContent(string content)
        {
            string[] headerAndRest = content.Split('\0');
            string header = headerAndRest[0];

            GitObject obj;

            if (header.StartsWith("commit"))
                obj = new Commit();
            else
                throw new NotImplementedException("Support for file type is not implemented.");

            obj.Load(content);

            return obj;
        }
示例#5
0
        private static IEnumerable<CommitInformation> AnalyzeRevisionHistory(Commit head, 
            IInterestedContentExtractingStrategy strategy)
        {
            var commitInfors = new List<CommitInformation>();

            // Translate every commit to a commit information and add them to the list.
            for (; head != null; head = head.Parent)
            {
                var infor = new CommitInformation(head, strategy);
                if(infor.HasInterestedContent())
                {
                    commitInfors.Insert(0, infor);
                };
            }
            return commitInfors;
        }
        private void Collect(Commit commit)
        {
            if (commit.CommitDate < _commitTimeTreshold && _counter > _minCommits)
            {
                return;
            }

            _results.Add(commit);
            _counter += 1;
            if (!commit.HasParents)
            {
                return;
            }

            foreach (var parent in commit.Parents)
            {
                Collect(parent);
            }
        }
        public CommitDetailsViewModel(Repository repository, RepositoryNavigationRequest request, Commit commit)
            : this(repository, new RepositoryNavigationRequest(request) { Treeish = commit.Hash })
        {
            CurrentCommit = new CommitViewModel(repository, request, commit, true);

            foreach (var change in commit.Changes)
            {
                // PASTE-START : borrowed from GitSharp.Demo
                var a = (change.ReferenceObject != null ? (change.ReferenceObject as Blob).RawData : new byte[0]);
                var b = (change.ComparedObject != null ? (change.ComparedObject as Blob).RawData : new byte[0]);

                a = (Diff.IsBinary(a) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + a.Length) : a);
                b = (Diff.IsBinary(b) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + b.Length) : b);
                // PASTE-END : borrowed from GitSharp.Demo

                var diff = new Diff(a, b);
                Changes.Add(new ChangeViewModel(request, change, diff));
            }
        }
        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;
        }
示例#9
0
        private Commit ResolveCommit(string commitHash)
        {
            var commit = new Commit(_repo, commitHash);

            if (!commit.IsCommit)
            {
                throw new ArgumentException(string.Format("The provided hash ({0}) does not point to a commit.", commitHash));
            }

            return commit;
        }
示例#10
0
 private static void ResetSoft(Commit commit)
 {
     Ref.Update("HEAD", commit);
 }
示例#11
0
 private void ResetHard(Commit commit)
 {
     commit.Checkout(_repo.WorkingDirectory);
     _repo._internal_repo.Index.write();
     Ref.Update("HEAD", commit);
 }
示例#12
0
 public void Reset(Commit commit)
 {
     Reset(commit, DEFAULT_RESET_BEHAVIOR);
 }
示例#13
0
        public void Reset(Commit commit, ResetBehavior resetBehavior)
        {
            if (commit == null)
            {
                throw new ArgumentNullException("commit");
            }

            switch (resetBehavior)
            {
                case ResetBehavior.Hard:
                    ResetHard(commit);
                    break;

                case ResetBehavior.Soft:
                    ResetSoft(commit);
                    break;

                case ResetBehavior.Mixed:
                case ResetBehavior.Merge:
                    throw new NotImplementedException();

                default:
                    throw new NotSupportedException(string.Format("{0} is not supported.", resetBehavior));
            }
        }
示例#14
0
        public ObjectId WriteCommit(Commit c)
        {
            Encoding encoding = c.Encoding;
            if (encoding == null)
                encoding = Constants.CHARSET;
            var os = new MemoryStream();
            var w = new BinaryWriter(os);
            StreamWriter sw;
            if (encoding != Constants.CHARSET)
                sw = new StreamWriter(os, encoding);
            else
                sw = new StreamWriter(os);

            w.Write(htree);
            w.Write(' ');
            c.TreeId.CopyTo(os);
            w.Write('\n');

            ObjectId[] ps = c.ParentIds;
            for (int i = 0; i < ps.Length; ++i)
            {
                w.Write(hparent);
                w.Write(' ');
                ps[i].CopyTo(os);
                w.Write('\n');
            }

            w.Write(hauthor);
            w.Write(' ');
            //w.Flush();
            sw.Write(c.Author.ToExternalString());
            sw.Flush();
            w.Write('\n');

            w.Write(hcommitter);
            w.Write(' ');
            //w.Flush();
            sw.Write(c.Committer.ToExternalString());
            sw.Flush();
            w.Write('\n');

            if (encoding != Encoding.UTF8)
            {
                w.Write(hencoding);
                w.Write(' ');
                w.Write(Constants.encodeASCII(encoding.HeaderName.ToUpper()));
                w.Write('\n');
            }

            w.Write('\n');
            //w.Flush();
            //var encoding_writer = new StreamWriter(os, encoding);
            //encoding_writer.Write(c.Message);
            //encoding_writer.Flush();
            sw.Write(c.Message);
            sw.Flush();
            return WriteCommit(os.ToArray());
        }
示例#15
0
 /// <summary>
 /// Create a new branch from the given commit
 /// </summary>
 /// <param name="repo"></param>
 /// <param name="name">The name of the branch to create (i.e. "master", not "refs/heads/master")</param>
 /// <param name="commit">The commit to base the branch on.</param>
 /// <returns>returns the newly created Branch object</returns>
 public static Branch Create(Repository repo, string name, Commit commit)
 {
     if (string.IsNullOrEmpty(name))
         throw new ArgumentException("Branch name must not be null or empty", "name");
     if (commit == null || !commit.IsCommit)
         throw new ArgumentException("Invalid commit", "commit");
     Ref.Update("refs/heads/" + name, commit);
     return new Branch(repo, name);
 }
        private bool TryGetCommit(string treeName, out Commit commit)
        {
            commit = null;
            try
            {
                var current = new Commit(_repository, treeName);
                if (current.IsCommit)
                {
                    commit = current;
                    return true;
                }
            }
            catch (ArgumentException)
            {
                return false;
            }

            return false;
        }
 protected static long min_changeset()
 {
     if (_minChangesetChache == null)
     {
         _head = _repo.Get<Commit>("HEAD");
         return (_head.Ancestors.Count() + 1) - MAX_NUMBER_OF_REVISIONS_TO_RECEIVE;
     }
     return (long)_minChangesetChache;
 }
示例#18
0
 /// <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)
 {
     return CompareCommits(this, other);
 }
示例#19
0
        // Returns a list of latest commits
        public List<SparkleCommit> GetCommits(int count)
        {
            if (count <= 0)
                return null;

            List <SparkleCommit> commits = new List <SparkleCommit> ();

            string commit_ref = "HEAD";

            try {

                for (int i = 0; i < count; i++) {

                    Commit commit = new Commit (this, commit_ref);

                    SparkleCommit sparkle_commit = new SparkleCommit ();

                    sparkle_commit.UserName  = commit.Author.Name;
                    sparkle_commit.UserEmail = commit.Author.EmailAddress;
                    sparkle_commit.DateTime  = commit.CommitDate.DateTime;
                    sparkle_commit.Hash      = commit.Hash;

                    foreach (Change change in commit.Changes) {

                        if (change.ChangeType.ToString ().Equals ("Added"))
                            sparkle_commit.Added.Add (change.Path);

                        if (change.ChangeType.ToString ().Equals ("Modified"))
                            sparkle_commit.Edited.Add (change.Path);

                        if (change.ChangeType.ToString ().Equals ("Deleted"))
                            sparkle_commit.Deleted.Add (change.Path);

                    }

                    commits.Add (sparkle_commit);
                    commit_ref += "^";

                }

            } catch (System.NullReferenceException) {

                // FIXME: Doesn't show the first commit because it throws
                // this exception before getting to it. Seems to be a bug in GitSharp

            }

            return commits;
        }
示例#20
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);
 }
示例#21
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author)
 {
     return Create(message, parent, tree, author, author, DateTimeOffset.Now);
 }
示例#22
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);
 }
示例#23
0
        /// <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;
        }
 public CommitHarvester(Commit root, DateTime? commitTimeTreshold, int minCommits)
 {
     _minCommits = minCommits;
     _commitTimeTreshold = commitTimeTreshold;
     _root = root;
 }
示例#25
0
        private List<SourceFileChange> GetSourceChanges(Commit commit, 
            IInterestedContentExtractingStrategy strategy)
        {
            var sourceChanges = new List<SourceFileChange>();

            // Get the changes that are changing the C# source code.
            var changes = commit.Changes.Where(c => c.Name.EndsWith(".cs") &&
                c.ChangedObject.IsBlob);

            if (changes.Any())
            {
                // For each change in the found changes.
                foreach (var change in changes)
                {
                    // Get the file name of where the change is performed on.
                    string fileName = change.Name;

                    // Get the source after change.
                    string source = ((Blob)change.ChangedObject).Data;

                    // Get the interested content from the source code.
                    var interestedContent = strategy.GetInterestedContent(source);
                    if (strategy.HasInterestedContent(interestedContent))
                    {
                        sourceChanges.Add(new SourceFileChange()
                        {
                            fileName = fileName,
                            interestedContents = strategy.GetInterestedContent(source)
                        });
                    }
                }
            }
            return sourceChanges;
        }
示例#26
0
        ///	<summary>
        /// Write a Commit to the object database
        ///	</summary>
        ///	<param name="c">Commit to store.</param>
        ///	<returns>SHA-1 of the commit.</returns>
        ///	<exception cref="IOException"></exception>
        public ObjectId WriteCommit(Commit c)
        {
            Encoding encoding = c.Encoding ?? Constants.CHARSET;
            var output = new MemoryStream();
            var s = new BinaryWriter(output, encoding);
            s.Write(HTree);
            s.Write(' ');
            c.TreeId.CopyTo(s);
            s.Write('\n');
            ObjectId[] parentIds = c.ParentIds;
            for (int i = 0; i < parentIds.Length; i++)
            {
                s.Write(HParent);
                s.Write(' ');
                parentIds[i].CopyTo(s);
                s.Write('\n');
            }
            s.Write(HAuthor);
            s.Write(' ');
            s.Write(c.Author.ToExternalString().ToCharArray());
            s.Write('\n');
            s.Write(HCommitter);
            s.Write(' ');
            s.Write(c.Committer.ToExternalString().ToCharArray());
            s.Write('\n');

            if (encoding != Constants.CHARSET)
            {
                s.Write(HEncoding);
                s.Write(' ');
                s.Write(Constants.encodeASCII(encoding.HeaderName.ToUpperInvariant()));
                s.Write('\n');
            }

            s.Write('\n');
            s.Write(c.Message.ToCharArray());

            return WriteCommit(output.ToArray());
        }
示例#27
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);
     }
 }
        protected Collection<Commit> QueryChangesetsLog()
        {
            _head = _repo.Get<Commit>("HEAD");
            if (changesetsLog == null)
            {
                Collection<Commit> log = new Collection<Commit>();

                foreach (Commit c in _head.Ancestors)
                {
                    log.Add(c);
                }

                changesetsLog = log;
            }
            return changesetsLog;
        }
示例#29
0
        public void Commit()
        {
            // Get the message of the previous commit
            string msg = new Commit(repo, "HEAD^").Message;
            Debug.Assert(msg == repo.CurrentBranch.CurrentCommit.Parent.Message);

            //Print a list of changes between two commits c1 and c2:
            Commit c1 = repo.Get<Commit>( "979829389f136bfabb5956c68d909e7bf3092a4e"); // <-- note: short hashes are not yet supported
            Commit c2 = new Commit(repo, "4a7455c2f23e0f7356877d1813594041c56e2db9");
            foreach (Change change in c1.CompareAgainst(c2))
                Console.WriteLine(change.ChangeType + ": " + change.Path);

            //Print all previous commits of HEAD of the repository repo
            foreach (Commit commit in repo.Head.CurrentCommit.Ancestors)
                Console.WriteLine(commit.ShortHash + ": " + commit.Message + ", " + commit.Author.Name + ", " + commit.AuthorDate);
        }
示例#30
0
文件: Commit.cs 项目: gilran/GitSharp
 private static void CollectAncestorIdsRecursive(Commit commit, Dictionary<ObjectId, Commit> ancestors)
 {
     foreach (var parent in commit.ParentIds.Where(id => !ancestors.ContainsKey(id)).Select(id => commit.Repository.OpenCommit(id)))
     {
         var parent_commit = parent as Commit;
         ancestors[parent_commit.CommitId] = parent_commit;
         CollectAncestorIdsRecursive(parent_commit, ancestors);
     }
 }