예제 #1
0
 private static Command GetCommand2(QueryStashParameters parameters)
 {
     return(new LogCommand(
                LogCommand.WalkReflogs(),
                LogCommand.NullTerminate(),
                LogCommand.FormatRaw(),
                new CommandParameter(GitConstants.StashFullName)));
 }
예제 #2
0
        public IList <StashedStateData> Invoke(QueryStashParameters parameters)
        {
            Verify.Argument.IsNotNull(parameters, "parameters");

            var command = _commandFactory(parameters);
            var output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();

            var cache = new Dictionary <Hash, RevisionData>(Hash.EqualityComparer);
            var list  = ParseResult1(output, cache);

            // get real commit parents
            command = GetCommand2(parameters);
            output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);
            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);

            parser.ParseCommitParentsFromRaw(list.Select(rrd => rrd.Revision), cache);

            return(list);
        }
예제 #3
0
        public Command GetQueryStashCommand(QueryStashParameters parameters)
        {
            Assert.IsNotNull(parameters);

            return new LogCommand(
                LogCommand.WalkReflogs(),
                LogCommand.NullTerminate(),
                GetRevisionFormatArgument(),
                new CommandParameter(GitConstants.StashFullName));
        }
예제 #4
0
        public Task <IList <StashedStateData> > InvokeAsync(QueryStashParameters parameters,
                                                            IProgress <OperationProgress> progress, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(parameters, "parameters");

            var command1 = _commandFactory(parameters);
            var command2 = GetCommand2(parameters);

            var tcs = new TaskCompletionSource <object>();

            if (cancellationToken.CanBeCanceled)
            {
                cancellationToken.Register(() => tcs.TrySetCanceled());
            }

            int completedTasks = 0;

            var task1 = _commandExecutor.ExecuteCommandAsync(command1, CommandExecutionFlags.None, cancellationToken);
            var task2 = _commandExecutor.ExecuteCommandAsync(command2, CommandExecutionFlags.None, cancellationToken);

            task1.ContinueWith(
                t => tcs.TrySetCanceled(),
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnCanceled,
                TaskScheduler.Default);
            task2.ContinueWith(
                t => tcs.TrySetCanceled(),
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnCanceled,
                TaskScheduler.Default);
            task1.ContinueWith(
                t => tcs.TrySetException(t.Exception),
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted,
                TaskScheduler.Default);
            task2.ContinueWith(
                t => tcs.TrySetException(t.Exception),
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted,
                TaskScheduler.Default);
            task1.ContinueWith(
                t =>
            {
                if (Interlocked.Increment(ref completedTasks) == 2)
                {
                    tcs.TrySetResult(null);
                }
            },
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
                TaskScheduler.Default);
            task2.ContinueWith(
                t =>
            {
                if (Interlocked.Increment(ref completedTasks) == 2)
                {
                    tcs.TrySetResult(null);
                }
            },
                cancellationToken,
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
                TaskScheduler.Default);

            return(tcs.Task.
                   ContinueWith(
                       t =>
            {
                TaskUtility.PropagateFaultedStates(t);

                var output1 = TaskUtility.UnwrapResult(task1);
                output1.ThrowOnBadReturnCode();
                var output2 = TaskUtility.UnwrapResult(task2);
                output2.ThrowOnBadReturnCode();

                var cache = new Dictionary <Hash, RevisionData>(Hash.EqualityComparer);
                var list = ParseResult1(output1, cache);
                var parser = new GitParser(output2.Output);
                parser.ParseCommitParentsFromRaw(list.Select(rrd => rrd.Revision), cache);
                return list;
            },
                       cancellationToken,
                       TaskContinuationOptions.ExecuteSynchronously,
                       TaskScheduler.Default));
        }