Skip to content

Instantly share code, notes, and snippets.

@BillyONeal
Created October 21, 2022 00:22
Show Gist options
  • Save BillyONeal/04a77c971d87a5b0e3727a42dd9e5dbe to your computer and use it in GitHub Desktop.
Save BillyONeal/04a77c971d87a5b0e3727a42dd9e5dbe to your computer and use it in GitHub Desktop.
Example of how git registries work
Git registry declaration has:
"repository": {
"type": "string",
"description": "The URI or SSH entry to clone from. (as if by `git clone`)"
},
"baseline": {
"description": "The SHA that will be checked out to find default versions for ports from this registry.",
"$ref": "#/definitions/sha1"
},
"reference": {
"type": "string",
"description": "The ref to fetch when cloning this git registry."
},
"packages": true
}
This says:
The baseline is the commit in the repository at the baseline SHA
The version database is in the commit referenced by the ref in "reference"
Example:
{
"kind": "git",
"baseline": "ae47a08cf1b4200d39a888e925a339b4d5a1ab5a",
"repository": "https://github.com/microsoft/vcpkg",
"reference": "master",
"packages": ["zlib"]
}
Baseline SHA -> baseline commit
Inside baseline commit, at versions/baseline.json, there is a version number per port
The version number is looked up in the head ref's versions/p-/port.json which contains version -> git tee-object SHA
The tree object is extracted to a temporary directory and loaded as a port
This means this is morally:
git clone <REPOSITORY> -b <REFERENCE> (Example: git clone https://github.com/microsoft/vcpkg -b master )
The version database is located in the clone at versions/*
git show <BASELINE>/versions/baseline.json (Example: git show ae47a08cf1b4200d39a888e925a339b4d5a1ab5a/versions/baseline.json)
This prints the JSON file containing all the versions to use when selected by the baseline.
Let's say for the sake of argument that it had zlib being this:
"zlib": {
"baseline": "1.2.12",
"port-version": 2
},
To map from version number to a git tree object containing the port's actual content, the version database is consulted (which came from the cloned reference, so it may have versions from the "future" relative to the baseline commit / json file)
(Under the covers this does a rev-parse <SHA OF REFERENCE>:versions + git archive <result> + tar zxf)
For the sake of argument, let's say that has:
{
"git-tree": "d40d86865ecbcc5b54d21f840dd2212556aeadd5",
"version": "1.2.12",
"port-version": 2
},
This tells us that the git tree object d40d86865ecbcc5b54d21f840dd2212556aeadd5 is the port directory of [email protected]#2
Next, that tree object is extracted by:
git archive --format tar <TREE OBJECT SHA> --output <A temporary location>
The temporary tar archive is extracted to C:\Users\bion\AppData\Local\vcpkg\registries\git-trees\<TREE OBJECT SHA>
Example:
git archive --foramt tar d40d86865ecbcc5b54d21f840dd2212556aeadd5 --output temp.tar
mkdir temp
cd temp
tar zsf ..\temp.tar
ls
Directory: C:\Dev\vcpkg\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/20/2022 5:14 PM 1417 0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch
-a--- 10/20/2022 5:14 PM 804 0002-android-build-mingw.patch
-a--- 10/20/2022 5:14 PM 2946 cmake_dont_build_more_than_needed.patch
-a--- 10/20/2022 5:14 PM 819 CVE-2022-37434.patch
-a--- 10/20/2022 5:14 PM 348 debug-postfix-mingw.patch
-a--- 10/20/2022 5:14 PM 1881 portfile.cmake
-a--- 10/20/2022 5:14 PM 148 usage
-a--- 10/20/2022 5:14 PM 709 vcpkg-cmake-wrapper.cmake
-a--- 10/20/2022 5:14 PM 252 vcpkg.json
This is then interpreted as a port to build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment