Ejemplo n.º 1
0
        public bool TryInvoke <TResult>(Func <LibGit2Repo, TResult> function, out TResult result)
        {
            LibGit2Repo repo = null;

            try
            {
                repo = this.GetRepoFromPool();
                if (repo != null)
                {
                    result = function(repo);
                    return(true);
                }

                result = default(TResult);
                return(false);
            }
            catch (Exception e)
            {
                this.tracer.RelatedError("Exception while invoking libgit2: " + e.ToString());
                throw;
            }
            finally
            {
                if (repo != null)
                {
                    this.ReturnToPool(repo);
                }
            }
        }
Ejemplo n.º 2
0
 private void ReturnToPool(LibGit2Repo repo)
 {
     if (repo != null)
     {
         if (this.pool.IsAddingCompleted ||
             !this.pool.TryAdd(repo, TryAddTimeoutMilliseconds))
         {
             // No more adding to the pool or trying to add to the pool failed
             repo.Dispose();
         }
     }
 }
Ejemplo n.º 3
0
        private void HandleAllFileAddOperations()
        {
            using (LibGit2Repo repo = new LibGit2Repo(this.tracer, this.enlistment.WorkingDirectoryRoot))
            {
                string availableBlob;
                while (this.AvailableBlobShas.TryTake(out availableBlob, millisecondsTimeout: -1))
                {
                    if (this.HasFailures)
                    {
                        return;
                    }

                    Interlocked.Increment(ref this.shasReceived);

                    HashSet <string> paths;
                    if (this.diff.FileAddOperations.TryRemove(availableBlob, out paths))
                    {
                        try
                        {
                            long written;
                            if (!repo.TryCopyBlobToFile(availableBlob, paths, out written))
                            {
                                // TryCopyBlobTo emits an error event.
                                this.HasFailures = true;
                            }

                            Interlocked.Add(ref this.bytesWritten, written);

                            foreach (string path in paths)
                            {
                                this.AddedOrEditedLocalFiles.Add(path);

                                if (Interlocked.Increment(ref this.fileWriteCount) % NumOperationsPerStatus == 0)
                                {
                                    EventMetadata metadata = new EventMetadata();
                                    metadata.Add("AvailableBlobsQueued", this.AvailableBlobShas.Count);
                                    metadata.Add("NumberBlobsNeeded", this.diff.FileAddOperations.Count);
                                    this.tracer.RelatedEvent(EventLevel.Informational, "CheckoutStatus", metadata);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            EventMetadata errorData = new EventMetadata();
                            errorData.Add("Operation", "WriteFile");
                            errorData.Add("ErrorMessage", ex.ToString());
                            this.tracer.RelatedError(errorData);
                            this.HasFailures = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void PerformDiff(string targetCommitSha)
        {
            string targetTreeSha;
            string headTreeSha;

            using (LibGit2Repo repo = new LibGit2Repo(this.tracer, this.enlistment.WorkingDirectoryBackingRoot))
            {
                targetTreeSha = repo.GetTreeSha(targetCommitSha);
                headTreeSha   = repo.GetTreeSha("HEAD");
            }

            this.PerformDiff(headTreeSha, targetTreeSha);
        }
Ejemplo n.º 5
0
        private void ReturnToPool(LibGit2Repo repo)
        {
            if (repo != null)
            {
                this.ResetRepoDisposalTimer();

                if (this.pool.IsAddingCompleted ||
                    !this.pool.TryAdd(repo, TryAddTimeoutMilliseconds))
                {
                    // No more adding to the pool or the pool is full
                    Interlocked.Decrement(ref this.numActiveRepos);
                    repo.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
        protected override void DoWork()
        {
            string blobId;

            using (LibGit2Repo repo = new LibGit2Repo(this.tracer, this.enlistment.WorkingDirectoryRoot))
            {
                while (this.inputQueue.TryTake(out blobId, Timeout.Infinite))
                {
                    if (!repo.ObjectExists(blobId))
                    {
                        Interlocked.Increment(ref this.missingBlobCount);
                        this.DownloadQueue.Add(blobId);
                    }
                    else
                    {
                        Interlocked.Increment(ref this.availableBlobCount);
                        this.AvailableBlobs.Add(blobId);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        protected void DownloadMissingCommit(string commitSha, GitObjects gitObjects)
        {
            EventMetadata startMetadata = new EventMetadata();

            startMetadata.Add("CommitSha", commitSha);

            using (ITracer activity = this.Tracer.StartActivity("DownloadTrees", EventLevel.Informational, Keywords.Telemetry, startMetadata))
            {
                using (LibGit2Repo repo = new LibGit2Repo(this.Tracer, this.Enlistment.WorkingDirectoryBackingRoot))
                {
                    if (!repo.ObjectExists(commitSha))
                    {
                        if (!gitObjects.TryDownloadCommit(commitSha))
                        {
                            EventMetadata metadata = new EventMetadata();
                            metadata.Add("ObjectsEndpointUrl", this.ObjectRequestor.CacheServer.ObjectsEndpointUrl);
                            activity.RelatedError(metadata, "Could not download commits");
                            throw new FetchException("Could not download commits from {0}", this.ObjectRequestor.CacheServer.ObjectsEndpointUrl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void DoWork()
        {
            string blobId;

            using (LibGit2Repo repo = new LibGit2Repo(this.tracer, this.enlistment.LocalStorageRoot))
            {
                while (this.requiredBlobs.TryTake(out blobId, Timeout.Infinite))
                {
                    if (this.alreadyFoundBlobIds.Add(blobId))
                    {
                        if (!repo.ObjectExists(blobId))
                        {
                            Interlocked.Increment(ref this.missingBlobCount);
                            this.MissingBlobs.Add(blobId);
                        }
                        else
                        {
                            Interlocked.Increment(ref this.availableBlobCount);
                            this.AvailableBlobs.Add(blobId);
                        }
                    }
                }
            }
        }