Small improvements

This commit is contained in:
Suzanne Soy 2021-04-02 18:29:48 +01:00
parent dcc466e4af
commit a4ba52e378
2 changed files with 29 additions and 19 deletions

View File

@ -49,7 +49,8 @@ article#git-tutorial { max-width: 63rem; position: absolute; right:18.4em; top:0
#git-tutorial #toc .notoc { display: none; } #git-tutorial #toc .notoc { display: none; }
#git-tutorial h1 { display: inline-block; } #git-tutorial h1 { display: inline-block; }
#git-tutorial h1 + p { clear: both; } #git-tutorial h1 + p { clear: both; }
#git-tutorial .permalink { opacity: 0.5; clear: both; padding: 1.2em 1.2em 0 0.5em; font-size: small; text-decoration: none; color: gray; } #git-tutorial .permalink { opacity: 0.5; clear: both; padding: 1.2em 1.2em 0 0.5em;
font-size: small; text-decoration: none; color: gray; }
#git-tutorial h1:hover + .permalink, #git-tutorial .permalink:hover { opacity: 1; } #git-tutorial h1:hover + .permalink, #git-tutorial .permalink:hover { opacity: 1; }
#git-tutorial #toc ul { list-style-type: none; padding: 0 !important; /*list-style-type: disc;*/ } #git-tutorial #toc ul { list-style-type: none; padding: 0 !important; /*list-style-type: disc;*/ }
#git-tutorial #toc a { color: #666; } #git-tutorial #toc a { color: #666; }

View File

@ -12,6 +12,8 @@
</head> </head>
<body> <body>
<h1>Under construction</h1>
<article id="git-tutorial"> <article id="git-tutorial">
<p>The main reference for this tutorial is the <a href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects">Pro Git book</a> section on GIT internals.</p> <p>The main reference for this tutorial is the <a href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects">Pro Git book</a> section on GIT internals.</p>
@ -88,9 +90,9 @@ directory.</p>
function listdir(dirname) { function listdir(dirname) {
var depth = dirname.split('/').length + 1; var depth = dirname.split('/').length + 1;
var descendents = filesystem var descendents = filesystem
.filter(filename => filename.startsWith(dirname + '/')); .filter(function (filename) { return filename.startsWith(dirname + '/'); });
var children = descendents var children = descendents
.map(filename => filename.split('/')[depth]); .map(function (filename) { return filename.split('/')[depth]; });
// remove duplicates: // remove duplicates:
return Array.from(new Set(children)); return Array.from(new Set(children));
} }
@ -217,14 +219,17 @@ This is done by creating a <em>tree</em> object</p>
// filenames is a list of strings // filenames is a list of strings
// subtrees is a list of {name, hash} objects. // subtrees is a list of {name, hash} objects.
function store_tree(base_directory, filenames, subtrees) { function store_tree(base_directory, filenames, subtrees) {
var get_file_hash = filename => function get_file_hash(filename) {
from_hex(hash_object(true, 'blob', false, join_paths(base_directory, filename))); return from_hex(hash_object(true, 'blob', false, join_paths(base_directory, filename)));
}
var blobs = filenames.map(filename => var blobs = filenames.map(function (filename) {
"100644 " + filename + "\0" + get_file_hash(filename)); return "100644 " + filename + "\0" + get_file_hash(filename)
});
var trees = subtrees.map(subtree => var trees = subtrees.map(function (subtree) {
"40000 " + subtree.name + "\0" + from_hex(subtree.hash)); return "40000 " + subtree.name + "\0" + from_hex(subtree.hash);
});
tree_contents = blobs.join('') + trees.join(''); tree_contents = blobs.join('') + trees.join('');
@ -235,14 +240,14 @@ function store_tree(base_directory, filenames, subtrees) {
<p>This function needs a small utility to convert hashes encoded in hexadecimal to a binary form.</p> <p>This function needs a small utility to convert hashes encoded in hexadecimal to a binary form.</p>
<textarea id="in9"> <textarea id="in9">
function from_hex(hex) { function from_hex(hex) {
var hex = String(hex); var hex = String(hex);
var str = "" var str = ""
for (var i = 0; i < hex.length; i+=2) { for (var i = 0; i < hex.length; i+=2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
} }
return str;
}
</textarea> </textarea>
<section id="store-tree-example"> <section id="store-tree-example">
@ -725,8 +730,8 @@ git_checkout(initial_commit);
to the default branch (a file which does not exist yet, as this branch does not contain any commit at this point).</p> to the default branch (a file which does not exist yet, as this branch does not contain any commit at this point).</p>
<textarea id="in21"> <textarea id="in21">
function git_init() { function git_init() {
git_init_mkdir(); git_init_mkdir();
git_init_head(); git_init_head();
} }
</textarea> </textarea>
</section> </section>
@ -822,6 +827,10 @@ git_checkout('main');
// the working directory matches the contents of HEAD. // the working directory matches the contents of HEAD.
store_index(['README', 'src/main.scm']); store_index(['README', 'src/main.scm']);
</textarea> </textarea>
<p>By clicking on "Copy commands to recreate in *nix terminal.", it is possible to copy a series of <code>mkdir …</code> and <code>printf … > …</code> commands that, when executed, will recreate the virtual filesystem on a real system. The resulting
folder is binary-compatible with the official <code>git log</code>, <code>git status</code>, <code>git checkout</code> etc.
commands.</p>
</section> </section>
<section id="conclusion"> <section id="conclusion">