Example #1
0
        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;
            }
        }
Example #2
0
        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;
        }
Example #3
0
        private void ProccessGitLog(CancellationToken taskState)
        {
            RevisionCount = 0;
            _heads = GetHeads().ToDictionaryOfList(head => head.Guid);

            string formatString =
                /* <COMMIT>       */ CommitBegin + "%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 Email         */ "%cE%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.

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

            if ((RefsOptions & RefsFiltringOptions.All) == RefsFiltringOptions.All)
                logParam += " --all";
            else
            {
                if ((RefsOptions & RefsFiltringOptions.Branches) == RefsFiltringOptions.Branches)
                    logParam = " --branches";
                if ((RefsOptions & RefsFiltringOptions.Remotes) == RefsFiltringOptions.Remotes)
                    logParam += " --remotes";
                if ((RefsOptions & RefsFiltringOptions.Tags) == RefsFiltringOptions.Tags)
                    logParam += " --tags";
            }
            if ((RefsOptions & RefsFiltringOptions.Boundary) == RefsFiltringOptions.Boundary)
                logParam += " --boundary";
            if ((RefsOptions & RefsFiltringOptions.ShowGitNotes) == RefsFiltringOptions.ShowGitNotes)
                logParam += " --not --glob=notes --not";

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

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

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

                if (taskState.IsCancellationRequested)
                    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 = GitModule.ReEncodeString(line, GitModule.LosslessEncoding, LogOutputEncoding);

                    if (line != null)
                    {
                        foreach (string entry in line.Split('\0'))
                        {
                            DataReceived(entry);
                        }
                    }
                } while (line != null && !taskState.IsCancellationRequested);
            }
        }
        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);
        }
Example #6
0
        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);
            }
        }
Example #7
0
 public void Dispose()
 {
     if (backgroundThread != null)
     {
         backgroundThread.Abort();
         backgroundThread = null;
     }
     if (gitGetGraphCommand != null)
     {
         gitGetGraphCommand.Kill();
         gitGetGraphCommand = null;
     }
 }
Example #8
0
        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;
        }
Example #9
0
        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());
            }
        }
Example #10
0
        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);
            }
        }
Example #11
0
        private void ProccessGitLog(CancellationToken taskState)
        {
            RevisionCount = 0;
            _refs         = GetRefs().ToDictionaryOfList(head => head.Guid);

            string formatString =
                /* <COMMIT>       */ CommitBegin + "%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 Email         */ "%cE%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.

            string logParam;

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

            if ((RefsOptions & RefsFiltringOptions.All) == RefsFiltringOptions.All)
            {
                logParam += " --all";
            }
            else
            {
                if ((RefsOptions & RefsFiltringOptions.Branches) == RefsFiltringOptions.Branches)
                {
                    logParam = " --branches";
                }
                if ((RefsOptions & RefsFiltringOptions.Remotes) == RefsFiltringOptions.Remotes)
                {
                    logParam += " --remotes";
                }
                if ((RefsOptions & RefsFiltringOptions.Tags) == RefsFiltringOptions.Tags)
                {
                    logParam += " --tags";
                }
            }
            if ((RefsOptions & RefsFiltringOptions.Boundary) == RefsFiltringOptions.Boundary)
            {
                logParam += " --boundary";
            }
            if ((RefsOptions & RefsFiltringOptions.ShowGitNotes) == RefsFiltringOptions.ShowGitNotes)
            {
                logParam += " --not --glob=notes --not";
            }

            string branchFilter = BranchFilter;

            if ((!string.IsNullOrWhiteSpace(BranchFilter)) &&
                (BranchFilter.IndexOfAny(ShellGlobCharacters) >= 0))
            {
                branchFilter = "--branches=" + BranchFilter;
            }

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

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

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

                if (taskState.IsCancellationRequested)
                {
                    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 = GitModule.ReEncodeString(line, GitModule.LosslessEncoding, LogOutputEncoding);
                    }

                    if (line != null)
                    {
                        foreach (string entry in line.Split('\0'))
                        {
                            DataReceived(entry);
                        }
                    }
                } while (line != null && !taskState.IsCancellationRequested);
            }
        }
Example #12
0
        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) + "\"");
                byte[] bytearr = ConvertFileNameTo(Settings.Encoding, "\"" + 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);
        }
Example #13
0
        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) + "\"");
                byte[] bytearr = ConvertFileNameTo(Settings.Encoding, "\"" + FixPath(file.Name) + "\"" + process1.StandardInput.NewLine);
                process1.StandardInput.BaseStream.Write(bytearr, 0, bytearr.Length);
            }
            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) + "\"");
                byte[] bytearr = ConvertFileNameTo(Settings.Encoding, "\"" + 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)
                {
                    if (!string.IsNullOrEmpty(output))
                    {
                        output += Environment.NewLine;
                    }
                    output += gitCommand.Output.ToString().Trim();
                }
            }

            return(output);
        }
Example #14
0
 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);
 }
Example #15
0
        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;
        }
Example #16
0
        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;
        }
Example #17
0
        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);
        }
Example #18
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);
        }
Example #19
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 */ "%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);

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

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

                    if (line != null)
                    {
                        foreach (string entry in line.Split('\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);
            }
        }
Example #20
0
        private void Initialize()
        {
            EnableStageButtons(false);

            Cursor.Current = Cursors.WaitCursor;

            if (_gitGetUnstagedCommand == null)
            {
                _gitGetUnstagedCommand = new GitCommandsInstance();
                _gitGetUnstagedCommand.Exited += GitCommandsExited;
            }

            // Load unstaged files
            var allChangedFilesCmd =
                GitCommandHelpers.GetAllChangedFilesCmd(
                    !showIgnoredFilesToolStripMenuItem.Checked,
                    showUntrackedFilesToolStripMenuItem.Checked);
            _gitGetUnstagedCommand.CmdStartProcess(Settings.GitCommand, allChangedFilesCmd);

            Loading.Visible = true;
            LoadingStaged.Visible = true;

            Commit.Enabled = false;
            CommitAndPush.Enabled = false;
            Amend.Enabled = false;
            Reset.Enabled = false;

            Cursor.Current = Cursors.Default;
        }
Example #21
0
        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);
            }
        }
Example #22
0
        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.KeyDown += Unstaged_KeyDown;
            Unstaged.DoubleClick += Unstaged_DoubleClick;
            Staged.KeyDown += Staged_KeyDown;
            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;
        }
Example #23
0
        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;
        }
        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(Module))
            {
                gitGetGraphCommand.StreamOutput = true;
                gitGetGraphCommand.CollectOutput = false;
                Encoding LogOutputEncoding = Module.LogOutputEncoding;
                gitGetGraphCommand.SetupStartInfoCallback = startInfo =>
                {
                    startInfo.StandardOutputEncoding = GitModule.LosslessEncoding;
                    startInfo.StandardErrorEncoding = GitModule.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 = GitModule.ReEncodeString(line, GitModule.LosslessEncoding, LogOutputEncoding);

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

            }
        }
Example #25
0
        private void Initialize()
        {
            EnableStageButtons(false);

            Cursor.Current = Cursors.WaitCursor;

            if (_gitGetUnstagedCommand == null)
            {
                _gitGetUnstagedCommand = new GitCommandsInstance();
                _gitGetUnstagedCommand.Exited += GitCommandsExited;
            }

            // Load unstaged files
            var allChangedFilesCmd =
                GitCommandHelpers.GetAllChangedFilesCmd(
                    !showIgnoredFilesToolStripMenuItem.Checked,
                    showUntrackedFilesToolStripMenuItem.Checked);
            _gitGetUnstagedCommand.CmdStartProcess(Settings.GitCommand, allChangedFilesCmd);

            // Check if commit.template is used
            ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
            string fileName = globalConfig.GetValue("commit.template");
            if (!string.IsNullOrEmpty(fileName))
            {
                using (var commitReader = new StreamReader(fileName))
                {
                    commitTemplate = commitReader.ReadToEnd().Replace("\r", "");
                }
                Message.Text = commitTemplate;
            }

            Loading.Visible = true;
            LoadingStaged.Visible = true;

            Commit.Enabled = false;
            CommitAndPush.Enabled = false;
            Amend.Enabled = false;
            Reset.Enabled = false;

            Cursor.Current = Cursors.Default;
        }