static protected DiffInfo[] GenerateUnifiedDiffInfo (string diffContent, FilePath basePath, FilePath[] localPaths)
{
basePath = basePath.FullPath;
var list = new List<DiffInfo> ();
using (StringReader sr = new StringReader (diffContent)) {
string line;
StringBuilder content = new StringBuilder ();
string fileName = null;
string pathRoot = null;
while ((line = sr.ReadLine ()) != null) {
if (pathRoot != null && fileName != null &&
(line.StartsWith ("+++ " + pathRoot, StringComparison.Ordinal) || line.StartsWith ("--- " + pathRoot, StringComparison.Ordinal))) {
line = line.Substring (0, 4) + line.Substring (4 + pathRoot.Length);
content.Append (line).Append ('\n');
}
else if (!line.StartsWith ("Index:", StringComparison.Ordinal)) {
content.Append (line).Append ('\n');
} else {
if (fileName != null) {
list.Add (new DiffInfo (basePath, fileName, content.ToString ()));
}
fileName = line.Substring (6).Trim ();
fileName = fileName.Replace ('/', Path.DirectorySeparatorChar); // svn returns paths using unix separators
FilePath fp = fileName;
pathRoot = null;
if (fp.IsAbsolute) {
if (fp == basePath)
pathRoot = fp.ParentDirectory;
else if (fp.IsChildPathOf (basePath))
pathRoot = basePath;
if (pathRoot != null) {
pathRoot = pathRoot.Replace (Path.DirectorySeparatorChar, '/').TrimEnd ('/');
pathRoot += '/';
}
}
else {
fp = fp.ToAbsolute (basePath);
}
fileName = fp;
content = new StringBuilder ();
line = sr.ReadLine (); // "===" Separator
// Filter out files not in the provided path list
if (localPaths != null && Array.IndexOf (localPaths, (FilePath) fileName) == -1)
fileName = null;
}
}
if (fileName != null) {
list.Add (new DiffInfo (basePath, fileName, content.ToString ()));
}
}
return list.ToArray ();
}