コード例 #1
0
        async public Task doUpdate(bool isAwaitedUpdate, CommitStorageUpdateContext context,
                                   Action <string> onProgressChange)
        {
            if (context == null || context.BaseToHeads.Data == null || !context.BaseToHeads.Data.Any() || _isDisposed)
            {
                return;
            }

            reportProgress(onProgressChange, "Downloading meta-information...");
            IEnumerable <FileInternal> allFiles = await fetchComparisonsAsync(isAwaitedUpdate, context);

            if (allFiles == null)
            {
                return;
            }

            reportProgress(onProgressChange, "Starting to download files from GitLab...");
            await processComparisonsAsync(isAwaitedUpdate, onProgressChange, allFiles);

            reportProgress(onProgressChange, "Files downloaded");
        }
コード例 #2
0
        async private Task <IEnumerable <FileInternal> > fetchComparisonsAsync(bool isAwaitedUpdate,
                                                                               CommitStorageUpdateContext context)
        {
            bool                      cancelled   = _isDisposed;
            Exception                 exception   = null;
            List <FileInternal>       allFiles    = new List <FileInternal>();
            List <ComparisonInternal> comparisons = new List <ComparisonInternal>();

            async Task doFetch(BaseToHeadsCollection.FlatBaseToHeadInfo baseToHeadInfo)
            {
                if (cancelled)
                {
                    return;
                }

                await suspendProcessingOfNonAwaitedUpdate(isAwaitedUpdate);

                Comparison comparison = await fetchSingleComparisonAsync(baseToHeadInfo.Base.Sha, baseToHeadInfo.Head.Sha);

                if (comparison == null || _isDisposed)
                {
                    cancelled = true;
                    return;
                }

                try
                {
                    throwOnBadComparison(comparison);
                }
                catch (LocalCommitStorageUpdaterLimitException ex)
                {
                    if (baseToHeadInfo.Files?.Any() ?? false)
                    {
                        ExceptionHandlers.Handle("Bad Comparison object", ex);
                        traceInformation(String.Format(
                                             "[FileStorageUpdater] Applying manual file comparison for {0} files", baseToHeadInfo.Files.Count()));
                        foreach (BaseToHeadsCollection.RelativeFileInfo fileInfo in baseToHeadInfo.Files)
                        {
                            allFiles.Add(new FileInternal(fileInfo.OldPath, baseToHeadInfo.Base.Sha));
                            allFiles.Add(new FileInternal(fileInfo.NewPath, baseToHeadInfo.Head.Sha));
                        }
                        return;
                    }

                    exception = ex;
                    cancelled = true;
                    return;
                }

                IEnumerable <DiffStruct> filteredDiffs = filterDiffs(isAwaitedUpdate, comparison.Diffs,
                                                                     baseToHeadInfo.Base.Sha, baseToHeadInfo.Head.Sha, baseToHeadInfo.Files);

                if (filteredDiffs != null && filteredDiffs.Any())
                {
                    comparisons.Add(new ComparisonInternal(filteredDiffs, baseToHeadInfo.Base.Sha, baseToHeadInfo.Head.Sha));
                }
            }

            await TaskUtils.RunConcurrentFunctionsAsync(context.BaseToHeads.Flatten(), doFetch,
                                                        () => getComparisonBatchLimits(isAwaitedUpdate), () => cancelled);

            if (exception != null)
            {
                throw exception;
            }

            if (cancelled)
            {
                return(null);
            }

            Action <string> traceFunction = traceDebug;

            if (isAwaitedUpdate)
            {
                traceFunction = traceInformation;
            }

            traceFunction(String.Format("Got {0} comparisons, isAwaitedUpdate={1}",
                                        comparisons.Count(), isAwaitedUpdate.ToString()));
            foreach (ComparisonInternal comparison in comparisons)
            {
                traceFunction(String.Format("{0} vs {1} ({2} files)",
                                            comparison.BaseSha, comparison.HeadSha, comparison.Diffs.Count()));
            }

            allFiles.AddRange(comparisons.SelectMany(x => extractFilesFromComparison(x)));
            return(allFiles);
        }