コード例 #1
0
ファイル: FormCommit.cs プロジェクト: chafnan/gitextensions
        public FormCommit()
        {
            _syncContext = SynchronizationContext.Current;

            InitializeComponent();
            splitRight.Panel2MinSize = 130;
            Translate();

            SolveMergeconflicts.Font = new Font(SystemFonts.MessageBoxFont, FontStyle.Bold);

            SelectedDiff.ExtraDiffArgumentsChanged += SelectedDiffExtraDiffArgumentsChanged;

            closeDialogAfterEachCommitToolStripMenuItem.Checked = Settings.CloseCommitDialogAfterCommit;
            closeDialogAfterAllFilesCommittedToolStripMenuItem.Checked = Settings.CloseCommitDialogAfterLastCommit;

            Unstaged.SetNoFilesText(_noUnstagedChanges.Text);
            Staged.SetNoFilesText(_noStagedChanges.Text);
            Message.SetEmptyMessage(_enterCommitMessageHint.Text);

            Unstaged.SelectedIndexChanged += UntrackedSelectionChanged;
            Staged.SelectedIndexChanged += TrackedSelectionChanged;

            Unstaged.DoubleClick += Unstaged_DoubleClick;
            Staged.DoubleClick += Staged_DoubleClick;

            _gitGetUnstagedCommand = new GitCommandsInstance();
            _gitGetUnstagedCommand.Exited += GitCommandsExited;

            Unstaged.Focus();

            SelectedDiff.AddContextMenuEntry(null, null);
            _StageSelectedLinesToolStripMenuItem = SelectedDiff.AddContextMenuEntry(_stageSelectedLines.Text, StageSelectedLinesToolStripMenuItemClick);
            SelectedDiff.AddContextMenuEntry(_resetSelectedLines.Text, ResetSelectedLinesToolStripMenuItemClick);

            splitMain.SplitterDistance = Settings.CommitDialogSplitter;

            this.HotkeysEnabled = true;
            this.Hotkeys = HotkeySettingsManager.LoadHotkeys(HotkeySettingsName);

            Commit.Focus();
        }
コード例 #2
0
        private void LoadModuleInfo(string command, string workingDir, ILoadingTaskState taskState)
        {
            using (GitCommandsInstance git = new GitCommandsInstance())
            {
                git.StreamOutput = true;
                git.CollectOutput = false;
                Process p = git.CmdStartProcess(Settings.GitCommand, command, workingDir);

                // Read line
                string line = p.StandardOutput.ReadLine();

                // Analyze commit listing
                while (!taskState.IsCanceled())
                {
                    Commit commit = new Commit();

                    // Reached the end ?
                    if (line == null)
                        break;

                    // Look for commit delimiters
                    if (!line.StartsWith("--- "))
                    {
                        line = p.StandardOutput.ReadLine();
                        continue;
                    }

                    // Strip "--- "
                    line = line.Substring(4);

                    // Split date and author
                    string[] header = line.Split(new string[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (header.Length != 2)
                        continue;

                    // Save author in variable
                    commit.author = header[1];

                    // Parse commit date
                    DateTime date = DateTime.Parse(header[0]).Date;
                    // Calculate first day of the commit week
                    date = commit.week = date.AddDays(-(int)date.DayOfWeek);

                    // Reset commit data
                    commit.data.Commits = 1;
                    commit.data.AddedLines = 0;
                    commit.data.DeletedLines = 0;

                    // Parse commit lines
                    while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- ") && !taskState.IsCanceled())
                    {
                        // Skip empty line
                        if (string.IsNullOrEmpty(line))
                            continue;

                        string[] file_line = line.Split('\t');
                        if (file_line.Length >= 2)
                        {
                            if (file_line[0] != "-")
                                commit.data.AddedLines += int.Parse(file_line[0]);
                            if (file_line[1] != "-")
                                commit.data.DeletedLines += int.Parse(file_line[1]);
                        }
                    }

                    if (Updated != null && !taskState.IsCanceled())
                        Updated(commit);
                }
            }
        }
コード例 #3
0
        private void LoadModuleInfo(string command, IGitModule module, CancellationToken token)
        {
            using (GitCommandsInstance git = new GitCommandsInstance(module))
            {
                git.StreamOutput  = true;
                git.CollectOutput = false;
                Process p = git.CmdStartProcess(Settings.GitCommand, command);

                // Read line
                string line = p.StandardOutput.ReadLine();

                // Analyze commit listing
                while (!token.IsCancellationRequested)
                {
                    Commit commit = new Commit();

                    // Reached the end ?
                    if (line == null)
                    {
                        break;
                    }

                    // Look for commit delimiters
                    if (!line.StartsWith("--- "))
                    {
                        line = p.StandardOutput.ReadLine();
                        continue;
                    }

                    // Strip "--- "
                    line = line.Substring(4);

                    // Split date and author
                    string[] header = line.Split(new[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (header.Length != 2)
                    {
                        continue;
                    }

                    // Save author in variable
                    commit.author = header[1];

                    // Parse commit date
                    DateTime date = DateTime.Parse(header[0]).Date;
                    // Calculate first day of the commit week
                    date = commit.week = date.AddDays(-(int)date.DayOfWeek);

                    // Reset commit data
                    commit.data.Commits      = 1;
                    commit.data.AddedLines   = 0;
                    commit.data.DeletedLines = 0;

                    // Parse commit lines
                    while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- ") && !token.IsCancellationRequested)
                    {
                        // Skip empty line
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }

                        string[] file_line = line.Split('\t');
                        if (file_line.Length >= 2)
                        {
                            if (file_line[0] != "-")
                            {
                                commit.data.AddedLines += int.Parse(file_line[0]);
                            }
                            if (file_line[1] != "-")
                            {
                                commit.data.DeletedLines += int.Parse(file_line[1]);
                            }
                        }
                    }

                    if (Updated != null && !token.IsCancellationRequested)
                    {
                        Updated(commit);
                    }
                }
            }
        }
コード例 #4
0
        private string BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            //Replace windows path separator to Linux path separator.
            //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(Module.WorkingDir, 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(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
            {
                fileName = fileName.Substring(Module.WorkingDir.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(Module)
                {
                    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);
            }

            return(filter);
        }
コード例 #5
0
        private void execute()
        {
            try
            {
                string command = "log --pretty=tformat:\"--- %ad --- %an\" --numstat --date=iso -C --all --no-merges";

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

                // Read line
                string line = p.StandardOutput.ReadLine();

                // Analyze commit listing
                while (true)
                {
                    Commit commit = new Commit();

                    // Reached the end ?
                    if (line == null)
                    {
                        break;
                    }

                    // Look for commit delimiters
                    if (!line.StartsWith("--- "))
                    {
                        line = p.StandardOutput.ReadLine();
                        continue;
                    }

                    // Strip "--- "
                    line = line.Substring(4);

                    // Split date and author
                    string[] header = line.Split(new string[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (header.Length != 2)
                    {
                        continue;
                    }

                    // Save author in variable
                    string author = commit.author = header[1];

                    // Parse commit date
                    DateTime date = DateTime.Parse(header[0]).Date;
                    // Calculate first day of the commit week
                    date = commit.week = date.AddDays(-(int)date.DayOfWeek);

                    // Reset commit data
                    commit.data.Commits      = 1;
                    commit.data.AddedLines   = 0;
                    commit.data.DeletedLines = 0;

                    // Parse commit lines
                    while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- "))
                    {
                        // Skip empty line
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }

                        string[] file_line = line.Split('\t');
                        if (file_line.Length >= 2)
                        {
                            if (file_line[0] != "-")
                            {
                                commit.data.AddedLines += int.Parse(file_line[0]);
                            }
                            if (file_line[1] != "-")
                            {
                                commit.data.DeletedLines += int.Parse(file_line[1]);
                            }
                        }
                    }

                    if (Updated != null)
                    {
                        Updated(commit);
                    }
                }
            }
            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);
            }
        }
コード例 #6
0
ファイル: ImpactLoader.cs プロジェクト: RodH257/gitextensions
 public void Dispose()
 {
     if (backgroundThread != null)
     {
         backgroundThread.Abort();
         backgroundThread = null;
     }
     if (git != null)
     {
         git.Dispose();
         git = null;
     }
 }
コード例 #7
0
ファイル: ImpactLoader.cs プロジェクト: RodH257/gitextensions
        private void execute()
        {
            try
            {
                string command = "log --pretty=tformat:\"--- %ad --- %an\" --numstat --date=iso -C --all --no-merges";

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

                // Read line
                string line = p.StandardOutput.ReadLine();

                // Analyze commit listing
                while (true)
                {
                    Commit commit = new Commit();

                    // Reached the end ?
                    if (line == null)
                        break;

                    // Look for commit delimiters
                    if (!line.StartsWith("--- "))
                    {
                        line = p.StandardOutput.ReadLine();
                        continue;
                    }

                    // Strip "--- "
                    line = line.Substring(4);

                    // Split date and author
                    string[] header = line.Split(new string[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (header.Length != 2)
                        continue;

                    // Save author in variable
                    string author = commit.author = header[1];

                    // Parse commit date
                    DateTime date = DateTime.Parse(header[0]).Date;
                    // Calculate first day of the commit week
                    date = commit.week = date.AddDays(-(int)date.DayOfWeek);

                    // Reset commit data
                    commit.data.Commits = 1;
                    commit.data.AddedLines = 0;
                    commit.data.DeletedLines = 0;

                    // Parse commit lines
                    while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- "))
                    {
                        // Skip empty line
                        if (string.IsNullOrEmpty(line))
                            continue;

                        string[] file_line = line.Split('\t');
                        if (file_line.Length >= 2)
                        {
                            if (file_line[0] != "-")
                                commit.data.AddedLines += int.Parse(file_line[0]);
                            if (file_line[1] != "-")
                                commit.data.DeletedLines += int.Parse(file_line[1]);
                        }
                    }

                    if (Updated != null)
                        Updated(commit);
                }
            }
            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);
        }