From da0bdaa5a2ed616e556c91be0cd8a45e8586c8c9 Mon Sep 17 00:00:00 2001 From: Steve Schmidt Date: Tue, 21 Feb 2012 16:35:20 +0100 Subject: [PATCH 1/2] Added support for filenames escaped with quotepath (core.quotepath setting) --- GitTfs/Core/GitChangeInfo.cs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/GitTfs/Core/GitChangeInfo.cs b/GitTfs/Core/GitChangeInfo.cs index 4d77f7e7..feb2010d 100644 --- a/GitTfs/Core/GitChangeInfo.cs +++ b/GitTfs/Core/GitChangeInfo.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Text.RegularExpressions; using GitSharp.Core; @@ -20,13 +21,16 @@ namespace Sep.Git.Tfs.Core " " + "(?.)" + "(?[0-9]*)" + "\\t" + - "(?[^\\t]+)" + + "(?\"?)(?[^\\t]+?)\"?" + "(\\t" + - "(?[^\\t]+)" + + "(?\"?)(?[^\\t]+?)\"?" + ")?" + "$", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex unicodePattern = new Regex(@"\\[0-7]{3}", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static GitChangeInfo Parse(string diffTreeLine) { var match = DiffTreePattern.Match(diffTreeLine); @@ -44,11 +48,28 @@ namespace Sep.Git.Tfs.Core } } + private static string replaceUnicode(Match match) + { + return char.ConvertFromUtf32(Convert.ToInt32(match.Value.Substring(1), 8)); + } + + private static string getPathFromMatch(Match match, string quotName, string pathName) + { + if (String.IsNullOrEmpty(match.Groups[quotName].Value)) + return match.Groups[pathName].Value; + else + return unicodePattern.Replace(match.Groups[pathName].Value, replaceUnicode); + } + private readonly Match _match; + private readonly string _srcpath; + private readonly string _dstpath; private GitChangeInfo(Match match) { _match = match; + _srcpath = getPathFromMatch(match, "srcquot", "srcpath"); + _dstpath = getPathFromMatch(match, "dstquot", "dstpath"); } public FileMode NewMode { get { return _match.Groups["dstmode"].Value.ToFileMode(); } } @@ -58,8 +79,8 @@ namespace Sep.Git.Tfs.Core public string newMode { get { return _match.Groups["dstmode"].Value; } } public string oldSha { get { return _match.Groups["srcsha1"].Value; } } public string newSha { get { return _match.Groups["dstsha1"].Value; } } - public string path { get { return _match.Groups["srcpath"].Value; } } - public string pathTo { get { return _match.Groups["dstpath"].Value; } } + public string path { get { return _srcpath; } } + public string pathTo { get { return _dstpath; } } public string score { get { return _match.Groups["score"].Value; } } public IGitChangedFile ToGitChangedFile(ExplicitArgsExpression builder) From d7c24b6a09f4b794fd409861a34a7b805427613d Mon Sep 17 00:00:00 2001 From: Steve Schmidt Date: Wed, 22 Feb 2012 17:06:50 +0100 Subject: [PATCH 2/2] Added unit tests to ensure that quotepath support is working --- GitTfsTest/Core/GitChangeInfoTests.cs | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/GitTfsTest/Core/GitChangeInfoTests.cs b/GitTfsTest/Core/GitChangeInfoTests.cs index b04c75eb..3375613c 100644 --- a/GitTfsTest/Core/GitChangeInfoTests.cs +++ b/GitTfsTest/Core/GitChangeInfoTests.cs @@ -41,6 +41,38 @@ namespace Sep.Git.Tfs.Test.Core Assert.AreEqual("R", info.Status); } + [TestMethod] + public void GetsPath() + { + var line = ":000000 100644 abcdef0123abcdef0123abcdef0123abcdef0123 01234567ab01234567ab01234567ab01234567ab M\tFoo\tBar"; + var info = GitChangeInfo.Parse(line); + Assert.AreEqual("Foo", info.path); + } + + [TestMethod] + public void GetsPathTo() + { + var line = ":000000 100644 abcdef0123abcdef0123abcdef0123abcdef0123 01234567ab01234567ab01234567ab01234567ab M\tFoo\tBar"; + var info = GitChangeInfo.Parse(line); + Assert.AreEqual("Bar", info.pathTo); + } + + [TestMethod] + public void GetsPathWithQuotepath() + { + var line = ":000000 100644 abcdef0123abcdef0123abcdef0123abcdef0123 01234567ab01234567ab01234567ab01234567ab M\t\"\\366\"\t\"\\337\""; + var info = GitChangeInfo.Parse(line); + Assert.AreEqual("ö", info.path); + } + + [TestMethod] + public void GetsPathToWithQuotepath() + { + var line = ":000000 100644 abcdef0123abcdef0123abcdef0123abcdef0123 01234567ab01234567ab01234567ab01234567ab M\t\"\\366\"\t\"\\337\""; + var info = GitChangeInfo.Parse(line); + Assert.AreEqual("ß", info.pathTo); + } + private IGitChangedFile GetChangeItem(string diffTreeLine) { // This method is similar to BuildGitChangedFile in GitRepository.