예제 #1
0
        public static Tree GetFixedTree(IEnumerable <TreeLine> treeLines)
        {
            var distinctTreeLines = new List <TreeLine>();

            // Treelines are ordered, so we only need to compare with the previous element, not all elements in the tree
            int i = 0;

            using (var it = treeLines.GetEnumerator())
            {
                if (it.MoveNext())
                {
                    distinctTreeLines.Add(it.Current);
                    ++i;
                }

                while (it.MoveNext())
                {
                    var treeLine = it.Current;
                    if (treeLine.TextBytes.Span.SpanEquals(distinctTreeLines[i++ - 1].TextBytes.Span))
                    {
                        --i;
                    }
                    else
                    {
                        distinctTreeLines.Add(treeLine);
                    }
                }
            }

            var serializedObject = GetSerializedObject(distinctTreeLines);

            return(GitObjectFactory.TreeFromContentBytes(serializedObject));
        }
        protected override void SynchronousStep(Commit commit)
        {
            var rewrittenParentHashes = GetRewrittenCommitHashes(commit.Parents);
            var changedCommit         = commit.WithChangedContributor(_contributorMappings, rewrittenParentHashes);

            var resultBytes   = GitObjectFactory.GetBytesWithHeader(GitObjectType.Commit, changedCommit);
            var newCommitHash = new ObjectHash(Hash.Create(resultBytes));

            EnqueueCommitWrite(commit.Hash, newCommitHash, resultBytes);
        }
        public static ITask <GitStatus> GetGitStatus(this IProcessManager processManager,
                                                     NPath workingDirectory,
                                                     IEnvironment environment, IProcessEnvironment gitEnvironment,
                                                     NPath?gitPath = null)
        {
            var gitStatusEntryFactory = new GitObjectFactory(environment);
            var processor             = new GitStatusOutputProcessor(gitStatusEntryFactory);

            NPath path = gitPath ?? defaultGitPath;

            return(new ProcessTask <GitStatus>(CancellationToken.None, processor)
                   .Configure(processManager, path, "status -b -u --porcelain", workingDirectory, false));
        }
예제 #4
0
        public void ShouldParseOddFile()
        {
            NPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions()
            {
                CurrentDirectory = @"c:\Projects\UnityProject"
            });

            var environment = Substitute.For <IEnvironment>();

            environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath());
            environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath());

            var gitObjectFactory = new GitObjectFactory(environment);
            var gitStatusEntry   = gitObjectFactory.CreateGitStatusEntry("c:UsersOculusGoVideo.mp4", GitFileStatus.None, GitFileStatus.Deleted);

            Assert.AreEqual(@"c:\Projects\UnityProject\c:UsersOculusGoVideo.mp4", gitStatusEntry.FullPath);
        }
        public void ShouldParseNormalFile()
        {
            SPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions()
            {
                CurrentDirectory = @"c:\Projects\UnityProject"
            });

            var environment = Substitute.For <IGitEnvironment>();

            environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToSPath());
            environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject");

            var gitObjectFactory = new GitObjectFactory(environment);
            var gitStatusEntry   = gitObjectFactory.CreateGitStatusEntry("hello.txt", GitFileStatus.None, GitFileStatus.Deleted);

            Assert.AreEqual(@"c:\Projects\UnityProject\hello.txt", gitStatusEntry.FullPath);
        }
예제 #6
0
        public Tag WithNewObject(string obj)
        {
            var resultBuffer = new byte[_content.Length];
            var resultIndex = 0;

            for (var i = 0; i < 7; i++)
                resultBuffer[resultIndex++] = _object.Span[i];

            var objBytes = Encoding.ASCII.GetBytes(obj);
            for (var i = 0; i < objBytes.Length; i++)
                resultBuffer[resultIndex++] = objBytes[i];

            resultBuffer[resultIndex++] = 10;

            for (var i = 0; i < _type.Length; i++)
                resultBuffer[resultIndex++] = _type.Span[i];

            resultBuffer[resultIndex++] = 10;

            for (var i = 0; i < _tag.Length; i++)
                resultBuffer[resultIndex++] = _tag.Span[i];

            resultBuffer[resultIndex++] = 10;

            if (_tagger.Length > 0)
            {
                for (var i = 0; i < _tagger.Length; i++)
                    resultBuffer[resultIndex++] = _tagger.Span[i];

                resultBuffer[resultIndex++] = 10;
            }

            for (var i = 0; i < _message.Length; i++)
                resultBuffer[resultIndex++] = _message.Span[i];

            return GitObjectFactory.TagFromContentBytes(resultBuffer);
        }
        protected override void SynchronousStep(Commit commit)
        {
            if (commit.Parents.Count == 1)
            {
                var parentHash     = GetRewrittenCommitHash(commit.Parents.Single());
                var parentTreeHash = _commitsWithTreeHashes[parentHash];
                if (parentTreeHash == commit.TreeHash)
                {
                    // This commit will be removed
                    RegisterCommitChange(commit.Hash, parentHash);
                    return;
                }
            }

            // rewrite this commit
            var correctParents = GetRewrittenCommitHashes(commit.Parents).ToList();

            byte[] newCommitBytes;
            if (correctParents.SequenceEqual(commit.Parents))
            {
                newCommitBytes = commit.SerializeToBytes();
            }
            else
            {
                newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, commit.TreeHash,
                                                                                     correctParents);
            }

            var resultBytes = GitObjectFactory.GetBytesWithHeader(GitObjectType.Commit, newCommitBytes);

            var newCommitHash = new ObjectHash(Hash.Create(resultBytes));
            var newCommit     = new Commit(newCommitHash, newCommitBytes);

            _commitsWithTreeHashes.TryAdd(newCommitHash, newCommit.TreeHash);

            EnqueueCommitWrite(commit.Hash, newCommitHash, resultBytes);
        }
예제 #8
0
        public static void WriteObject(string basePath, GitObjectBase gitObject)
        {
            var bytesWithHeader = GitObjectFactory.GetBytesWithHeader(gitObject.Type, gitObject.SerializeToBytes());

            WriteFile(basePath, bytesWithHeader, gitObject.Hash.ToString());
        }