Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken SCM tree #8048

Merged
merged 1 commit into from
Jun 23, 2020
Merged

Fix broken SCM tree #8048

merged 1 commit into from
Jun 23, 2020

Conversation

westbury
Copy link
Contributor

Fixes #8004

What it does

The code that generated the tree in the Source Control view assumed that files came back from the SCM sorted, or at least with files in the same folder kept together. Git mostly does, but not always. So this PR sorts the files before building the tree.

How to test

  1. Checkout branch theia-7577
  2. Amend all the commits in the branch, back to and including the initial commit.
  3. See the tree under 'Staged Changes'. This tree is correct.
  4. Unstage all. You will now see the tree incorrect (without this PR), correct with this PR.

Review checklist

Reminder for reviewers

Signed-off-by: Nigel Westbury <[email protected]>
@westbury westbury added the scm issues related to the source control manager label Jun 18, 2020
@akosyakov akosyakov requested a review from vince-fugnitto June 19, 2020 06:35
@akosyakov
Copy link
Member

@vince-fugnitto Could you help reviewing it? or find a reviewer?

@akosyakov akosyakov requested a review from lmcbout June 19, 2020 06:36
@lmcbout
Copy link
Contributor

lmcbout commented Jun 19, 2020

Applying "How to Test", I don't see any differences between this patch and the master branch commit. It seems to be the same. What exactly should not be the same ? Is there something specific in the tree ?

@westbury
Copy link
Contributor Author

I don't see any differences between this patch and the master branch commit.

Did you unstage the changes?

The problem is caused because 'git status' returns the untracked files last. So if a folder contains both tracked and untracked files then the folder appears twice in the tree (except it doesn't because it will have the same id in both instances). Have a look at the screen shot in #8004.

The problem occurs for both Theia's git package and vs code's builtin.

@lmcbout
Copy link
Contributor

lmcbout commented Jun 19, 2020

I followed the
How to test
Checkout branch theia-7577
Amend all the commits in the branch, back to and including the initial commit.

(git reset  --soft c20fed2b5045392e113071176a284addfbde84fa to get all files)

See the tree under 'Staged Changes'. This tree is correct.
--> See the tree with all items marked with "A"
Unstage all.
--> See the tree with all files maked "U"
--> Tree is moved from 'Staged Changes' to Changes

Samething with / without this PR
Note: The screenshot is without your PR
Tested on Ubuntu 18.04
Is it specific to a platform ?

GitStageUnstage

@westbury
Copy link
Contributor Author

westbury commented Jun 19, 2020

@lmcbout Sorry, I meant the initial commit in the branch, not the initial commit in the repository. That would be resetting to daede30. I just checked out the branch then pressed the 'Amend' button three times (to amend the two merge commits plus the first commit in the branch).

You just need to get both a modified file and an untracked file into the CHANGES (unstaged) section. These two files must be in the same folder and not at the root of the repository. Furthermore these two files must be separated (in the order returned by git status) by one or more other files that are in a different folder.

@@ -207,19 +211,19 @@ export class ScmTreeModel extends TreeModelImpl {
if (folderEnd - folderStart < nestingThreshold) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, the name "nestingThreshold" seems to indicate the depth of the tree. I don't see how the difference between two different indices in the list of resources is related to that. Shouldn't this expression involve the level somehow?

// Multiple files with first folder.
// See if more folder levels match and include those if so.
let thisLevel = level + 1;
while (thisLevel < firstFileParts.length - 1 && thisLevel < lastFileParts.length - 1 && firstFileParts[thisLevel] === lastFileParts[thisLevel]) {
thisLevel++;
}
const nodeRelativePath = firstFileParts.slice(level, thisLevel).join('/');
result.push(this.toFileChangeFolderNode(resources, folderStart, folderEnd, thisLevel, nodeRelativePath, parent));
result.push(this.toFileChangeFolderNode(sortedResources, folderStart, folderEnd, thisLevel, nodeRelativePath, parent));
}
folderStart = folderEnd;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of result.sort(...) if we keep separate result arrays for file nodes and folder nodes and concatenate them at the end. With your change, the list of resources is already sorted and as far as I can see, the sorting will be correct under the algorithm.

@tsmaeder
Copy link
Contributor

@westbury is this algorithm time-critical? I have an idea to make it O(n), just wondering if it would be worth giving it a try.

@tsmaeder tsmaeder self-requested a review June 23, 2020 07:49
Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments are not directly related to the correctness of this change. Testing indicates that it fixes the problem and I haven't found any new ones. Therefore :lgtm:

Copy link
Contributor

@lmcbout lmcbout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I though I approved it yesterday, my mistake :(

@westbury
Copy link
Contributor Author

Thanks for your reviews.

@tsmaeder You are correct that the files and folders can be pushed to two lists and then appended, so O(n) rather than O(n log n). I would rather take the time to do a fuller performance investigation as we have a ticket against Mbed Studio complaining about the 1000 limit on the changes status. So I'll merge this fix for now.

@westbury westbury merged commit 9397130 into master Jun 23, 2020
@westbury westbury deleted the fix-scm-tree branch June 23, 2020 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scm issues related to the source control manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scm tree is not always correct
4 participants