Remove .scalar directory from enlistment root#239
Remove .scalar directory from enlistment root#239derrickstolee merged 11 commits intomicrosoft:masterfrom derrickstolee:log-location
Conversation
|
I saw this is draft so I haven't taken a detailed look through the change yet, but one high level question that came to mind: With this change what is the best way to tell that a git repo is a Scalar repo (or is that no longer possible)? I'd hope our customers don't care (and don't want to check), but if we wanted to do something like add options for registering/unregistering a repo for maintenance would they be able to validate if they're running against a Scalar repo? Or would the maintenance tasks no-op if they were run against a repo that wasn't a Scalar repo (e.g. one that does use the MIDX)? |
This is a very good question, and I think it really depends on how we implement the "Scalar watching a vanilla Git repo" feature. I'm hoping to dig into that feature around December when everyone else is on vacation. In general, we will want to use our custom Git config values, for example:
|
|
@derrickstolee thanks for the details!
I think this config option sounds like a good fit for what I was asking about. If we reserve Plus there would be no need to check that there isn't a |
True. While I would like to have some notion of "enlistment id" for vanilla Git repos (think about supporting Edge/Chromium developers) we could change the name to |
kewillford
left a comment
There was a problem hiding this comment.
Looks good. Just a couple minor comments.
| private const int ScalarGenericError = 3; | ||
|
|
||
| [TestCase] | ||
| public void CloneInsideExistingEnlistment() |
There was a problem hiding this comment.
Don't we still want to make sure we can't scalar clone in an existing clone?
There was a problem hiding this comment.
That is something to watch for. But we need to reevaluate how to do that (or if we should).
I'm working to plan out what it would look like for Scalar to watch a vanilla Git repo, or a repo with submodules. I filed #241 to track this.
wilbaker
left a comment
There was a problem hiding this comment.
Overall I think these changes are looking good, just left a few comments.
| public override bool TryGetScalarEnlistmentRoot(string directory, out string enlistmentRoot, out string errorMessage) | ||
| { | ||
| return WindowsPlatform.TryGetScalarEnlistmentRootImplementation(directory, out enlistmentRoot, out errorMessage); | ||
| return WindowsFileSystem.TryGetNormalizedPathImplementation(directory, out enlistmentRoot, out errorMessage); |
There was a problem hiding this comment.
Rather than calling TryGetNormalizedPathImplementation here, should we something like one of the following instead:
- Update
TryGetScalarEnlistmentRootImplementationto search forsrc\.gitinstead of.scalar - Remove
TryGetScalarEnlistmentRootcompletely and update the callers to callTryGetNormalizedPath(confirming that behavior is correct for the caller).
My concern here that some callers of ScalarEnlistment.CreateFromDirectory might be depending on the old behavior of TryGetScalarEnlistmentRootImplementation walking up the directory tree (see its call to Paths.GetRoot). The change to call TryGetNormalizedPathImplementation is equivalent behavior.
Example: When something like scalar diagnose is run from a subfolder, EnlistmentRootPathParameter will be set to Environment.CurrentDirectory:
Line 84 in 9812441
And then that path will be passed to ScalarEnlistment.CreateFromDirectory:
scalar/Scalar/CommandLine/ScalarVerb.cs
Line 763 in 9812441
And TryGetScalarEnlistmentRoot needs to walk up the directory to find the correct root.
There was a problem hiding this comment.
Some clarifications:
- Update
TryGetScalarEnlistmentRootImplementationto search forsrc\.gitinstead of.scalar- Remove
TryGetScalarEnlistmentRootcompletely and update the callers to callTryGetNormalizedPath(confirming that behavior is correct for the caller).
These recommendations make sense if we are going to preserve the behavior in the current version of the PR, but not preserve the behavior in master.
My concern here that some callers of
ScalarEnlistment.CreateFromDirectorymight be depending on the old behavior ofTryGetScalarEnlistmentRootImplementationwalking up the directory tree (see its call toPaths.GetRoot). The change to callTryGetNormalizedPathImplementationis equivalent behavior.Example: When something like
scalar diagnoseis run from a subfolder,EnlistmentRootPathParameterwill be set toEnvironment.CurrentDirectory:Line 84 in 9812441
And then that path will be passed to
ScalarEnlistment.CreateFromDirectory:scalar/Scalar/CommandLine/ScalarVerb.cs
Line 763 in 9812441
And
TryGetScalarEnlistmentRootneeds to walk up the directory to find the correct root.
And I agree that I'm changing behavior in a bad way here. I'm not sure that using TryGetNormalizedPathImplementation() is enough, as it seems to have some VFS for Git leftovers (comments like "The folder might not be on disk yet...").
I'm going to instead do the following algorithm:
- On clone, set a
scalar.enlistmentRootconfig value in the Git config. - To discover the enlistment root, we do the following:
a. Check if the current directory has asrcsubfolder. If so, append that to the path.
b. Rungit config --local --get scalar.enlistmentRootin the path to get the config value. Git can walk the paths for us.
I believe this direction is future-proof to allow removing the src folder at clone time.
There was a problem hiding this comment.
Check if the current directory has a
srcsubfolder. If so, append that to the path.
There are src folders all over in some repos so what will happen running something from a directory inside the repo that has a src folder?
There was a problem hiding this comment.
The nice thing is that the Git command will walk up until seeing the .git folder to get the config option. We don't need to duplicate that option.
There was a problem hiding this comment.
On clone, set a scalar.enlistmentRoot config value in the Git config.
To discover the enlistment root, we do the following:
a. Check if the current directory has a src subfolder. If so, append that to the path.
b. Run git config --local --get scalar.enlistmentRoot in the path to get the config value. Git can walk the paths for us.
Another alternative:
- Call
git config --local --get scalar.enlistment-idto confirm repo is a Scalar repo - The enlistment root is the grandparent of the
.gitdirectory (maybe get that with a call togit rev-parse --absolute-git-dir?)
I'm not sure if that approach would be simpler/better, but it would avoid the need to set another config.
I actually wonder if we can use git rev-parse --absolute-git-dir to remove the need for TryGetNormalizedPathImplementation, but that could be its own investigation.
There was a problem hiding this comment.
I just realized the scenario my suggestion does not handle is checking while we are in the root itself (but perhaps we special case that by looking for a child src/.git directory)?
There was a problem hiding this comment.
@wilbaker: I've updated the algorithm to use that search instead of the config option.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
wilbaker
left a comment
There was a problem hiding this comment.
Just a few more comments, overall the PR is looking good.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
@kewillford noticed that the perf builds started failing after #239 merged. Revert it for now, and I'll investigate tomorrow.
This replaces #239 which was reverted in #248. The only change is the algorithm for finding the enlistment root. The previous algorithm had an issue when called from the `src` folder as it would create the enlistment root there and then the `ScalarEnlistment` class still automatically added `src` to that for the working directory root. This was not caught by the functional tests because they run the maintenance verbs from the enlistment root, not the `src` folder. I didn't catch it in testing because my local testing was from the old mechanism using `git config` instead. The performance test suite does reveal this problem. As a follow-up, we should remove the "working directory backing root" (#250).
Removing the
.scalardirectory took a few steps, and each commit can be reviewed independently:mount-id..scalarfolder an intosrc/.git/logs..scalar/diagnosticsand into.scalarDiagnostics.ShowStatusWhileRunning(the line that says "run scalar log for more info).DotScalarconstants.RepoMetadata.RepoMetadata..scalarfolder.