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); } } }
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(); } } }
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; } } } } }
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); }
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(); } } }
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); } } } }
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); } } } } }
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); } } } } }