Пример #1
0
        /// <summary>Deletes all stale tracking branches.</summary>
        public Task PruneAsync(IProgress <OperationProgress> progress, CancellationToken cancellationToken)
        {
            Verify.State.IsNotDeleted(this);

            if (progress != null)
            {
                progress.Report(new OperationProgress(Resources.StrsSearchingStaleBranches.AddEllipsis()));
            }
            var state1     = RefsState.Capture(Repository, ReferenceType.RemoteBranch);
            var block      = Repository.Monitor.BlockNotifications(RepositoryNotifications.BranchChanged);
            var parameters = GetPruneParameters();

            return(Repository.Accessor.PruneRemote.InvokeAsync(parameters, progress, cancellationToken)
                   .ContinueWith(
                       t =>
            {
                block.Dispose();
                Repository.Refs.Remotes.Refresh();
                var state2 = RefsState.Capture(Repository, ReferenceType.RemoteBranch);
                var changes = RefsDiff.Calculate(state1, state2);
                Repository.Remotes.OnPruneCompleted(this, changes);
                TaskUtility.PropagateFaultedStates(t);
            },
                       CancellationToken.None,
                       TaskContinuationOptions.ExecuteSynchronously,
                       TaskScheduler.Default));
        }
Пример #2
0
        public static Task FetchOrPullAsync(
            Repository repository, Remote remote, bool pull,
            IProgress <OperationProgress> progress, CancellationToken cancellationToken)
        {
            var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;

            if (pull)
            {
                affectedReferences |= ReferenceType.LocalBranch;
            }
            var suppressedNotifications = repository.Monitor.BlockNotifications(
                RepositoryNotifications.BranchChanged, RepositoryNotifications.TagChanged);
            var  state1 = RefsState.Capture(repository, affectedReferences);
            Task task;

            if (pull)
            {
                var p = new PullParameters();
                if (remote != null)
                {
                    p.Repository = remote.Name;
                }
                task = repository.Accessor.Pull.InvokeAsync(p, progress, cancellationToken);
            }
            else
            {
                var p = new FetchParameters();
                if (remote != null)
                {
                    p.Repository = remote.Name;
                }
                task = repository.Accessor.Fetch.InvokeAsync(p, progress, cancellationToken);
            }
            return(task.ContinueWith(
                       t =>
            {
                progress.Report(new OperationProgress(Resources.StrRefreshingReferences.AddEllipsis()));
                repository.Refs.Refresh(affectedReferences);
                var state2 = RefsState.Capture(repository, affectedReferences);
                var changes = RefsDiff.Calculate(state1, state2);
                suppressedNotifications.Dispose();
                if (changes != null && changes.Length != 0)
                {
                    repository.OnUpdated();
                }
                TaskUtility.PropagateFaultedStates(t);
                if (pull)
                {
                    repository.Remotes.OnPullCompleted(remote, changes);
                }
                else
                {
                    repository.Remotes.OnFetchCompleted(remote, changes);
                }
            }));
        }
Пример #3
0
        public static void FetchOrPull(Repository repository, Remote remote, bool pull)
        {
            var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;

            if (pull)
            {
                affectedReferences |= ReferenceType.LocalBranch;
            }
            ReferenceChange[] changes;
            var state1 = RefsState.Capture(repository, affectedReferences);

            using (repository.Monitor.BlockNotifications(
                       RepositoryNotifications.BranchChanged,
                       RepositoryNotifications.TagChanged))
            {
                try
                {
                    if (pull)
                    {
                        var p = new PullParameters();
                        if (remote != null)
                        {
                            p.Repository = remote.Name;
                        }
                        repository.Accessor.Pull.Invoke(p);
                    }
                    else
                    {
                        var p = new FetchParameters();
                        if (remote != null)
                        {
                            p.Repository = remote.Name;
                        }
                        repository.Accessor.Fetch.Invoke(p);
                    }
                }
                finally
                {
                    repository.Refs.Refresh(affectedReferences);
                    var state2 = RefsState.Capture(repository, affectedReferences);
                    changes = RefsDiff.Calculate(state1, state2);
                    if (changes != null && changes.Length != 0)
                    {
                        repository.OnUpdated();
                    }
                }
            }
            if (pull)
            {
                repository.Remotes.OnPullCompleted(remote, changes);
            }
            else
            {
                repository.Remotes.OnFetchCompleted(remote, changes);
            }
        }
Пример #4
0
        public static ReferenceChange[] Calculate(RefsState state1, RefsState state2)
        {
            var changeset = new List <ReferenceChange>();

            foreach (var refState2 in state2.States)
            {
                var refState1 = state1.GetState(refState2.FullName, refState2.ReferenceType);
                if (refState1 == null)
                {
                    changeset.Add(
                        new ReferenceChange(
                            refState2.ReferenceType,
                            refState2.FullName,
                            refState2.Name,
                            default(Hash),
                            refState2.Hash,
                            ReferenceChangeType.Added));
                }
                else
                {
                    if (refState2.Hash != refState1.Hash)
                    {
                        changeset.Add(
                            new ReferenceChange(
                                refState1.ReferenceType,
                                refState1.FullName,
                                refState1.Name,
                                refState1.Hash,
                                refState2.Hash,
                                ReferenceChangeType.Moved));
                    }
                }
            }
            foreach (var refState1 in state1.States)
            {
                var refState2 = state2.GetState(refState1.FullName, refState1.ReferenceType);
                if (refState2 == null)
                {
                    changeset.Add(
                        new ReferenceChange(
                            refState1.ReferenceType,
                            refState1.FullName,
                            refState1.Name,
                            refState1.Hash,
                            default(Hash),
                            ReferenceChangeType.Removed));
                }
            }
            return(changeset.ToArray());
        }
Пример #5
0
 public static ReferenceChange[] Calculate(RefsState state1, RefsState state2)
 {
     var changeset = new List<ReferenceChange>();
     foreach(var refState2 in state2.States)
     {
         var refState1 = state1.GetState(refState2.FullName, refState2.ReferenceType);
         if(refState1 == null)
         {
             changeset.Add(
                 new ReferenceChange(
                     refState2.ReferenceType,
                     refState2.FullName,
                     refState2.Name,
                     default(Hash),
                     refState2.Hash,
                     ReferenceChangeType.Added));
         }
         else
         {
             if(refState2.Hash != refState1.Hash)
             {
                 changeset.Add(
                     new ReferenceChange(
                         refState1.ReferenceType,
                         refState1.FullName,
                         refState1.Name,
                         refState1.Hash,
                         refState2.Hash,
                         ReferenceChangeType.Moved));
             }
         }
     }
     foreach(var refState1 in state1.States)
     {
         var refState2 = state2.GetState(refState1.FullName, refState1.ReferenceType);
         if(refState2 == null)
         {
             changeset.Add(
                 new ReferenceChange(
                     refState1.ReferenceType,
                     refState1.FullName,
                     refState1.Name,
                     refState1.Hash,
                     default(Hash),
                     ReferenceChangeType.Removed));
         }
     }
     return changeset.ToArray();
 }
Пример #6
0
        /// <summary>Deletes all stale tracking branches.</summary>
        public void Prune()
        {
            Verify.State.IsNotDeleted(this);

            var state1 = RefsState.Capture(Repository, ReferenceType.RemoteBranch);

            using (Repository.Monitor.BlockNotifications(
                       RepositoryNotifications.BranchChanged))
            {
                var parameters = GetPruneParameters();
                Repository.Accessor.PruneRemote.Invoke(parameters);
            }
            Repository.Refs.Remotes.Refresh();
            var state2  = RefsState.Capture(Repository, ReferenceType.RemoteBranch);
            var changes = RefsDiff.Calculate(state1, state2);

            Repository.Remotes.OnPruneCompleted(this, changes);
        }