protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Settings.WaitUntilAllSettingsLoaded();
if (Settings.FollowRenamesInFileHistory)
{
// git log --follow is not working as expected (see http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
//
// But we can take a more complicated path to get reasonable results:
// 1. use git log --follow to get all previous filenames of the file we are interested in
// 2. use git log "list of filesnames" to get the histroy graph
//
// note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
//
GitCommandsInstance gitGetGraphCommand = new GitCommandsInstance();
gitGetGraphCommand.StreamOutput = true;
gitGetGraphCommand.CollectOutput = false;
string arg = "log --format=\"%n\" --name-only --follow -- \"" + FileName + "\"";
Process p = gitGetGraphCommand.CmdStartProcess(Settings.GitCommand, arg);
// the sequence of (quoted) file names - start with the initial filename for the search.
string listOfFileNames = "\"" + FileName + "\"";
// keep a set of the file names already seen
HashSet<string> setOfFileNames = new HashSet<string>();
setOfFileNames.Add(FileName);
string line;
do
{
line = p.StandardOutput.ReadLine();
if ((line != null) && (line != ""))
{
if (!setOfFileNames.Contains(line))
{
listOfFileNames = listOfFileNames + " \"" + line + "\"";
setOfFileNames.Add(line);
}
}
} while (line != null);
// here we need --name-only to get the previous filenames in the revision graph
FileChanges.Filter = " --name-only --parents -- " + listOfFileNames;
FileChanges.AllowGraphWithFilter = true;
}
else
{
// --parents doesn't work with --follow enabled, but needed to graph a filtered log
FileChanges.Filter = " --parents -- \"" + FileName + "\"";
FileChanges.AllowGraphWithFilter = true;
}
}
private void LoadFileHistory(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return;
//The section below contains native windows (kernel32) calls
//and breaks on Linux. Only use it on Windows. Casing is only
//a Windows problem anyway.
if (Settings.RunningOnWindows())
{
// we will need this later to look up proper casing for the file
string fullFilePath = fileName;
if (!fileName.StartsWith(Settings.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
fullFilePath = Path.Combine(Settings.WorkingDir, fileName);
if (File.Exists(fullFilePath))
{
// grab the 8.3 file path
StringBuilder shortPath = new StringBuilder(4096);
NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);
// use 8.3 file path to get properly cased full file path
StringBuilder longPath = new StringBuilder(4096);
NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);
// remove the working dir and now we have a properly cased file name.
fileName = longPath.ToString().Substring(Settings.WorkingDir.Length);
}
}
if (fileName.StartsWith(Settings.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
fileName = fileName.Substring(Settings.WorkingDir.Length);
FileName = fileName;
if (Settings.FollowRenamesInFileHistory)
{
// git log --follow is not working as expected (see http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
//
// But we can take a more complicated path to get reasonable results:
// 1. use git log --follow to get all previous filenames of the file we are interested in
// 2. use git log "list of filesnames" to get the histroy graph
//
// note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
//
GitCommandsInstance gitGetGraphCommand = new GitCommandsInstance();
gitGetGraphCommand.StreamOutput = true;
gitGetGraphCommand.CollectOutput = false;
string arg = "log --format=\"%n\" --name-only --follow -- \"" + fileName + "\"";
Process p = gitGetGraphCommand.CmdStartProcess(Settings.GitCommand, arg);
// the sequence of (quoted) file names - start with the initial filename for the search.
string listOfFileNames = "\"" + fileName + "\"";
// keep a set of the file names already seen
HashSet<string> setOfFileNames = new HashSet<string>();
setOfFileNames.Add(fileName);
string line;
do
{
line = p.StandardOutput.ReadLine();
if ( (line != null) && (line != "") )
{
if (!setOfFileNames.Contains(line))
{
listOfFileNames = listOfFileNames + " \"" + line + "\"";
setOfFileNames.Add(line);
}
}
} while (line != null);
// here we need --name-only to get the previous filenames in the revision graph
FileChanges.Filter = " --name-only --parents -- " + listOfFileNames;
FileChanges.AllowGraphWithFilter = true;
}
else
{
// --parents doesn't work with --follow enabled, but needed to graph a filtered log
FileChanges.Filter = " --parents -- \"" + fileName + "\"";
FileChanges.AllowGraphWithFilter = true;
}
}
private void LoadFileHistory(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return;
//Replace windows path seperator to linux path seperator.
//This is needed to keep the file history working when started from file tree in
//browse dialog.
fileName = fileName.Replace('\\', '/');
// we will need this later to look up proper casing for the file
var fullFilePath = Path.Combine(GitModule.CurrentWorkingDir, fileName);
//The section below contains native windows (kernel32) calls
//and breaks on Linux. Only use it on Windows. Casing is only
//a Windows problem anyway.
if (Settings.RunningOnWindows() && File.Exists(fullFilePath))
{
// grab the 8.3 file path
var shortPath = new StringBuilder(4096);
NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);
// use 8.3 file path to get properly cased full file path
var longPath = new StringBuilder(4096);
NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);
// remove the working dir and now we have a properly cased file name.
fileName = longPath.ToString().Substring(GitModule.CurrentWorkingDir.Length);
}
if (fileName.StartsWith(GitModule.CurrentWorkingDir, StringComparison.InvariantCultureIgnoreCase))
fileName = fileName.Substring(GitModule.CurrentWorkingDir.Length);
FileName = fileName;
string filter;
if (Settings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
{
// git log --follow is not working as expected (see http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
//
// But we can take a more complicated path to get reasonable results:
// 1. use git log --follow to get all previous filenames of the file we are interested in
// 2. use git log "list of files names" to get the history graph
//
// note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
//
var gitGetGraphCommand = new GitCommandsInstance { StreamOutput = true, CollectOutput = false };
string arg = "log --format=\"%n\" --name-only --follow -- \"" + fileName + "\"";
Process p = gitGetGraphCommand.CmdStartProcess(Settings.GitCommand, arg);
// the sequence of (quoted) file names - start with the initial filename for the search.
var listOfFileNames = new StringBuilder("\"" + fileName + "\"");
// keep a set of the file names already seen
var setOfFileNames = new HashSet<string> { fileName };
string line;
do
{
line = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
{
listOfFileNames.Append(" \"");
listOfFileNames.Append(line);
listOfFileNames.Append('\"');
}
} while (line != null);
// here we need --name-only to get the previous filenames in the revision graph
filter = " -M -C --name-only --parents -- " + listOfFileNames;
}
else
{
// --parents doesn't work with --follow enabled, but needed to graph a filtered log
filter = " --parents -- \"" + fileName + "\"";
}
if (Settings.FullHistoryInFileHistory)
{
filter = string.Concat(" --full-history --simplify-by-decoration ", filter);
}
syncContext.Post(_ =>
{
FileChanges.FixedFilter = filter;
FileChanges.AllowGraphWithFilter = true;
FileChanges.Load();
}, null);
}
请发表评论