Permalink
Browse files

Merge pull request #146 from Rezun/changes

Support for filenames escaped with quotepath
  • Loading branch information...
2 parents 40dc113 + d7c24b6 commit f608447a8a40271262d8bebb4c4ffd88e45f42ca @sc68cal sc68cal committed Feb 22, 2012
Showing with 57 additions and 4 deletions.
  1. +25 −4 GitTfs/Core/GitChangeInfo.cs
  2. +32 −0 GitTfsTest/Core/GitChangeInfoTests.cs
@@ -1,3 +1,4 @@
+using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using GitSharp.Core;
@@ -20,13 +21,16 @@ public class GitChangeInfo
" " +
"(?<status>.)" + "(?<score>[0-9]*)" +
"\\t" +
- "(?<srcpath>[^\\t]+)" +
+ "(?<srcquot>\"?)(?<srcpath>[^\\t]+?)\"?" +
"(\\t" +
- "(?<dstpath>[^\\t]+)" +
+ "(?<dstquot>\"?)(?<dstpath>[^\\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 @@ private static void Debug(string input, Match match, Regex regex)
}
}
+ 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 @@ private GitChangeInfo(Match match)
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)
@@ -41,6 +41,38 @@ public void GetsChangeTypeWhenScoreIsPresent()
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.

0 comments on commit f608447

Please sign in to comment.