How does git diff work in vscode git extension?

I am trying to create a version control extension in vscode. I tried to take a look at the git implementation in vscode. The confusing part is the diff file. The source code for the git extension uses vscode.diff to view file vscode.diff . To get the uri source file, a new uri is created by changing the scheme modified uri file. How it works?

eg,

In https://github.com/Microsoft/vscode/blob/master/extensions/git/src/commands.ts , getRightResource method, toGitUri is called from the uri of the file. toGitUri is executed as follows:

 export function toGitUri(uri: Uri, ref: string, replaceFileExtension = false): Uri { return uri.with({ scheme: 'git', path: replaceFileExtension ? `${uri.path}.git` : uri.path, query: JSON.stringify({ path: uri.fsPath, ref }) }); } 

Here toGitUri just changes the file scheme from file to git with the request. This uri then provided by vscode.diff along with the original uri file to show diff git. How does toGitUri work?

thanks and welcome

Satish V

+7
version-control visual-studio-code vscode-extensions
source share
1 answer

I think that there is no difference. I also think that you correctly understood what this function does: it takes the file URI for the file on disk and finds the corresponding URI for git repo. And then he has 2 resources for comparison.

Then these 2 resources are transferred to the built-in various functionality.

Track the code in 1.12.1 (follow the links one by one):

  • vscode.diff registered here

  • delegates before _workbench.diff

  • This one is registered here and delegates to edit the built-in diff ...

  • ... like this: editorService.openEditor({ leftResource, rightResource, ...) ...

  • ... where leftResource is the file on disk and rightResource is the URI for the file in git repo.
+3
source share

All Articles