diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-02-06 17:11:56 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-02-06 17:11:56 +0400 |
commit | ccb97d728804dbc7c856f1317d4ef0360d976f8a (patch) | |
tree | 6ee118f2f3b727f0be9034fea48cefd6e3a8e2f2 /main/src | |
parent | 9eb4daabaeac957da280fa3a953f97924f2e16ee (diff) | |
parent | a323259ce9092dfb4524c0799981d0720e15c534 (diff) |
Merge branch 'master' into newresolver
Diffstat (limited to 'main/src')
3 files changed, 24 insertions, 189 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs index 2b21cd1348..2850a1f95c 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs @@ -163,7 +163,7 @@ namespace MonoDevelop.VersionControl.Git RevWalk walk = new RevWalk (repo); string path = ToGitPath (localFile); if (path != ".") - walk.SetTreeFilter (AndTreeFilter.Create (TreeFilter.ANY_DIFF, PathFilter.Create (path))); + walk.SetTreeFilter (FollowFilter.Create (path)); walk.MarkStart (hc); foreach (RevCommit commit in walk) { @@ -644,8 +644,8 @@ namespace MonoDevelop.VersionControl.Git List<FilePath> changedFiles = new List<FilePath> (); List<FilePath> removedFiles = new List<FilePath> (); - monitor.BeginTask (GettextCatalog.GetString ("Revering files"), 3); - monitor.BeginStepTask (GettextCatalog.GetString ("Revering files"), localPaths.Length, 2); + monitor.BeginTask (GettextCatalog.GetString ("Reverting files"), 3); + monitor.BeginStepTask (GettextCatalog.GetString ("Reverting files"), localPaths.Length, 2); DirCache dc = repo.LockDirCache (); DirCacheBuilder builder = dc.Builder (); @@ -1282,35 +1282,24 @@ namespace MonoDevelop.VersionControl.Git RevCommit hc = GetHeadCommit (); if (hc == null) return new Annotation [0]; - RevCommit[] lineCommits = GitUtil.Blame (repo, hc, repositoryPath); - int lineCount = lineCommits.Length; - List<Annotation> annotations = new List<Annotation>(lineCount); - for (int n = 0; n < lineCount; n++) { - RevCommit c = lineCommits[n]; - Annotation annotation = new Annotation (c.Name, c.GetAuthorIdent ().GetName () + "<" + c.GetAuthorIdent ().GetEmailAddress () + ">", c.GetCommitterIdent ().GetWhen ()); - annotations.Add(annotation); - } - - Document baseDocument = new Document (GetCommitTextContent (hc, repositoryPath)); - Document workingDocument = new Document (File.ReadAllText (repositoryPath)); - Annotation uncommittedRev = new Annotation("0000000000000000000000000000000000000000", "", new DateTime()); - // Based on Subversion code until we support blame on things other than commits - foreach (var hunk in baseDocument.Diff (workingDocument)) { - annotations.RemoveRange (hunk.RemoveStart, hunk.Removed); - int start = hunk.InsertStart - 1; //Line number - 1 = index - bool insert = (start < annotations.Count); - - for (int i = 0; i < hunk.Inserted; ++i) { - if (insert) { - annotations.Insert (start, uncommittedRev); - } else { - annotations.Add (uncommittedRev); - } + var git = new NGit.Api.Git (repo); + var result = git.Blame ().SetFilePath (ToGitPath (repositoryPath)).Call (); + result.ComputeAll (); + + List<Annotation> list = new List<Annotation> (); + for (int i = 0; i < result.GetResultContents ().Size (); i++) { + var commit = result.GetSourceCommit (i); + var author = result.GetSourceCommitter (i); + if (commit != null && author != null) { + string name = string.Format ("{0} <{1}>", author.GetName (), author.GetEmailAddress ()); + var commitTime = new DateTime (1970, 1, 1).AddSeconds (commit.CommitTime); + list.Add (new Annotation (commit.Name, name, commitTime)); + } else { + list.Add (new Annotation (new string ('0', 20), "<uncommitted>", DateTime.Now)); } } - - return annotations.ToArray(); + return list.ToArray (); } internal GitRevision GetPreviousRevisionFor (GitRevision revision) diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitUtil.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitUtil.cs index c4a6f5b855..8f9912e4ec 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitUtil.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitUtil.cs @@ -350,155 +350,7 @@ namespace MonoDevelop.VersionControl.Git repo.GetConfig().Save(); return repo; } - - public static RevCommit[] Blame (NGit.Repository repo, RevCommit commit, string file) - { - string localFile = ToGitPath (repo, file); - TreeWalk tw = TreeWalk.ForPath (repo, localFile, commit.Tree); - if (tw == null) - return new RevCommit [0]; - int totalLines = GetFileLineCount (repo, tw); - int lineCount = totalLines; - RevCommit[] lines = new RevCommit [lineCount]; - RevWalk revWalker = new RevWalk (repo); - revWalker.MarkStart (commit); - List<RevCommit> commitHistory = new List<RevCommit>(); - FilePath localCpath = FromGitPath (repo, localFile); - - foreach (RevCommit ancestorCommit in revWalker) { - foreach (Change change in GetCommitChanges (repo, ancestorCommit)) { - FilePath cpath = FromGitPath (repo, change.Path); - if (change.ChangeType != ChangeType.Deleted && (localCpath == cpath || cpath.IsChildPathOf (localCpath))) - { - commitHistory.Add(ancestorCommit); - break; - } - } - } - - int historySize = commitHistory.Count; - - if (historySize > 1) { - RevCommit recentCommit = commitHistory[0]; - RawText latestRawText = GetRawText (repo, localFile, recentCommit); - - for (int i = 1; i < historySize; i++) { - RevCommit ancestorCommit = commitHistory[i]; - RawText ancestorRawText = GetRawText (repo, localFile, ancestorCommit); - lineCount -= SetBlameLines(repo, lines, recentCommit, latestRawText, ancestorRawText); - recentCommit = ancestorCommit; - - if (lineCount <= 0) - { - break; - } - } - - if (lineCount > 0) { - RevCommit firstCommit = commitHistory[historySize - 1]; - - for (int i = 0; i < totalLines; i++) { - if (lines[i] == null) { - lines[i] = firstCommit; - } - } - } - } else if (historySize == 1) { - RevCommit firstCommit = commitHistory[0]; - - for (int i = 0; i < totalLines; i++) { - lines[i] = firstCommit; - } - } - - return lines; - } - - static int GetFileLineCount (NGit.Repository repo, TreeWalk tw) { - ObjectId id = tw.GetObjectId (0); - byte[] data = repo.ObjectDatabase.Open (id).GetBytes (); - return new RawText (data).Size(); - } - - static RawText GetRawText(NGit.Repository repo, string file, RevCommit commit) { - TreeWalk tw = TreeWalk.ForPath (repo, file, commit.Tree); - if (tw == null) - return new RawText (new byte[0]); - ObjectId objectID = tw.GetObjectId(0); - byte[] data = repo.ObjectDatabase.Open (objectID).GetBytes (); - return new RawText (data); - } - - static int SetBlameLines (NGit.Repository repo, RevCommit[] lines, RevCommit commit, RawText curText, RawText ancestorText) - { - int lineCount = 0; - IEnumerable<Hunk> diffHunks = GetDiffHunks (curText, ancestorText); - foreach (Hunk e in diffHunks) { - int basePosition = e.InsertStart - 1; - for (int i = 0; i < e.Inserted; i++) { - int lineNum = basePosition + i; - if (lines [lineNum] == null) { - lines [lineNum] = commit; - lineCount++; - } - } - } - - return lineCount; - } - - static IEnumerable<Hunk> GetDiffHunks (RawText curText, RawText ancestorText) - { - Dictionary<string, int> codeDictionary = new Dictionary<string, int> (); - int codeCounter = 0; - int[] ancestorDiffCodes = GetDiffCodes (ref codeCounter, codeDictionary, ancestorText); - int[] currentDiffCodes = GetDiffCodes (ref codeCounter, codeDictionary, curText); - return Diff.GetDiff<int> (ancestorDiffCodes, currentDiffCodes); - } - - static int[] GetDiffCodes (ref int codeCounter, Dictionary<string, int> codeDictionary, RawText text) - { - int lineCount = text.Size (); - int[] result = new int[lineCount]; - string[] lines = GetLineStrings (text); - for (int i = 0; i < lineCount; i++) { - string lineText = lines [i]; - int curCode; - if (!codeDictionary.TryGetValue (lineText, out curCode)) { - codeDictionary [lineText] = curCode = ++codeCounter; - } - result [i] = curCode; - } - return result; - } - - static string[] GetLineStrings (RawText text) - { - int lineCount = text.Size (); - string[] lines = new string[lineCount]; - - for (int i = 0; i < lineCount; i++) { - lines [i] = text.GetString (i); - } - - return lines; - } - - static int FillRemainingBlame (RevCommit[] lines, RevCommit commit) - { - int lineCount = 0; - - for (int n=0; n<lines.Length; n++) { - if (lines [n] == null) { - lines [n] = commit; - lineCount++; - } - } - - return lineCount; - } - public static MergeCommandResult MergeTrees (NGit.ProgressMonitor monitor, NGit.Repository repo, RevCommit srcBase, RevCommit srcCommit, string sourceDisplayName, bool commitResult) { RevCommit newHead = null; @@ -578,17 +430,5 @@ namespace MonoDevelop.VersionControl.Git } } } - - class RevisionObjectIdPair - { - public RevisionObjectIdPair(RevCommit revision, ObjectId objectId) - { - this.Commit = revision; - this.ObjectId = objectId; - } - - public RevCommit Commit { get; private set; } - public ObjectId ObjectId { get; private set; } - } } diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion/SubversionRepository.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion/SubversionRepository.cs index 510c079f23..d9705d1100 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion/SubversionRepository.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion/SubversionRepository.cs @@ -217,6 +217,12 @@ namespace MonoDevelop.VersionControl.Subversion public override void Revert (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
{
+ // If we have an array of paths such as: new [] { "/Foo/Directory", "/Foo/Directory/File1", "/Foo/Directory/File2" }
+ // svn will successfully revert the first entry (the directory) and then throw an error when trying to revert the
+ // second and third entries because by reverting the directory the files are implicitly reverted. Try to work around
+ // this issue.
+ Array.Sort<FilePath>(localPaths);
+ Array.Reverse (localPaths);
Svn.Revert (localPaths, recurse, monitor);
}
|