Пример #1
0
        private void PerformPrefetch(GVFSEnlistment enlistment, ITracer tracer)
        {
            try
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Commits", this.Commits);
                metadata.Add("PathWhitelist", this.PathWhitelist);
                metadata.Add("PathWhitelistFile", this.PathWhitelistFile);
                tracer.RelatedEvent(EventLevel.Informational, "PerformPrefetch", metadata);

                if (this.Commits)
                {
                    if (!string.IsNullOrEmpty(this.PathWhitelistFile) ||
                        !string.IsNullOrWhiteSpace(this.PathWhitelist))
                    {
                        this.ReportErrorAndExit("Cannot supply both --commits (-c) and --folders (-f)");
                    }

                    PrefetchHelper prefetchHelper = new PrefetchHelper(
                        tracer,
                        enlistment,
                        DownloadThreadCount);
                    prefetchHelper.PrefetchCommitsAndTrees();
                    return;
                }

                FetchHelper fetchHelper = new FetchHelper(
                    tracer,
                    enlistment,
                    ChunkSize,
                    SearchThreadCount,
                    DownloadThreadCount,
                    IndexThreadCount);

                if (!FetchHelper.TryLoadPathWhitelist(this.PathWhitelist, this.PathWhitelistFile, tracer, fetchHelper.PathWhitelist))
                {
                    Environment.ExitCode = (int)ReturnCode.GenericError;
                    return;
                }

                bool   gvfsHeadFileExists;
                string error;
                string projectedCommitId;

                if (!enlistment.TryParseGVFSHeadFile(out gvfsHeadFileExists, out error, out projectedCommitId))
                {
                    tracer.RelatedError(error);
                    this.Output.WriteLine(error);
                    Environment.ExitCode = (int)ReturnCode.GenericError;
                    return;
                }

                fetchHelper.FastFetch(projectedCommitId.Trim(), isBranch: false);
                if (fetchHelper.HasFailures)
                {
                    Environment.ExitCode = 1;
                }
            }
            catch (AggregateException e)
            {
                this.Output.WriteLine("Cannot prefetch @ {0}:", enlistment.EnlistmentRoot);
                foreach (Exception ex in e.Flatten().InnerExceptions)
                {
                    this.Output.WriteLine("Exception: {0}", ex.ToString());
                }

                Environment.ExitCode = (int)ReturnCode.GenericError;
            }
            catch (VerbAbortedException)
            {
                throw;
            }
            catch (Exception e)
            {
                this.ReportErrorAndExit("Cannot prefetch @ {0}: {1}", enlistment.EnlistmentRoot, e.ToString());
            }
        }