Implementing (parts of) git from scratch in Rust

  Рет қаралды 87,471

Jon Gjengset

Jon Gjengset

Күн бұрын

Пікірлер: 80
@laurenlewis4189
@laurenlewis4189 9 ай бұрын
Not only the best resource for learning Rust on the internet, also one of the most clear and easy to follow programming tutors on the internet. Thanks for all you do, Jon!
@yotubecreators47
@yotubecreators47 9 ай бұрын
Jon's channel is my favorite place on internet and earth thank you Jon please do more of these
@MohitAgnihotri5
@MohitAgnihotri5 9 ай бұрын
Thank you for the video. I am writing in the Rust from last 2 years for commercial company. It's a coincidence that my name is previewing in your video @01:09 "mohitagnihotri", I have implemented this challenge own self (no external reference) and now comparing my solution with yours. I learn not only from your way of Rust code implementation but I also take some lessons from your thought process. Really very beneficial for me. Thankful to you!!!
@DotDager
@DotDager 9 ай бұрын
Hey man, just wanted to say I love your stuff. This kind of stream actually sold me on streaming CodeCrafters myselft, and on playing with Rust as well. Keep it up!
@driedurchin
@driedurchin 9 ай бұрын
The cross-platform gymnastics git has to do is truly spooky.
@Benabik
@Benabik 9 ай бұрын
3:19:10 The write-tree ordering was bugging me, so I looked at what git.git does. The ordering of the tree contents is just based on comparing bytes (strcmp), but they are sorting the entire index which has entries like "src/commands-rs" and "src/commands/write_tree-rs" (using dashes instead of dots to avoid becoming links). So the ordering in the tree object includes a phantom "/" at the end of a directory name. Ignoring the index probably makes the examples easier, but make actually working like git much harder.
@Benabik
@Benabik 9 ай бұрын
3:33:04 I think the comparison logic you looked up is trying to emulate that without building the index. But you can see the place new entries are added in add_index_entry_with_check in read-cache and that is just using strcmp. You can see the result with `git ls-files --stage` which shows that ordering.
@adamszalkowski8226
@adamszalkowski8226 9 ай бұрын
Oh, thank you! Just found your comment. Had the same theory - thanks for looking it up!
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
Thanks for looking this up! Implicitly ending with a slash actually makes a lot of sense... though I'd prefer that the UI showed it!
@flwi
@flwi 9 ай бұрын
This blows me away. I thought there is more "magic" in git. Nice to learn how it works. I'm currently learning rust and had a good time following your explanations. You have a very good style of explaining things!
@jordanyates3349
@jordanyates3349 9 ай бұрын
Another neat thing to implement might be an Entity Component System like FLECS / shipyard / etc
@angelstojanov2346
@angelstojanov2346 9 ай бұрын
I second this
@kenzo3477
@kenzo3477 9 ай бұрын
Jon, a walk through the actix framework would be nice for someone like me trying to understand the actor model
@draakisback
@draakisback 9 ай бұрын
Actix's actor model is not a great representation of most other actor models. It's got some really weird limitations and it's difficult to build proper supervision trees with it.
@cooldude3010
@cooldude3010 9 ай бұрын
**british DJ voice** one of the best one of the best more of these building complex systems long form videos please bossman
@clubpenguinfan1928
@clubpenguinfan1928 9 ай бұрын
Wait, you're one of the missing semester folks? Holy crap you're the goat
@codingcoyote
@codingcoyote 9 ай бұрын
Haven't watched it yet, but as someone still getting acquainted with rust and craving a deeper understanding of gits internals, I look forward to seeing what you've done.
@puolisointu
@puolisointu 9 ай бұрын
I was inspired by this and did the redis challenge. It was super interesting and I learned a lot. It would be awesome to see Jon have a stab at it the "correct" way. I have a little bit of trouble of finding correct mental model of TCP and how to parse it incrementally without excessive cloning, it's hard to search youtube or google for good information. If you have any recommendations for material I would be interested!
@ruijieyu9035
@ruijieyu9035 7 ай бұрын
3:40:22 it seems that ultimately the comparison rule just says append / to directory names while sorting, and what the git function does is to ensure that no new memory allocation is needed
@damoon_az2465
@damoon_az2465 9 ай бұрын
Thanks!
@driedurchin
@driedurchin 9 ай бұрын
AFAIK Windows has no concept of an executable bit. On windows, under git-bash, it has a series of heuristics that it uses to guess if a file is executable, but they don't work well. So much so, there is a specific git subcommand to directly set its file-mode flags because you have no chmod on windows. P.S. One of the heuristics it uses when you run ls -la on git-bash is to actually check for shebang by reading the file.
@danygagnon8446
@danygagnon8446 9 ай бұрын
I watched all of your videos and they're so well made. Thanks so much for this content. You are amazing!
@LesleyLai
@LesleyLai 9 ай бұрын
Nice content! My implementation used a lot of in-memory strings compared to your streaming implementation. This is definitely very educational!
@microcolonel
@microcolonel 9 ай бұрын
I love to send this kind of material to people. I'm thinking of doing my own spin on these types of challenges, where we start with a discussion of the problem and datastructure and dataflow design, and then build in a way that is *fast* by the time the tutorial is done. For example in this or the bittornent one, architecting for io_uring and mmap, instead of high overhead POSIX stuff.
@dantenotavailable
@dantenotavailable 9 ай бұрын
Interesting note: not sure about the rest of the plumbing but `git cat-file` itself will ignore the size value and print the entire rest of file. I used the same basic idea you used for your type (i.e. read one byte extra and compare how much was read) and created an object with a mangled size for testing. Tried it on both, mine worked, proper git printed the entire file.
@JaLikon65
@JaLikon65 9 ай бұрын
Great episode! Not only did I learn a bit about Rust, but I also learned quite a bit about git! Nice :)
@drvanon
@drvanon 9 ай бұрын
I wonder why your abstractions returned out so awesome. I notice that often when I make my own abstractions they often do not benefit me as much as i do see n this video
@TheAulto
@TheAulto 9 ай бұрын
That may also be your case, but he doesn’t seem to abstract until needed. Your first guess it probably gonna fail, so just inline everything and wait for a clear second candidate to pop up, evaluate and implement. Especially with an already working state, it should also be easier to pull off.
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
The general answer is unfortunately "get good" - there's lots of rules of thumb and guidelines and blog posts and everything else telling you how to do it well: and none of them seem to really help all that much because you don't know which to use and when. For me, it's all been hard-won experience over to decades, and I think I'm still not as good as Jon. Ugh. 😂
@adamszalkowski8226
@adamszalkowski8226 9 ай бұрын
Maybe the directories in write-tree have a silent slash at the end?
@Joqer88
@Joqer88 9 ай бұрын
This is like crack to me, I can't get enough! Not only do I learn more Rust, I learn more stuff about git! I wish this challenge would continue until a fully featured git clone (😉) would be implemented!
@steffenuhlig1970
@steffenuhlig1970 9 ай бұрын
My brain already hurts after watching just about a third of the video, but it _is_ amazing. Thanks for this!
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
Surprised the tree sort didn't just use collect(). I suppose you can't distinguish the errors?
@adrienpelfresne9820
@adrienpelfresne9820 2 ай бұрын
can someone tell me what font he is using ? thanks a lot
@Gh0stwrter
@Gh0stwrter 3 ай бұрын
great video man, it was the first time I came across your channel. I've went back to C to try and gain a better understanding for Rust which is helping and I go back and forth between the two a lot. Kinda like Neovim and Doom Emacs, I use both for some reason and both are great but your neovim theme is a little different then the grobox type themes I've been using. I like that comments are orange. Would you mind sharing what theme your neovim is using and is that feline status bar? also what lsp are you using for rust in vim? I ask becasue you are not getting tons of errors outputted recommendations when your first starting out and that always bothers me.
@jonhoo
@jonhoo 3 ай бұрын
Hey there! I discuss a lot of those things over in kzbin.info/www/bejne/rp7Uoa2mr8mdf5o :)
@Gh0stwrter
@Gh0stwrter 3 ай бұрын
@@jonhoo awesome thank you for the response.
@dbarenholz
@dbarenholz 9 ай бұрын
Another voice in the aether: these videos are awesome. Thanks for making them!
@pathakvivek7865
@pathakvivek7865 9 ай бұрын
Hey, what is this theme? Can i get it on VSCode?
@yokebabjr3866
@yokebabjr3866 Ай бұрын
We don't need to use `BufReader`/`BufWriter` here because, quite surprisingly, `flate2` `std::io::Write` implementations already use a buffer
@leob554
@leob554 3 ай бұрын
where is he running vim on?
@iam.pastel
@iam.pastel 8 ай бұрын
can you share your vim config?
@f3arbhy
@f3arbhy 9 ай бұрын
Great content! Couldn't help but notice that you have your browser search bar on the bottom - can't say i have ever seen that 😅
@mpete0273
@mpete0273 9 ай бұрын
What colorscheme is that? Love it.
@jonhoo
@jonhoo 9 ай бұрын
Gruvbox dark hard :)
@SOMEWORKS456
@SOMEWORKS456 9 ай бұрын
What are you using for tab completion in terminal ?
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
I assume it's at least close to the default fish config, which is pretty nice.
@antifa_communist
@antifa_communist 8 ай бұрын
Could you maybe try to implement the basics of Vim/Neovim in Rust?
@georgiossmyridis5088
@georgiossmyridis5088 6 ай бұрын
What does he mean "this allocates"?
@fabioc9142
@fabioc9142 9 ай бұрын
Please do a decrusting rayon
@jimmylarsson5425
@jimmylarsson5425 9 ай бұрын
What is the inline hints for function arguments called prepended with a panda and the defeninition above?, for example at kzbin.info/www/bejne/q2G5oKerfN93ldk
@jonhoo
@jonhoo 9 ай бұрын
You know, I honestly couldn't tell you 😅 I think it shows the current argument type, but no idea what has enabled it!
@jonhoo
@jonhoo 9 ай бұрын
Ah, looks like it's github.com/ray-x/lsp_signature.nvim specifically the "hint prefix"!
@jimmylarsson5425
@jimmylarsson5425 9 ай бұрын
@@jonhoohuge thanks!! also thanks for all the videos, filling the void for us above beginner level but not professional rust users :D
@Dygear
@Dygear 9 ай бұрын
3:31:07 - 3:31:15 --- Clip it. Meme it.
@MrEnsiferum77
@MrEnsiferum77 9 ай бұрын
Just fix Git, with this alternate version, on the way...
@8ack2Lobby
@8ack2Lobby 9 ай бұрын
dude you are amazing! 💝
@thehady1
@thehady1 9 ай бұрын
I'll also wait one day with zig
@AnubhavAndReena
@AnubhavAndReena 9 ай бұрын
Awesome
@Dygear
@Dygear 9 ай бұрын
God I hope Code Crafters adds a dark mode. Getting smacked in the face with white backgrounds when swapping between the editor and the browser is giving me the squints.
@Dygear
@Dygear 9 ай бұрын
Also, never realized that std::fs::create_dir_all was a thing. That's very handy!
@minatonamikaze2637
@minatonamikaze2637 9 ай бұрын
the darkreader extension
@timvw01
@timvw01 9 ай бұрын
Great stuff
@DrOptix
@DrOptix 9 ай бұрын
I stopped to comment when you arrived at the sorting issue. I'll make a guess that the answer is that they first list the elements of a directory, then the directory itself. Now that I commented this I'm looking forward to see if this is the answer to the problem.
@DrOptix
@DrOptix 9 ай бұрын
OK I did not expect them to have that approach. I'm still trying to understand why go to such lengths just to sort stuff
@selvarajs.7494
@selvarajs.7494 9 ай бұрын
Those who are struggling in Windows os let mode = if meta.is_dir() { "40000" } else if meta.is_symlink() { "120000" } else if is_executable(&path) { // use is_executable::is_executable "100755" } else { "100644" };
@chaitanyasharma6270
@chaitanyasharma6270 6 ай бұрын
please do git clone
@AidenPearce-i6d
@AidenPearce-i6d 9 ай бұрын
implement udp next time
@Greemjou23
@Greemjou23 9 ай бұрын
8:40 - actual start of the video thank me later :)
@jonhoo
@jonhoo 9 ай бұрын
The chapter marks already have that time code in there (and other useful ones!) :)
@regisk7
@regisk7 9 ай бұрын
high level, zero cost abstraction and yet we are reading and writing in buffers like cave men... doesn't feel high level at all, other than useless verbose keywords and method calls...
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
You mean passing the output to read calls? The whole point is these are the low level io interfaces used to reduce memory usage and improve throughout, if you want the high level APIs just fs::read(path) and you get all the bytes, or fs::read_to_string(path) for UTF-8; or use Read::bytes() to get an iterator you can use all the goodies there on. It's not like this is any different to how, say, Node does this, either, with the exception that you don't have a resizable buffer type yet (they're adding one for WASM memory), so if you, say, wanted to read to end you need to end up doing all that reallocation and copying yourself, or keeping and array of buffers and concatenating then at the end. Not fun. Can you say what verbose keywords and method calls you're referring to? Do you mean individual names or just that there's generally a lot more used than in other languages? There's definitely an argument that Rust can get too verbose; but in my experience that's tricky to actually compare; for example adding .with_context(|| ...) to each call seems like a pain in the butt until you try to do the equivalent in other languages: most of the time it's a wrapping try .. catch throw of an error, and it's often tricky to get it to give readable output. JS did recently make this much nicer with Error accepting a cause option, which I really appreciate, but it still is missing expression throws and trys.
@damoon_az2465
@damoon_az2465 9 ай бұрын
Thanks!
Solving distributed systems challenges in Rust
3:15:52
Jon Gjengset
Рет қаралды 284 М.
Implementing a Lox interpreter in Rust
7:53:42
Jon Gjengset
Рет қаралды 54 М.
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1,3 МЛН
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 117 М.
Jon Gjengset - Towards Impeccable Rust
55:59
Rust Nation UK
Рет қаралды 32 М.
Decrusting the tokio crate
3:31:48
Jon Gjengset
Рет қаралды 147 М.
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 167 М.
"Type-Driven API Design in Rust" by Will Crichton
40:57
Strange Loop Conference
Рет қаралды 126 М.
Rust's Most Important Containers 📦 10 Useful Patterns
17:11
Code to the Moon
Рет қаралды 131 М.
Let's Create a Compiler (Pt.1)
1:11:03
Pixeled
Рет қаралды 578 М.