当前位置: 首页>>代码示例>>C#>>正文


C# GitCommandsInstance.CmdStartProcess方法代码示例

本文整理汇总了C#中GitCommands.GitCommandsInstance.CmdStartProcess方法的典型用法代码示例。如果您正苦于以下问题:C# GitCommandsInstance.CmdStartProcess方法的具体用法?C# GitCommandsInstance.CmdStartProcess怎么用?C# GitCommandsInstance.CmdStartProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GitCommands.GitCommandsInstance的用法示例。


在下文中一共展示了GitCommandsInstance.CmdStartProcess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnShown

        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;
            }
        }
开发者ID:xaro,项目名称:gitextensions,代码行数:57,代码来源:FormFileHistory.cs

示例2: processStart

        private void processStart(FormStatus form)
        {
            BeforeProcessStart();
            AddOutput(ProcessString + " " + ProcessArguments);
            gitCommand = new GitCommandsInstance { CollectOutput = false };

            try
            {
                Process = gitCommand.CmdStartProcess(ProcessString, ProcessArguments);

                gitCommand.Exited += gitCommand_Exited;
                gitCommand.DataReceived += gitCommand_DataReceived;
                if (!string.IsNullOrEmpty(ProcessInput))
                {
                    Thread.Sleep(500);
                    Process.StandardInput.Write(ProcessInput);
                    AddOutput(string.Format(":: Wrote [{0}] to process!\r\n", ProcessInput));
                }
            }
            catch (Exception e)
            {
                AddOutput(e.Message);
                gitCommand.ExitCode = 1;
                gitCommand_Exited(null, null);
            }
        }
开发者ID:afabre,项目名称:gitextensions,代码行数:26,代码来源:FormProcess.cs

示例3: execute

        private void execute()
        {
            try
            {
                RevisionCount = 0;
                heads = GetHeads();

                string formatString =
                    /* <COMMIT>       */ COMMIT_BEGIN + "%n" +
                    /* Hash           */ "%H%n" +
                    /* Parents        */ "%P%n";
                if (!ShaOnly)
                {
                    formatString +=
                        /* Tree                    */ "%T%n" +
                        /* Author Name             */ "%aN%n" +
                        /* Author Email            */ "%aE%n" +
                        /* Author Date             */ "%ai%n" +
                        /* Committer Name          */ "%cN%n" +
                        /* Committer Date          */ "%ci%n" +
                        /* Commit message encoding */ "%e%n" + //there is a bug: git does not recode commit message when format is given
                        /* Commit Message          */ "%s";
                }

                // NOTE:
                // when called from FileHistory and FollowRenamesInFileHistory is enabled the "--name-only" argument is set.
                // the filename is the next line after the commit-format defined above.

                if (Settings.OrderRevisionByDate)
                {
                    LogParam = " --date-order " + LogParam;
                }
                else
                {
                    LogParam = " --topo-order " + LogParam;
                }

                string arguments = String.Format(CultureInfo.InvariantCulture,
                    "log -z {2} --pretty=format:\"{1}\" {0}",
                    LogParam,
                    formatString,
                    BranchFilter);

                gitGetGraphCommand = new GitCommandsInstance();
                gitGetGraphCommand.StreamOutput = true;
                gitGetGraphCommand.CollectOutput = false;
                Encoding LogOutputEncoding = Settings.LogOutputEncoding;
                gitGetGraphCommand.SetupStartInfoCallback = (ProcessStartInfo startInfo) =>
                {
                    startInfo.StandardOutputEncoding = Settings.LosslessEncoding;
                    startInfo.StandardErrorEncoding = Settings.LosslessEncoding;
                };

                Process p = gitGetGraphCommand.CmdStartProcess(Settings.GitCommand, arguments);

                if (BeginUpdate != null)
                    BeginUpdate(this, EventArgs.Empty);

                string line;
                do
                {
                    line = p.StandardOutput.ReadLine();
                    //commit message is not encoded by git
                    if (nextStep != ReadStep.CommitMessage)
                        line = GitCommandHelpers.ReEncodeString(line, Settings.LosslessEncoding, LogOutputEncoding);

                    if (line != null)
                    {
                        foreach (string entry in line.SplitString(new char[] {'\0'}))
                        {
                            dataReceived(entry);
                        }
                    }
                } while (line != null);
                finishRevision();
            }
            catch (ThreadAbortException)
            {
                //Silently ignore this exception...
            }
            catch (Exception ex)
            {
                if (Error != null)
                    Error(this, EventArgs.Empty);
                MessageBox.Show("Cannot load commit log." + Environment.NewLine + Environment.NewLine + ex.ToString());
                return;
            }

            if (Exited != null)
                Exited(this, EventArgs.Empty);
        }
开发者ID:antis81,项目名称:gitextensions,代码行数:91,代码来源:RevisionGraph.cs

示例4: UnstageFiles

        public static string UnstageFiles(List<GitItemStatus> files)
        {
            var gitCommand = new GitCommandsInstance();

            var output = "";

            Process process1 = null;
            foreach (var file in files)
            {
                if (file.IsNew)
                    continue;
                if (process1 == null)
                    process1 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --info-only --index-info");

                process1.StandardInput.WriteLine("0 0000000000000000000000000000000000000000\t\"" + FixPath(file.Name) +
                                                 "\"");
            }
            if (process1 != null)
            {
                process1.StandardInput.Close();
                process1.WaitForExit();
            }

            if (gitCommand.Output != null)
                output = gitCommand.Output.ToString();

            Process process2 = null;
            foreach (var file in files)
            {
                if (!file.IsNew)
                    continue;
                if (process2 == null)
                    process2 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --force-remove --stdin");
                process2.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
            }
            if (process2 != null)
            {
                process2.StandardInput.Close();
                process2.WaitForExit();
            }

            if (gitCommand.Output != null)
                output += gitCommand.Output.ToString();

            return output;
        }
开发者ID:avish,项目名称:gitextensions,代码行数:46,代码来源:GitCommandsHelper.cs

示例5: StageFiles

        public static string StageFiles(IList<GitItemStatus> files)
        {
            var gitCommand = new GitCommandsInstance();

            var output = "";

            Process process1 = null;
            foreach (var file in files)
            {
                if (file.IsDeleted)
                    continue;
                if (process1 == null)
                    process1 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --add --stdin");

                process1.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
            }
            if (process1 != null)
            {
                process1.StandardInput.Close();
                process1.WaitForExit();

                if (gitCommand.Output != null)
                    output = gitCommand.Output.ToString().Trim();
            }

            Process process2 = null;
            foreach (var file in files)
            {
                if (!file.IsDeleted)
                    continue;
                if (process2 == null)
                    process2 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --remove --stdin");
                process2.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
            }
            if (process2 != null)
            {
                process2.StandardInput.Close();
                process2.WaitForExit();

                if (gitCommand.Output != null)
                {
                    if (!string.IsNullOrEmpty(output))
                    {
                        output += Environment.NewLine;
                    }
                    output += gitCommand.Output.ToString().Trim();
                }
            }

            return output;
        }
开发者ID:avish,项目名称:gitextensions,代码行数:51,代码来源:GitCommandsHelper.cs

示例6: ApplyPatch

        public string ApplyPatch(string dir, string amCommand)
        {
            var output = string.Empty;

            using (var gitCommand = new GitCommandsInstance(this))
            {

                var files = Directory.GetFiles(dir);

                if (files.Length > 0)
                    using (Process process1 = gitCommand.CmdStartProcess(Settings.GitCommand, amCommand))
                    {
                        foreach (var file in files)
                        {
                            using (FileStream fs = new FileStream(file, FileMode.Open))
                            {
                                fs.CopyTo(process1.StandardInput.BaseStream);
                            }
                        }
                        process1.StandardInput.Close();
                        process1.WaitForExit();

                        if (gitCommand.Output != null)
                            output = gitCommand.Output.ToString().Trim();
                    }
            }

            return output;
        }
开发者ID:dopry,项目名称:gitextensions,代码行数:29,代码来源:GitModule.cs

示例7: UnstageFiles

        public string UnstageFiles(List<GitItemStatus> files)
        {
            var gitCommand = new GitCommandsInstance(this);

            var output = "";

            Process process1 = null;
            foreach (var file in files)
            {
                if (file.IsNew)
                    continue;
                if (process1 == null)
                    process1 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --info-only --index-info");

                process1.StandardInput.WriteLine("0 0000000000000000000000000000000000000000\t\"" + FixPath(file.Name) +
                                                 "\"");
            }
            if (process1 != null)
            {
                process1.StandardInput.Close();
                process1.WaitForExit();
            }

            if (gitCommand.Output != null)
                output = gitCommand.Output.ToString();

            Process process2 = null;
            foreach (var file in files)
            {
                if (!file.IsNew)
                    continue;
                if (process2 == null)
                    process2 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --force-remove --stdin");
                //process2.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
                byte[] bytearr = EncodingHelper.ConvertTo(GitModule.SystemEncoding, "\"" + FixPath(file.Name) + "\"" + process2.StandardInput.NewLine);
                process2.StandardInput.BaseStream.Write(bytearr, 0, bytearr.Length);
            }
            if (process2 != null)
            {
                process2.StandardInput.Close();
                process2.WaitForExit();
            }

            if (gitCommand.Output != null)
                output += gitCommand.Output.ToString();

            return output;
        }
开发者ID:dopry,项目名称:gitextensions,代码行数:48,代码来源:GitModule.cs

示例8: LoadFileHistory

        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;
            }
        }
开发者ID:pinkchry,项目名称:gitextensions,代码行数:87,代码来源:FormFileHistory.cs

示例9: StageFiles

        public string StageFiles(IList<GitItemStatus> files, out bool wereErrors)
        {
            var gitCommand = new GitCommandsInstance(this);

            var output = "";
            wereErrors = false;

            Process process1 = null;
            foreach (var file in files)
            {
                if (file.IsDeleted)
                    continue;
                if (process1 == null)
                    process1 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --add --stdin");

                //process1.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
                byte[] bytearr = EncodingHelper.ConvertTo(SystemEncoding, "\"" + FixPath(file.Name) + "\"" + process1.StandardInput.NewLine);
                process1.StandardInput.BaseStream.Write(bytearr, 0, bytearr.Length);
            }
            if (process1 != null)
            {
                process1.StandardInput.Close();
                process1.WaitForExit();
                wereErrors = process1.ExitCode != 0;

                if (gitCommand.Output != null)
                    output = gitCommand.Output.ToString().Trim();
            }

            Process process2 = null;
            foreach (var file in files)
            {
                if (!file.IsDeleted)
                    continue;
                if (process2 == null)
                    process2 = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --remove --stdin");
                //process2.StandardInput.WriteLine("\"" + FixPath(file.Name) + "\"");
                byte[] bytearr = EncodingHelper.ConvertTo(SystemEncoding, "\"" + FixPath(file.Name) + "\"" + process2.StandardInput.NewLine);
                process2.StandardInput.BaseStream.Write(bytearr, 0, bytearr.Length);
            }
            if (process2 != null)
            {
                process2.StandardInput.Close();
                process2.WaitForExit();
                wereErrors = wereErrors || process2.ExitCode != 0;

                if (gitCommand.Output != null)
                {
                    if (!string.IsNullOrEmpty(output))
                    {
                        output += Environment.NewLine;
                    }
                    output += gitCommand.Output.ToString().Trim();
                }
            }

            return output;
        }
开发者ID:ashH,项目名称:gitextensions,代码行数:58,代码来源:GitModule.cs

示例10: processStart

        private void processStart(FormStatus form)
        {
            BeforeProcessStart();
            string QuotedProcessString = ProcessString;
            if (QuotedProcessString.IndexOf(' ') != -1)
                QuotedProcessString = QuotedProcessString.Quote();
            AddMessageLine(QuotedProcessString + " " + ProcessArguments);
            gitCommand = new GitCommandsInstance(WorkingDirectory) { CollectOutput = false };

            try
            {
                Process = gitCommand.CmdStartProcess(ProcessString, ProcessArguments);

                gitCommand.Exited += gitCommand_Exited;
                gitCommand.DataReceived += gitCommand_DataReceived;
                if (!string.IsNullOrEmpty(ProcessInput))
                {
                    Thread.Sleep(500);
                    Process.StandardInput.Write(ProcessInput);
                    AddMessageLine(string.Format(":: Wrote [{0}] to process!\r\n", ProcessInput));
                }
            }
            catch (Exception e)
            {
                AddMessageLine("\n" + e.ToStringWithData());
                gitCommand.ExitCode = 1;
                gitCommand_Exited(null, null);
            }
        }
开发者ID:CallMeLaNN,项目名称:gitextensions,代码行数:29,代码来源:FormProcess.cs

示例11: processStart

        private void processStart(FormStatus form)
        {
            restart = false;
            AddOutput(ProcessString + " " + ProcessArguments);

            Plink = GitCommandHelpers.Plink();

            gitCommand = new GitCommands.GitCommandsInstance();
            gitCommand.CollectOutput = false;
            Process = gitCommand.CmdStartProcess(ProcessString, ProcessArguments);

            gitCommand.Exited += new EventHandler(gitCommand_Exited);
            gitCommand.DataReceived += new DataReceivedEventHandler(gitCommand_DataReceived);
        }
开发者ID:RyanFarley,项目名称:gitextensions,代码行数:14,代码来源:FormProcess.cs

示例12: execute

        private void execute()
        {
            try
            {
                lock (revisions)
                {
                    revisions.Clear();
                }

                heads = GitCommandHelpers.GetHeads(true);

                string formatString =
                    /* <COMMIT>       */ COMMIT_BEGIN + "%n" +
                    /* Hash           */ "%H%n" +
                    /* Parents        */ "%P%n";
                if (!ShaOnly)
                {
                    formatString +=
                        /* Tree           */ "%T%n" +
                        /* Author Name    */ "%aN%n" +
                        /* Author Date    */ "%ai%n" +
                        /* Committer Name */ "%cN%n" +
                        /* Committer Date */ "%ci%n" +
                        /* Commit Message */ "%s";
                }

                // NOTE:
                // when called from FileHistory and FollowRenamesInFileHistory is enabled the "--name-only" argument is set.
                // the filename is the next line after the commit-format defined above.

                if (Settings.OrderRevisionByDate)
                {
                    LogParam = " --date-order " + LogParam;
                }
                else
                {
                    LogParam = " --topo-order " + LogParam;
                }

                string arguments = String.Format(CultureInfo.InvariantCulture,
                    "log -z {2} --pretty=format:\"{1}\" {0}",
                    LogParam,
                    formatString,
                    BranchFilter);

                gitGetGraphCommand = new GitCommandsInstance();
                gitGetGraphCommand.StreamOutput = true;
                gitGetGraphCommand.CollectOutput = false;
                Process p = gitGetGraphCommand.CmdStartProcess(Settings.GitCommand, arguments);

                string line;
                do
                {
                    line = p.StandardOutput.ReadLine();

                    if (line != null)
                    {
                        foreach (string entry in line.Split('\0'))
                        {
                            dataReceived(entry);
                        }
                    }
                } while (line != null);
                finishRevision();

                Exited(this, new EventArgs());
            }
            catch (ThreadAbortException ex)
            {
                //Silently ignore this exception...
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot load commit log." + Environment.NewLine + Environment.NewLine + ex.ToString());
            }
        }
开发者ID:nixdog,项目名称:gitextensions,代码行数:76,代码来源:RevisionGraph.cs

示例13: processStart

        private void processStart(FormStatus form)
        {
            restart = false;
            AddOutput(ProcessString + " " + ProcessArguments);

            Plink = GitCommandHelpers.Plink();

            gitCommand = new GitCommands.GitCommandsInstance();
            gitCommand.CollectOutput = false;
            try
            {
                Process = gitCommand.CmdStartProcess(ProcessString, ProcessArguments);

                gitCommand.Exited += new EventHandler(gitCommand_Exited);
                gitCommand.DataReceived += new DataReceivedEventHandler(gitCommand_DataReceived);
            }
            catch (Exception e)
            {
                AddOutput(e.Message);
                gitCommand.ExitCode = 1;
                gitCommand_Exited(null, null);
            }
        }
开发者ID:gorbach,项目名称:gitextensions,代码行数:23,代码来源:FormProcess.cs

示例14: UpdateIndex

 private static void UpdateIndex(GitCommandsInstance gitCommand, ref Process process, string filename)
 {
     if (process == null)
         process = gitCommand.CmdStartProcess(Settings.GitCommand, "update-index --remove --stdin");
     //process2.StandardInput.WriteLine("\"" + FixPath(filename) + "\"");
     byte[] bytearr = EncodingHelper.ConvertTo(SystemEncoding,
                                               "\"" + FixPath(filename) + "\"" + process.StandardInput.NewLine);
     process.StandardInput.BaseStream.Write(bytearr, 0, bytearr.Length);
 }
开发者ID:dmay,项目名称:gitextensions,代码行数:9,代码来源:GitModule.cs

示例15: LoadFileHistory

        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);
        }
开发者ID:vgravade,项目名称:gitextensions,代码行数:92,代码来源:FormFileHistory.cs


注:本文中的GitCommands.GitCommandsInstance.CmdStartProcess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。