コード例 #1
0
        void dataReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            if (line == COMMIT_BEGIN)
            {
                // a new commit finalizes the last revision
                finishRevision();

                nextStep = ReadStep.Commit;
            }

            switch (nextStep)
            {
            case ReadStep.Commit:
                // Sanity check
                if (line == COMMIT_BEGIN)
                {
                    revision = new GitRevision();
                }
                else
                {
                    // Bail out until we see what we expect
                    return;
                }
                break;

            case ReadStep.Hash:
                revision.Guid = line;
                for (int i = heads.Count - 1; i >= 0; i--)
                {
                    if (heads[i].Guid == revision.Guid)
                    {
                        revision.Heads.Add(heads[i]);

                        //Only search for a head once, remove it from list
                        heads.Remove(heads[i]);
                    }
                }
                break;

            case ReadStep.Parents:
                revision.ParentGuids = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                break;

            case ReadStep.Tree:
                revision.TreeGuid = line;
                break;

            case ReadStep.AuthorName:
                revision.Author = line;
                break;

            case ReadStep.AuthorEmail:
                revision.AuthorEmail = line;
                break;

            case ReadStep.AuthorDate:
            {
                DateTime dateTime;
                DateTime.TryParse(line, out dateTime);
                revision.AuthorDate = dateTime;
            }
            break;

            case ReadStep.CommitterName:
                revision.Committer = line;
                break;

            case ReadStep.CommitterDate:
            {
                DateTime dateTime;
                DateTime.TryParse(line, out dateTime);
                revision.CommitDate = dateTime;
            }
            break;

            case ReadStep.CommitMessage:
                //We need to recode the commit message because of a bug in Git.
                //We cannot let git recode the message to Settings.Encoding which is
                //needed to allow the "git log" to print the filename in Settings.Encoding
                if (logoutputEncoding == null)
                {
                    logoutputEncoding = GitCommandHelpers.GetLogoutputEncoding();
                }

                if (!logoutputEncoding.Equals(Settings.Encoding))
                {
                    revision.Message = logoutputEncoding.GetString(Settings.Encoding.GetBytes(line));
                }
                else
                {
                    revision.Message = line;
                }
                break;

            case ReadStep.FileName:
                revision.Name = line;
                break;
            }

            nextStep++;
        }
コード例 #2
0
 /// <summary>
 /// Push a local branch to a remote one, optionally forcing a non-fast-forward commit.
 /// </summary>
 /// <param name="source">Name of the branch to push.</param>
 /// <param name="destination">Ref on the remote side to be updated.</param>
 /// <param name="force">Indicates whether to update the <paramref name="destination"/>
 /// ref even when the update is not a fast-forward.</param>
 public GitPushAction(string source, string destination, bool force = false)
 {
     _localBranch  = GitCommandHelpers.GetFullBranchName(source);
     _remoteBranch = GitCommandHelpers.GetFullBranchName(destination);
     _force        = force;
 }
コード例 #3
0
        private void execute()
        {
            try
            {
                RevisionCount = 0;

                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 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);

                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);
            }
        }
コード例 #4
0
 /// <summary>Delete a remote branch.</summary>
 /// <param name="branch">Remote branch to delete.</param>
 public static GitPushAction DeleteRemoteBranch(string branch)
 {
     branch = GitCommandHelpers.GetFullBranchName(branch);
     return(new GitPushAction(null, branch));
 }