private IEnumerable <string> ExtractLogParameter( GitBranch branch, int skip, int limit, GitLogOptions logOptions, string revisionRange) { IList <string> arguments = new List <string>(); arguments.Add($"{revisionRange} "); if (branch != null) { arguments.Add($"--branches={branch.FriendlyName} "); } if (skip > 0) { arguments.Add($"--skip={skip}"); } if (limit > 0) { arguments.Add($"--max-count={limit}"); } arguments.Add("--full-history"); if (logOptions.HasFlag(GitLogOptions.TopologicalOrder)) { arguments.Add("--topo-order"); } if (!logOptions.HasFlag(GitLogOptions.IncludeMerges)) { arguments.Add("--no-merges"); arguments.Add("--first-parent"); } GenerateFormat(arguments); if (logOptions.HasFlag(GitLogOptions.BranchOnlyAndParent)) { var ignoreBranches = new StringBuilder("--not "); IList <GitBranch> branches = this.GetLocalBranches().ToList().Wait(); foreach (GitBranch testBranch in branches) { if (testBranch != branch) { ignoreBranches.Append($"{testBranch.FriendlyName} "); } } arguments.Add($" {ignoreBranches} -- "); } return(arguments); }
/// <inheritdoc /> public IObservable <GitCommit> GetCommitsForBranch( GitBranch branch, int skip, int limit, GitLogOptions logOptions, IScheduler scheduler = null) { return(Observable.Return(new[] { "log" }) .CombineLatest(ExtractLogParameter(branch, skip, limit, logOptions, "HEAD"), (cmd, other) => cmd.Concat(other)) .SelectMany(x => _gitProcessManager.RunGit(x, scheduler: scheduler).Select(ConvertStringToGitCommit))); }
/// <inheritdoc /> public IObservable <GitCommit> GetCommitsForBranch( GitBranch branch, int skip, int limit, GitLogOptions logOptions, IScheduler scheduler = null) { string[] arguments = new[] { "log" }.Concat(this.ExtractLogParameter(branch, skip, limit, logOptions, "HEAD")).ToArray(); return(this.gitProcessManager.RunGit(arguments, scheduler: scheduler).Select(this.ConvertStringToGitCommit)); }
private IObservable <IEnumerable <string> > ExtractLogParameter( GitBranch branch, int skip, int limit, GitLogOptions logOptions, string revisionRange) { IList <string> arguments = new List <string>(); arguments.Add($"{revisionRange} "); if (branch != null) { arguments.Add($"--branches={branch.FriendlyName} "); } if (skip > 0) { arguments.Add($"--skip={skip}"); } if (limit > 0) { arguments.Add($"--max-count={limit}"); } arguments.Add("--full-history"); if (logOptions.HasFlag(GitLogOptions.TopologicalOrder)) { arguments.Add("--topo-order"); } if (!logOptions.HasFlag(GitLogOptions.IncludeMerges)) { arguments.Add("--no-merges"); arguments.Add("--first-parent"); } GenerateFormat(arguments); var argumentsObservable = Observable.Return(arguments); if (logOptions.HasFlag(GitLogOptions.BranchOnlyAndParent)) { argumentsObservable = argumentsObservable.CombineLatest( GetLocalBranches().Where(x => x != branch).Select(x => x.FriendlyName).ToList().Select(x => $"--not {string.Join(" ", x)} --"), (arg, branches) => arg.Concat(new[] { branches }).ToList()); } return(argumentsObservable); }
/// <inheritdoc /> public Task <IList <GitCommit> > GetCommitsForBranch(GitBranch branch, CancellationToken token, GitLogOptions logOptions, int number = 25) { return(this.branchManager.GetCommitsForBranch(branch, 0, number, logOptions, token)); }
/// <summary> /// Initializes a new instance of the <see cref="GitLogOptionViewModel"/> class. /// </summary> /// <param name="logOption">The log option this represents.</param> public GitLogOptionViewModel(GitLogOptions logOption) { this.Value = logOption; this.Name = Enum.GetName(typeof(GitLogOptions), logOption); }
private async Task <string> ExtractLogParameter(GitBranch branch, int skip, int limit, GitLogOptions logOptions, string revisionRange, CancellationToken token) { StringBuilder arguments = new StringBuilder(); arguments.Append($"{revisionRange} "); if (branch != null) { arguments.Append($"--branches={branch.FriendlyName} "); } if (skip > 0) { arguments.Append($" --skip={skip}"); } if (limit > 0) { arguments.Append($" --max-count={limit}"); } arguments.Append(" --full-history"); if (logOptions.HasFlag(GitLogOptions.TopologicalOrder)) { arguments.Append(" --topo-order"); } if (!logOptions.HasFlag(GitLogOptions.IncludeMerges)) { arguments.Append(" --no-merges --first-parent"); } GenerateFormat(arguments); if (logOptions.HasFlag(GitLogOptions.BranchOnlyAndParent)) { StringBuilder ignoreBranches = new StringBuilder("--not "); var branches = await this.GetLocalBranches(token); foreach (var testBranch in branches) { if (testBranch != branch) { ignoreBranches.Append($"{testBranch.FriendlyName} "); } } arguments.Append($" {ignoreBranches} -- "); } return(arguments.ToString()); }
/// <inheritdoc /> public async Task <IList <GitCommit> > GetCommitsForBranch(GitBranch branch, int skip, int limit, GitLogOptions logOptions, CancellationToken token) { string arguments = await this.ExtractLogParameter(branch, skip, limit, logOptions, "HEAD", token); var result = await this.gitProcessManager.RunGit("log " + arguments, token); if (result.Success == false) { return(new List <GitCommit>()); } string[] lines = result.ProcessOutput.Trim('\r', '\n').Split(new[] { '\u001e' }, StringSplitOptions.RemoveEmptyEntries); IList <GitCommit> results = ConvertStringToGitCommits(lines).ToList(); if (logOptions.HasFlag(GitLogOptions.BranchOnlyAndParent) && results.Last().Parents.Any()) { await this.GetSingleCommitLog(token, results); } return(results); }