oshbec / grit Goto Github PK
View Code? Open in Web Editor NEWImplementing git in rust to learn more about each
Implementing git in rust to learn more about each
Minimal implementation of git-init to get us started. While the full command looks like:
git init [-q | --quiet] [--bare] [--template=<template_directory>]
[--separate-git-dir <git dir>]
[--shared[=<permissions>]] [directory]
we're just starting with a basic:
git init [directory]
where directory
is the path to our new repository.
This is really just about making sure the right directory structure is created for the repository in a way that git will recognize our repo as valid.
Some details:
directory
isn't specified, default to the current working directorydirectory
doesn't yet exist, create itdirectory
, but all our git-y things go in .git
, minimally:
.git/objects
(a directory).git/refs
(another directory)For files that shouldn't be ignored (at this point, everything but .git
, running commit
should iterate through each of them, create a blob, and store it in the git database.
./git/objects/
)Clippy has some opinions about how I write my rust code. They'll prompt me to think about how I'm writing this thing in un-idiomatic ways and get better.
I've started work on this in a couple ways. 735b60a fixes a bunch of Clippy issues and e505954 gets CI yelling if there are any warnings.
This is mostly done. Except for one final warning:
warning: this `.filter_map` can be written more simply using `.filter`
--> src/ignore.rs:29:9
|
29 | / paths
30 | | .into_iter()
31 | | .filter_map(|p| {
32 | | if self.ignore_item(&p) {
... |
35 | | Some(p)
36 | | })
| |______________^
|
= note: #[warn(clippy::unnecessary_filter_map)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
Write the commit object. It looks something like this:
commit 173tree d563e95f9546ba7708a37dc1d61f82a1b4bbcf14
author Count Dracula <count@dracula> 1570466082 -0500
committer Count Dracula <count@dracula> 1570466082 -0500
It is a commit!
It depends on:
GIT_AUTHOR_NAME
and GIT_AUTHOR_EMAIL
)
%s %z
)
Things to do yet:
-m
and -message
as CLI args for the binaryHEAD
to point to the commit objectWhat's a tree?
It's like a blob
. It's an object. But instead of starting with blob
it starts with tree
. Like a blob, it even has a space after that first word, followed by the length of the file in bytes! There's even a null byte between the byte length and whatever comes next. Super familiar now, so 👍.
So what's in the body of this object? It's a list of files. They seem to be called entries though, so I've got a variable that needs to be renamed in the existing code to make this non-confusing. Each entry has:
100644
, for now)" "
)\0
100644 {file_name}\0{20_byte_object_id}
These are listed alphabetically by filename. And joined together with nothing between them (""
).
Commits beyond the first one should be keeping track of their parent. Add a parent
field to these commit objects with the ID of the parent commit.
The first commit should look like it does now, with no parent
field in sight.
Automated tests should run every time we push code. The simplest path to making this happens seems to be GitHub Actions and the new built-in CI stuff.
A dummy test file should be fine for now. I want to see two things:
assert!(false)
)assert!(true)
)Go ahead and leave the fake passing test in until we have our first real one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.