Exemple #1
0
        private void execute(ILoadingTaskState taskState)
        {
            RevisionCount = 0;
            heads         = GetHeads().ToDictionaryOfList(head => head.Guid);

            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             */ "%at%n" +
                    /* Committer Name          */ "%cN%n" +
                    /* Committer Date          */ "%ct%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);

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

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

                if (taskState.IsCanceled())
                {
                    return;
                }

                previousFileName = null;
                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.Split('\0'))
                        {
                            dataReceived(entry);
                        }
                    }
                } while (line != null && !taskState.IsCanceled());
            }
        }
Exemple #2
0
        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);
            }
        }