public static MergeResult Execute(MergeOptions options) { options.Validate(); var merger = SelectMerger(options); bool success = merger.Merge(options.Commits.Select(c => ((Core.Commit)c).CommitId).ToArray()); var result = new MergeResult { Success = success }; result.Tree = new Tree(options.Repository, merger.GetResultTreeId()); if (options.NoCommit) { } else { if (string.IsNullOrEmpty(options.Message)) { options.Message = FormatMergeMessage(options); } var author = Author.GetDefaultAuthor(options.Repository); result.Commit = Commit.Create(options.Message, options.Commits, result.Tree, author, author, DateTimeOffset.Now); if (options.Branches.Length >= 1 && options.Branches[0] is Branch) { Ref.Update("refs/heads/" + options.Branches[0].Name, result.Commit); } } return(result); }
public static IEnumerable <Commit <byte[]> > Execute(DocumentTransaction tx, ReadEventsByCommitIds command) { if (!command.Ids.Any()) { return(Enumerable.Empty <Commit <byte[]> >()); } var parameters = new DynamicParameters(); foreach (var param in command.Ids.Select((value, i) => (name: $"@p{i}", value: value))) { parameters.Add(param.name, param.value); } var sql = $@" SELECT Position, EventId, CommitId, StreamId, SequenceNumber, Name, Generation, Metadata, Data FROM {tx.Store.Database.FormatTableNameAndEscape(command.Table.Name)} WHERE CommitId IN ({string.Join(", ", parameters.ParameterNames.Select(x => $"@{x}"))}) ORDER BY Position"; var commits = new[] { Commit.Empty <byte[]>() }.Concat( from row in tx.SqlConnection.Query <Row>(sql, parameters, tx.SqlTransaction) group row by row.CommitId into grouping let last = grouping.Last() select Commit.Create(grouping.Key, last.Generation, last.Position, grouping.Select(Row.ToEvent).ToList()) ).ToList(); return (from id in command.Ids join commit in commits on id equals commit.Id into cs from commit in cs.DefaultIfEmpty() select commit); }
public static Commit <byte[]> Execute(DocumentTransaction tx, LoadParentCommit command) { if (command.CommitId == Guid.Empty) { return(null); } var tablename = tx.Store.Database.FormatTableNameAndEscape(command.Table.Name); var sql = $@"SELECT EventId, Position, CommitId, StreamId, SequenceNumber, Name, Generation, Data, Metadata FROM {tablename} WHERE CommitId = ( SELECT TOP 1 CommitId FROM {tablename} WHERE Position < ISNULL( (SELECT MIN(Position) FROM {tablename} WHERE CommitId = @id), (SELECT MAX(Position) + 1 FROM {tablename}) ) ORDER BY Position DESC ) ORDER BY Position"; var rows = tx.SqlConnection.Query <Row>(sql, new { id = command.CommitId }, transaction: tx.SqlTransaction).ToList(); // if no parent commit is found, the initial, transient commit is parent if (!rows.Any()) { return(new Commit <byte[]>(Guid.Empty, 0, -1, -1)); } var lastRow = rows.Last(); return(Commit.Create(lastRow.CommitId, lastRow.Generation, lastRow.Position, rows.Select(Row.ToEvent).ToList())); }
public static IEnumerable <Commit <byte[]> > Batch(this IEnumerable <Row> rows) { var currentCommitId = Guid.Empty; var currentGeneration = -1; var currentPosition = -1L; var events = new List <EventData <byte[]> >(); foreach (var row in rows) { // first row if (currentCommitId == Guid.Empty) { currentCommitId = row.CommitId; } // next commit begun, return the current if (row.CommitId != currentCommitId) { yield return(Commit.Create(currentCommitId, currentGeneration, currentPosition, events)); currentCommitId = row.CommitId; events = new List <EventData <byte[]> >(); } currentGeneration = row.Generation; currentPosition = row.Position; // still same commit var metadata = new Metadata(JsonConvert.DeserializeObject <Dictionary <string, string> >(row.Metadata)); events.Add(new EventData <byte[]>(row.StreamId, row.EventId, row.Name, row.SequenceNumber, metadata, row.Data)); } if (events.Any()) { yield return(Commit.Create(currentCommitId, currentGeneration, currentPosition, events)); } }
/// <summary> /// Loads branches and commits. /// </summary> /// <param name="repo"></param> private void LoadBranchesAndCommits(LibGit2Sharp.Repository repo) { var dispose = false; if (repo == null) { repo = new LibGit2Sharp.Repository(RepositoryFullPath); dispose = true; } // Small performance boosts. Commits.DisableNotifications(); Branches.DisableNotifications(); // Create commits. Commits.Clear(); List <Commit> commitList = new List <Commit>(); foreach (LibGit2Sharp.Commit commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = repo.Branches }).Take(CommitsPerPage)) { commitList.Add(Commit.Create(repo, commit, Tags)); } Commits.AddRange(commitList); // Create branches. Branches.Clear(); foreach (LibGit2Sharp.Branch branch in repo.Branches) { Branch b = Branch.Create(this, repo, branch); Branches.Add(b); } // Post-process branches (tips and tracking branches). foreach (Branch branch in Branches) { // Set the HEAD property if it matches. if (repo.Head.Name == branch.Name) { Head = branch; branch.Tip.IsHead = true; } branch.PostProcess(Branches, Commits); } // Post-process commits (commit parents). foreach (Commit commit in Commits) { // Set the HEAD property to a DetachedHead branch if the HEAD matched and it was null. if (Head == null && repo.Head.Tip.Sha == commit.Hash) { Head = new DetachedHead { Tip = commit }; commit.IsHead = true; } commit.PostProcess(Commits, Branches); } // Calculate commit visual positions for each branch tree. foreach (Branch branch in Branches) { RepoUtil.IncrementCommitTreeVisualPositionsRecursively(branch.Tip); } Commits.EnableNotifications(); Branches.EnableNotifications(); if (dispose) { repo.Dispose(); } }
/// <summary> /// Loads branches and commits. /// </summary> /// <param name="repo"></param> private void LoadBranchesAndCommits(LibGit2Sharp.Repository repo = null) { var dispose = false; if (repo == null) { repo = new LibGit2Sharp.Repository(RepositoryFullPath); dispose = true; } // Small performance boosts. Commits.DisableNotifications(); Branches.DisableNotifications(); // Create commits. Commits.Clear(); var commitList = new List <Commit>(); foreach (var commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = repo.Branches }).Take(CommitsPerPage)) { commitList.Add(Commit.Create(repo, commit, Tags)); } Commits.AddRange(commitList); // Create branches. Branches.Clear(); foreach (var branch in repo.Branches) { var b = Branch.Create(this, repo, branch); Branches.Add(b); } // Post-process branches (tips and tracking branches). foreach (var branch in Branches) { // Set the HEAD property if it matches. if (repo.Head.Name == branch.Name) { Head = branch; branch.Tip.IsHead = true; } branch.PostProcess(Branches, Commits); } // Post-process commits (commit parents). foreach (var commit in Commits) { // Set the HEAD property to a DetachedHead branch if the HEAD matched and it was null. if (Head == null && repo.Head.Tip.Sha == commit.Hash) { Head = new DetachedHead { Tip = commit }; commit.IsHead = true; } commit.PostProcess(Commits, Branches); } // Calculate commit visual positions for each branch tree. foreach (var branch in Branches) { RepoUtil.IncrementCommitTreeVisualPositionsRecursively(branch.Tip); } // Fire notifications for the collections on the UI thread. Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action)(() => { Commits.EnableNotifications(true); Branches.EnableNotifications(true); var tabControl = UIHelper.FindChild <TabControl>(Application.Current.MainWindow, "RepositoryTabs"); var changesetHistory = UIHelper.FindChild <ChangesetHistory>(tabControl); if (changesetHistory != null) { changesetHistory.RedrawGraph(); } }) ); if (dispose) { repo.Dispose(); } }