Example #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));
        }
Example #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));
     }
 }
Example #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);
         }
     }
 }
Example #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)));
        }
Example #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);
     }
 }
Example #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);
     }
 }
Example #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);
     }
 }
Example #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;
     }
 }
Example #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();
 }
Example #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);
     }
 }
Example #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());
        }
Example #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);
         }
     }
 }
Example #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);
            }
        }
Example #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);
         }
     }
 }
Example #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);
         }
     }
 }
Example #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)
             );
     }
 }
Example #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);
         }
     }
 }
Example #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);
     }
 }
Example #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);
            }
        }
Example #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);
         }
     }
 }
Example #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);
        }
Example #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);
        }
Example #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
                 );
         }
     }
 }
Example #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);
        }
Example #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));
 }
Example #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));
        }
Example #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();
        }
Example #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)));
        }
Example #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);
         }
     }
 }
Example #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);
     }
 }
Example #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));
     }
 }
Example #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);
         }
     }
 }
Example #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)
         );
     }
 }
Example #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);
         }
     }
 }
Example #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
             );
         }
     }
 }
Example #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);
                }
            }
        }