This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Enable navigation from historical file to solution #1783
Merged
StanleyGoldman
merged 4 commits into
master
from
feature/navigate-from-history-to-working-directory
Aug 4, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3081e24
Enable navigation from historical file to solution
jcansdale c228d9e
Merge branch 'master' into feature/navigate-from-history-to-working-d…
StanleyGoldman 92f8298
Refactored to make more readable
jcansdale a7ee6e4
Merge branch 'master' into feature/navigate-from-history-to-working-d…
StanleyGoldman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ public class GitHubContextService : IGitHubContextService | |
| static readonly Regex treeishCommitRegex = new Regex($"(?<commit>[a-z0-9]{{40}})(/(?<tree>.+))?", RegexOptions.Compiled); | ||
| static readonly Regex treeishBranchRegex = new Regex($"(?<branch>master)(/(?<tree>.+))?", RegexOptions.Compiled); | ||
|
|
||
| static readonly Regex tempFileObjectishRegex = new Regex(@"\\TFSTemp\\[^\\]*[.](?<objectish>[a-z0-9]{8})[.][^.\\]*$", RegexOptions.Compiled); | ||
|
|
||
| [ImportingConstructor] | ||
| public GitHubContextService(IGitHubServiceProvider serviceProvider, IGitService gitService) | ||
| { | ||
|
|
@@ -305,6 +307,55 @@ public bool TryOpenFile(string repositoryDir, GitHubContext context) | |
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string FindObjectishForTFSTempFile(string tempFile) | ||
| { | ||
| var match = tempFileObjectishRegex.Match(tempFile); | ||
| if (match.Success) | ||
| { | ||
| return match.Groups["objectish"].Value; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public (string commitSha, string blobPath) ResolveBlobFromHistory(string repositoryDir, string objectish) | ||
| { | ||
| using (var repo = gitService.GetRepository(repositoryDir)) | ||
| { | ||
| var blob = repo.Lookup<Blob>(objectish); | ||
| if (blob == null) | ||
| { | ||
| return (null, null); | ||
| } | ||
|
|
||
| foreach (var commit in repo.Commits) | ||
| { | ||
| var trees = new Stack<Tree>(); | ||
| trees.Push(commit.Tree); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now know what a Git blob sha is, I've yet to wrap my head around a Commit Tree.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to read the tests more |
||
|
|
||
| while (trees.Count > 0) | ||
| { | ||
| foreach (var treeEntry in trees.Pop()) | ||
| { | ||
| if (treeEntry.Target == blob) | ||
| { | ||
| return (commit.Sha, treeEntry.Path); | ||
| } | ||
|
|
||
| if (treeEntry.TargetType == TreeEntryTargetType.Tree) | ||
| { | ||
| trees.Push((Tree)treeEntry.Target); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return (null, null); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool HasChangesInWorkingDirectory(string repositoryDir, string commitish, string path) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you name the group
objectish?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not you, that's just what the value is called in
RepoExtensions.Lookup(...). Nvm me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(first 8 chars of a blob SHA)ahhThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It started off being called blobish, but I stole the name from the
Lookupmethod you found. 😄