Exemplo n.º 1
0
        public SyncResults SyncNow(SyncOptions options)
        {
            SyncResults results = new SyncResults();
            List <RepositoryAddress> sourcesToTry = options.RepositorySourcesToTry;
            //this just saves us from trying to connect twice to the same repo that is, for example, no there.
            Dictionary <RepositoryAddress, bool> connectionAttempts = new Dictionary <RepositoryAddress, bool>();

            try
            {
                if (_progress.ProgressIndicator != null)
                {
                    _progress.ProgressIndicator.IndicateUnknownProgress();
                }
                var repo = new HgRepository(_localRepositoryPath, _progress);

                RemoveLocks(repo);
                repo.RecoverFromInterruptedTransactionIfNeeded();
                repo.FixUnicodeAudio();
                string branchName = _sychronizerAdjunct.BranchName;
                ChangeBranchIfNecessary(branchName);
                Commit(options);

                var workingRevBeforeSync = repo.GetRevisionWorkingSetIsBasedOn();

                if (options.DoPullFromOthers)
                {
                    results.DidGetChangesFromOthers = PullFromOthers(repo, sourcesToTry, connectionAttempts);
                }

                if (options.DoMergeWithOthers)
                {
                    MergeHeadsOrRollbackAndThrow(repo, workingRevBeforeSync);
                }

                if (options.DoSendToOthers)
                {
                    SendToOthers(repo, sourcesToTry, connectionAttempts);
                }

                //If we did pull any data or a trivial merge succeeded we should call UpdateToTheDescendantRevision
                if (results.DidGetChangesFromOthers ||                                                             //we pulled something
                    (workingRevBeforeSync != null &&                //will be null if this is the 1st checkin ever, but no files were added so there was no actual rev created
                     !repo.GetRevisionWorkingSetIsBasedOn().Number.Hash.Equals(workingRevBeforeSync.Number.Hash))) //a merge happened
                {
                    UpdateToTheDescendantRevision(repo, workingRevBeforeSync);
                }
                _sychronizerAdjunct.CheckRepositoryBranches(repo.BranchingHelper.GetBranches(), _progress);

                results.Succeeded = true;
                _progress.WriteMessage("Done");
            }
            catch (SynchronizationException error)
            {
                error.DoNotifications(Repository, _progress);
                results.Succeeded        = false;
                results.ErrorEncountered = error;
            }
            catch (UserCancelledException error)
            {
                results.Succeeded        = false;
                results.Cancelled        = true;
                results.ErrorEncountered = null;
            }
            catch (Exception error)
            {
                if (error.InnerException != null)
                {
                    _progress.WriteVerbose("inner exception:");
                    _progress.WriteError(error.InnerException.Message);
                    _progress.WriteVerbose(error.InnerException.StackTrace);
                }

                _progress.WriteException(error);                //this preserves the whole exception for later retrieval by the client
                _progress.WriteError(error.Message);            //review still needed if we have this new WriteException?
                _progress.WriteVerbose(error.StackTrace);       //review still needed if we have this new WriteException?

                results.Succeeded        = false;
                results.ErrorEncountered = error;
            }
            return(results);
        }
Exemplo n.º 2
0
        public SyncResults SyncNow(SyncOptions options)
        {
            SyncResults results = new SyncResults();
            List<RepositoryAddress> sourcesToTry = options.RepositorySourcesToTry;
            //this just saves us from trying to connect twice to the same repo that is, for example, no there.
            Dictionary<RepositoryAddress, bool> connectionAttempts = new Dictionary<RepositoryAddress, bool>();

            try
            {
                if (_progress.ProgressIndicator != null)
                {
                    _progress.ProgressIndicator.IndicateUnknownProgress();
                }
                var repo = new HgRepository(_localRepositoryPath, _progress);

                RemoveLocks(repo);
                repo.RecoverFromInterruptedTransactionIfNeeded();
                repo.FixUnicodeAudio();
                string branchName = _sychronizerAdjunct.BranchName;
                ChangeBranchIfNecessary(branchName);
                Commit(options);

                var workingRevBeforeSync = repo.GetRevisionWorkingSetIsBasedOn();

                if (options.DoPullFromOthers)
                {
                    results.DidGetChangesFromOthers = PullFromOthers(repo, sourcesToTry, connectionAttempts);
                }

                if (options.DoMergeWithOthers)
                {
                    MergeHeadsOrRollbackAndThrow(repo, workingRevBeforeSync);
                }

                if (options.DoSendToOthers)
                {
                    SendToOthers(repo, sourcesToTry, connectionAttempts);
                }

                //If we did pull any data or a trivial merge succeeded we should call UpdateToTheDescendantRevision
                if (results.DidGetChangesFromOthers || //we pulled something
                    (workingRevBeforeSync!=null //will be null if this is the 1st checkin ever, but no files were added so there was no actual rev created
                    && !repo.GetRevisionWorkingSetIsBasedOn().Number.Hash.Equals(workingRevBeforeSync.Number.Hash))) //a merge happened
                {
                    UpdateToTheDescendantRevision(repo, workingRevBeforeSync);
                }
                _sychronizerAdjunct.CheckRepositoryBranches(repo.BranchingHelper.GetBranches(), _progress);

                results.Succeeded = true;
               _progress.WriteMessage("Done");
            }
            catch (SynchronizationException error)
            {
                error.DoNotifications(Repository, _progress);
                results.Succeeded = false;
                results.ErrorEncountered = error;
            }
            catch (UserCancelledException error)
            {
                results.Succeeded = false;
                results.Cancelled = true;
                results.ErrorEncountered = null;
            }
            catch (Exception error)
            {
                if (error.InnerException != null)
                {
                    _progress.WriteVerbose("inner exception:");
                    _progress.WriteError(error.InnerException.Message);
                    _progress.WriteVerbose(error.InnerException.StackTrace);
                }

                _progress.WriteException(error);//this preserves the whole exception for later retrieval by the client
                _progress.WriteError(error.Message);//review still needed if we have this new WriteException?
                _progress.WriteVerbose(error.StackTrace);//review still needed if we have this new WriteException?

                results.Succeeded = false;
                results.ErrorEncountered = error;
            }
            return results;
        }