Ejemplo n.º 1
0
        public CommitRef(string branch, CommitId commitId)
        {
            if (string.IsNullOrWhiteSpace(branch))
            {
                throw new ArgumentNullException(nameof(branch));
            }

            Branch   = branch;
            CommitId = commitId;
        }
Ejemplo n.º 2
0
        public CommitRef(string name, CommitId commitId)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name     = name;
            CommitId = commitId;
        }
Ejemplo n.º 3
0
 public override int GetHashCode(CommitId obj) => Sha1Comparer.Default.GetHashCode(obj.Sha1);
Ejemplo n.º 4
0
 public override int Compare(CommitId x, CommitId y) => Sha1Comparer.Default.Compare(x.Sha1, y.Sha1);
Ejemplo n.º 5
0
 public override bool Equals(CommitId x, CommitId y) => Sha1Comparer.Default.Equals(x.Sha1, y.Sha1);
Ejemplo n.º 6
0
 public override int GetHashCode(CommitId obj) => obj.Sha1.GetHashCode();
Ejemplo n.º 7
0
 public override bool Equals(CommitId x, CommitId y) => x.Sha1.Equals(y.Sha1);
Ejemplo n.º 8
0
 public override int Compare(CommitId x, CommitId y) => x.Sha1.CompareTo(y.Sha1);
Ejemplo n.º 9
0
        public string                             Message => _message ?? string.Empty; // May be null due to default ctor

        #endregion

        #region De/Constructors

        public Commit(IReadOnlyList <CommitId> parents, TreeId?treeId, Audit author, Audit committer, string message)
        {
            TreeId    = treeId;
            Author    = author;
            Committer = committer;
            _message  = message;

            // We choose to coerce empty & null, so de/serialization round-trips with fidelity
            if (parents == null)
            {
                _parents = Array.Empty <CommitId>();
                return;
            }

            // Optimize for common cases 0, 1, 2, N
            switch (parents.Count)
            {
            case 0:
                _parents = Array.Empty <CommitId>();
                return;

            case 1:
                _parents = new CommitId[1] {
                    parents[0]
                };
                return;

            case 2:
            {
                var cmp = CommitIdComparer.Default.Compare(parents[0], parents[1]);
                switch (cmp)
                {
                // Silently de-duplicate
                case 0: _parents = new CommitId[1] {
                        parents[0]
                }; return;

                // Sort forward
                case -1: _parents = new CommitId[2] {
                        parents[0], parents[1]
                }; return;

                // Sort reverse
                default: _parents = new CommitId[2] {
                        parents[1], parents[0]
                }; return;
                }
            }

            default:
            {
                // Copy
                var array = new CommitId[parents.Count];
                for (var i = 0; i < parents.Count; i++)
                {
                    array[i] = parents[i];
                }

                // Sort: Delegate dispatch faster than interface (https://github.com/dotnet/coreclr/pull/8504)
                Array.Sort(array, CommitIdComparer.Default.Compare);

                // Distinct
                var j = 1;
                for (var i = 1; i < array.Length; i++)
                {
                    // If it's a duplicate, silently skip
                    if (CommitIdComparer.Default.Equals(array[i - 1], array[i]))
                    {
                        continue;
                    }

                    array[j++] = array[i];         // Increment target index iff distinct
                }

                if (j < array.Length)
                {
                    Array.Resize(ref array, j);
                }

                // Assign
                _parents = array;
            }
                return;
            }
        }
Ejemplo n.º 10
0
 public Commit(CommitId parent, TreeId treeId, Audit author, Audit committer, string message)
     : this(new[] { parent }, treeId, author, committer, message)
 {
 }