Пример #1
0
        public LogEntry CopyTree(GitIndexInfo index)
        {
            var startTime = DateTime.Now;
            var itemsCopied = 0;
            var maxChangesetId = 0;
            var tfsTreeEntries = GetTree().ToArray();
            if (tfsTreeEntries.Length == 0)
            {
                maxChangesetId = _changeset.ChangesetId;
            }
            else
            {
                foreach (var entry in tfsTreeEntries)
                {
                    Add(entry.Item, entry.FullName, index);
                    maxChangesetId = Math.Max(maxChangesetId, entry.Item.ChangesetId);

                    itemsCopied++;
                    if (DateTime.Now - startTime > TimeSpan.FromSeconds(30))
                    {
                        _stdout.WriteLine("{0} objects created...", itemsCopied);
                        startTime = DateTime.Now;
                    }
                }
            }
            return MakeNewLogEntry(maxChangesetId == _changeset.ChangesetId ? _changeset : _tfs.GetChangeset(maxChangesetId));
        }
Пример #2
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace)
 {
     if (item.DeletionId == 0)
     {
         index.Update(Mode.NewFile, pathInGitRepo, workspace.GetLocalPath(pathInGitRepo));
     }
 }
Пример #3
0
 private void Apply(IChange change, GitIndexInfo index, ITfsWorkspace workspace, IDictionary <string, GitObject> initialTree)
 {
     // If you make updates to a dir in TF, the changeset includes changes for all the children also,
     // and git doesn't really care if you add or delete empty dirs.
     if (change.Item.ItemType == TfsItemType.File)
     {
         var pathInGitRepo = GetPathInGitRepo(change.Item.ServerItem, workspace.Remote, initialTree);
         if (pathInGitRepo == null || Summary.Remote.ShouldSkip(pathInGitRepo))
         {
             return;
         }
         if (change.ChangeType.IncludesOneOf(TfsChangeType.Rename))
         {
             Rename(change, pathInGitRepo, index, workspace, initialTree);
         }
         else if (change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
         {
             Delete(pathInGitRepo, index, initialTree);
         }
         else
         {
             Update(change, pathInGitRepo, index, workspace, initialTree);
         }
     }
 }
Пример #4
0
        public LogEntry CopyTree(GitIndexInfo index, ITfsWorkspace workspace)
        {
            var startTime      = DateTime.Now;
            var itemsCopied    = 0;
            var maxChangesetId = 0;
            var tfsTreeEntries = GetTree().ToArray();

            if (tfsTreeEntries.Length == 0)
            {
                maxChangesetId = _changeset.ChangesetId;
            }
            else
            {
                workspace.Get(_changeset.ChangesetId);
                foreach (var entry in tfsTreeEntries)
                {
                    Add(entry.Item, entry.FullName, index, workspace);
                    maxChangesetId = Math.Max(maxChangesetId, entry.Item.ChangesetId);

                    itemsCopied++;
                    if (DateTime.Now - startTime > TimeSpan.FromSeconds(30))
                    {
                        _stdout.WriteLine("{0} objects created...", itemsCopied);
                        startTime = DateTime.Now;
                    }
                }
            }
            return(MakeNewLogEntry(maxChangesetId == _changeset.ChangesetId ? _changeset : _tfs.GetChangeset(maxChangesetId)));
        }
Пример #5
0
 private static int Do(TextWriter stdin, IGitRepository repository, Action <GitIndexInfo> action)
 {
     using (var indexInfo = new GitIndexInfo(stdin, repository))
     {
         action(indexInfo);
         return(indexInfo.nr);
     }
 }
Пример #6
0
 private void Delete(string pathInGitRepo, GitIndexInfo index, IDictionary <string, GitObject> initialTree)
 {
     if (initialTree.ContainsKey(pathInGitRepo))
     {
         index.Remove(initialTree[pathInGitRepo].Path);
         Trace.WriteLine("\tD\t" + pathInGitRepo);
     }
 }
Пример #7
0
 private void Delete(string pathInGitRepo, GitIndexInfo index, IDictionary<string, GitObject> initialTree)
 {
     if(initialTree.ContainsKey(pathInGitRepo))
     {
         index.Remove(initialTree[pathInGitRepo].Path);
         Trace.WriteLine("\tD\t" + pathInGitRepo);
     }
 }
Пример #8
0
 private static int Do(TextWriter stdin, IGitRepository repository, Action<GitIndexInfo> action)
 {
     using (var indexInfo = new GitIndexInfo(stdin, repository))
     {
         action(indexInfo);
         return indexInfo.nr;
     }
 }
Пример #9
0
 public LogEntry Apply(string lastCommit, GitIndexInfo index)
 {
     var initialTree = Summary.Remote.Repository.GetObjects(lastCommit);
     foreach (var change in Sort(_changeset.Changes))
     {
         Apply(change, index, initialTree);
     }
     return MakeNewLogEntry();
 }
Пример #10
0
 public void Update(Change change, string pathInGitRepo, GitIndexInfo index, IDictionary<string, GitObject> initialTree)
 {
     using (var tempFile = new TemporaryFile())
     {
         change.Item.DownloadFile(tempFile);
         index.Update(GetMode(change, initialTree, pathInGitRepo),
                      UpdateDirectoryToMatchExtantCasing(pathInGitRepo, initialTree),
                      tempFile);
     }
 }
Пример #11
0
        public LogEntry Apply(string lastCommit, GitIndexInfo index)
        {
            var initialTree = Summary.Remote.Repository.GetObjects(lastCommit);

            foreach (var change in Sort(_changeset.Changes))
            {
                Apply(change, index, initialTree);
            }
            return(MakeNewLogEntry());
        }
Пример #12
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if (item.DeletionId == 0)
     {
         // Download the content directly into the git database as a blob:
         using (var temp = item.DownloadFile())
         {
             index.Update(Mode.NewFile, pathInGitRepo, temp);
         }
     }
 }
Пример #13
0
        private void ApplyAdds(Change change, GitIndexInfo index, IDictionary<string, GitObject> initialTree)
        {
            var pathInGitRepo = Summary.Remote.GetPathInGitRepo(change.Item.ServerItem);
            if (pathInGitRepo == null || Summary.Remote.ShouldSkip(pathInGitRepo))
                return;

            if (change.ChangeType != ChangeType.Delete)
            {
                Update(change, pathInGitRepo, index, initialTree);
            }
        }
Пример #14
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if (item.DeletionId == 0)
     {
         using (var tempFile = new TemporaryFile())
         {
             item.DownloadFile(tempFile);
             index.Update(Mode.NewFile, pathInGitRepo, tempFile);
         }
     }
 }
Пример #15
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if (item.DeletionId == 0)
     {
         // Download the content directly into the index as a blob:
         using (var stream = item.DownloadFile())
         {
             index.Update(Mode.NewFile, pathInGitRepo, stream, item.ContentLength);
         }
     }
 }
Пример #16
0
 private void Update(IChange change, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace, IDictionary <string, GitObject> initialTree)
 {
     if (change.Item.DeletionId == 0)
     {
         index.Update(
             GetMode(change, initialTree, pathInGitRepo),
             pathInGitRepo,
             workspace.GetLocalPath(pathInGitRepo)
             );
     }
 }
Пример #17
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if(item.DeletionId == 0)
     {
         using(var tempFile = new TemporaryFile())
         {
             item.DownloadFile(tempFile);
             index.Update(Mode.NewFile, pathInGitRepo, tempFile);
         }
     }
 }
Пример #18
0
 private void Rename(IChange change, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace, IDictionary<string, GitObject> initialTree)
 {
     var oldPath = GetPathInGitRepo(GetPathBeforeRename(change.Item), initialTree);
     if (oldPath != null)
     {
         Delete(oldPath, index, initialTree);
     }
     if (!change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
     {
         Update(change, pathInGitRepo, index, workspace, initialTree);
     }
 }
Пример #19
0
        private void Rename(IChange change, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace, IDictionary <string, GitObject> initialTree)
        {
            var oldPath = GetPathInGitRepo(GetPathBeforeRename(change.Item), workspace.Remote, initialTree);

            if (oldPath != null)
            {
                Delete(oldPath, index, initialTree);
            }
            if (!change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
            {
                Update(change, pathInGitRepo, index, workspace, initialTree);
            }
        }
Пример #20
0
 private void Update(IChange change, string pathInGitRepo, GitIndexInfo index, IDictionary <string, GitObject> initialTree)
 {
     if (change.Item.DeletionId == 0)
     {
         using (var tempFile = new TemporaryFile())
         {
             change.Item.DownloadFile(tempFile);
             index.Update(GetMode(change, initialTree, pathInGitRepo),
                          pathInGitRepo,
                          tempFile);
         }
     }
 }
Пример #21
0
        private LogEntry CopyTree(string lastCommit, ITfsChangeset changeset)
        {
            LogEntry result = null;

            WithTemporaryIndex(
                () => GitIndexInfo.Do(Repository, index => result = changeset.CopyTree(index)));
            WithTemporaryIndex(
                () => result.Tree = Repository.CommandOneline("write-tree"));
            if (!String.IsNullOrEmpty(lastCommit))
            {
                result.CommitParents.Add(lastCommit);
            }
            return(result);
        }
Пример #22
0
        private LogEntry CopyTree(string lastCommit, ITfsChangeset changeset)
        {
            LogEntry result = null;

            WithTemporaryIndex(() => Tfs.WithWorkspace(WorkingDirectory, this, changeset.Summary, workspace => {
                GitIndexInfo.Do(Repository, index => result = changeset.CopyTree(index, workspace));
                result.Tree = Repository.CommandOneline("write-tree");
            }));
            if (!String.IsNullOrEmpty(lastCommit))
            {
                result.CommitParents.Add(lastCommit);
            }
            return(result);
        }
Пример #23
0
 private void Update(IChange change, string pathInGitRepo, GitIndexInfo index, IDictionary <string, GitObject> initialTree)
 {
     if (change.Item.DeletionId == 0)
     {
         using (var stream = change.Item.DownloadFile())
         {
             index.Update(
                 GetMode(change, initialTree, pathInGitRepo),
                 pathInGitRepo,
                 stream,
                 change.Item.ContentLength
                 );
         }
     }
 }
Пример #24
0
        private LogEntry Apply(string parent, ITfsChangeset changeset)
        {
            LogEntry result = null;

            WithTemporaryIndex(() => WithWorkspace(changeset.Summary, workspace =>
            {
                AssertTemporaryIndexClean(parent);
                GitIndexInfo.Do(Repository, index => result = changeset.Apply(parent, index, workspace));
                result.Tree = Repository.CommandOneline("write-tree");
            }));
            if (!String.IsNullOrEmpty(parent))
            {
                result.CommitParents.Add(parent);
            }
            return(result);
        }
Пример #25
0
 public LogEntry CopyTree(GitIndexInfo index)
 {
     var maxChangesetId = 0;
     foreach(var item in changeset.VersionControlServer.GetItems(Summary.Remote.TfsRepositoryPath, changeset.ChangesetId, TfsRecursionType.Full))
     {
         if (item.ItemType == TfsItemType.File)
         {
             var pathInGitRepo = Summary.Remote.GetPathInGitRepo(item.ServerItem);
             if (pathInGitRepo != null && !Summary.Remote.ShouldSkip(pathInGitRepo))
             {
                 Add(item, pathInGitRepo, index);
                 maxChangesetId = Math.Max(maxChangesetId, item.ChangesetId);
             }
         }
     }
     return MakeNewLogEntry(tfs.GetChangeset(maxChangesetId));
 }
Пример #26
0
        public LogEntry CopyTree(GitIndexInfo index)
        {
            var startTime = DateTime.Now;
            var itemsCopied = 0;
            var maxChangesetId = 0;
            foreach (var entry in GetTree())
            {
                Add(entry.Item, entry.FullName, index);
                maxChangesetId = Math.Max(maxChangesetId, entry.Item.ChangesetId);

                itemsCopied++;
                if(DateTime.Now - startTime > TimeSpan.FromSeconds(30))
                {
                    _stdout.WriteLine("" + itemsCopied + " objects created...");
                    startTime = DateTime.Now;
                }
            }
            return MakeNewLogEntry(maxChangesetId == _changeset.ChangesetId ? _changeset : _tfs.GetChangeset(maxChangesetId));
        }
Пример #27
0
        public LogEntry Apply(string lastCommit, GitIndexInfo index, TfsFailTracker failTracker)
        {
            var initialTree = Summary.Remote.Repository.GetObjects(lastCommit);

            // If you make updates to a dir in TF, the changeset includes changes for all the children also,
            // and git doesn't really care if you add or delete empty dirs.
            var fileChanges = changeset.Changes.Where(c => c.Item.ItemType == ItemType.File);

            foreach(var change in fileChanges)
            {
                ApplyDelete(change, index, initialTree, failTracker);
            }

            foreach (var change in fileChanges)
            {
                ApplyAdds(change, index, initialTree);
            }

            return MakeNewLogEntry();
        }
Пример #28
0
        public LogEntry CopyTree(GitIndexInfo index)
        {
            var startTime      = DateTime.Now;
            var itemsCopied    = 0;
            var maxChangesetId = 0;

            foreach (var entry in GetTree())
            {
                Add(entry.Item, entry.FullName, index);
                maxChangesetId = Math.Max(maxChangesetId, entry.Item.ChangesetId);

                itemsCopied++;
                if (DateTime.Now - startTime > TimeSpan.FromSeconds(30))
                {
                    _stdout.WriteLine("" + itemsCopied + " objects created...");
                    startTime = DateTime.Now;
                }
            }
            return(MakeNewLogEntry(maxChangesetId == _changeset.ChangesetId ? _changeset : _tfs.GetChangeset(maxChangesetId)));
        }
Пример #29
0
 private void Apply(IChange change, GitIndexInfo index, ITfsWorkspace workspace, IDictionary<string, GitObject> initialTree)
 {
     // If you make updates to a dir in TF, the changeset includes changes for all the children also,
     // and git doesn't really care if you add or delete empty dirs.
     if (change.Item.ItemType == TfsItemType.File)
     {
         var pathInGitRepo = GetPathInGitRepo(change.Item.ServerItem, initialTree);
         if (pathInGitRepo == null || Summary.Remote.ShouldSkip(pathInGitRepo))
             return;
         if (change.ChangeType.IncludesOneOf(TfsChangeType.Rename))
         {
             Rename(change, pathInGitRepo, index, workspace, initialTree);
         }
         else if (change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
         {
             Delete(pathInGitRepo, index, initialTree);
         }
         else
         {
             Update(change, pathInGitRepo, index, workspace, initialTree);
         }
     }
 }
Пример #30
0
 private void Rename(Change change, string pathInGitRepo, GitIndexInfo index, IDictionary<string, GitObject> initialTree)
 {
     var oldPath = Summary.Remote.GetPathInGitRepo(GetPathBeforeRename(change.Item));
     if (oldPath != null)
     {
         Delete(oldPath, index, initialTree);
     }
     if (!change.ChangeType.IncludesOneOf(ChangeType.Delete))
     {
         Update(change, pathInGitRepo, index, initialTree);
     }
 }
Пример #31
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace)
 {
     if (item.DeletionId == 0)
     {
         index.Update(Mode.NewFile, pathInGitRepo, workspace.GetLocalPath(pathInGitRepo));
     }
 }
Пример #32
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if (item.DeletionId == 0)
     {
         // Download the content directly into the git database as a blob:
         using (var temp = item.DownloadFile())
         {
             index.Update(Mode.NewFile, pathInGitRepo, temp);
         }
     }
 }
Пример #33
0
 private void Update(IChange change, string pathInGitRepo, GitIndexInfo index, ITfsWorkspace workspace, IDictionary<string, GitObject> initialTree)
 {
     if (change.Item.DeletionId == 0)
     {
         index.Update(
             GetMode(change, initialTree, pathInGitRepo),
             pathInGitRepo,
             workspace.GetLocalPath(pathInGitRepo)
         );
     }
 }
Пример #34
0
 private void Add(IItem item, string pathInGitRepo, GitIndexInfo index)
 {
     if(item.DeletionId == 0)
     {
         // Download the content directly into the index as a blob:
         using (var stream = item.DownloadFile())
         {
             index.Update(Mode.NewFile, pathInGitRepo, stream, item.ContentLength);
         }
     }
 }
Пример #35
0
 private void Update(IChange change, string pathInGitRepo, GitIndexInfo index, IDictionary<string, GitObject> initialTree)
 {
     if (change.Item.DeletionId == 0)
     {
         using (var temp = change.Item.DownloadFile())
         {
             index.Update(
                 GetMode(change, initialTree, pathInGitRepo),
                 pathInGitRepo,
                 temp
             );
         }
     }
 }
Пример #36
0
        void ApplyDelete(Change change, GitIndexInfo index, IDictionary<string, GitObject> initialTree, TfsFailTracker failTracker)
        {
            if (change.Item.DeletionId != 0)
            {
                string oldPath = null;

                try
                {
                    oldPath = Summary.Remote.GetPathInGitRepo(GetPathBeforeRename(change.Item));
                } catch (Exception e)
                {
                    failTracker.TrackFailureLoadingChange(change.Item.ChangesetId, change.ChangeType, change.Item.ServerItem, "Unable to locate deleted item");
                }

                if (oldPath != null)
                {
                    Delete(oldPath, index, initialTree);
                }
            }
        }