top | item 19540845

Git implemented in Rust

370 points| adamnemecek | 7 years ago |github.com | reply

119 comments

order
[+] akdas|7 years ago|reply
I love to see people reimplementing existing tools on their own, because I find that to be a great way to learn more about those tools. I started on a Git implementation in Rust as well, though I haven't worked on it in a while: https://github.com/avik-das/gitters
[+] giancarlostoro|7 years ago|reply
Are you basing it off anything in particular? Like outside of just going through gits own source code?
[+] jonty|7 years ago|reply
If you're interested in this, you may enjoy "Building Git" by James Coglan - a comprehensive book that takes you through reimplementing git in Ruby.

https://shop.jcoglan.com/building-git/

[+] abhijat|7 years ago|reply
If you have read this book, would you care to comment about its content and quality?

It is something I am interested in buying but I have not been able to find reviews of it.

[+] ernst_klim|7 years ago|reply
Also a git implementation in pure OCaml, used for irmin git-based kv storage:

https://github.com/mirage/ocaml-git

https://github.com/mirage/irmin

[+] empath75|7 years ago|reply
Man I was thinking last week that something like this based on git or pijul would be a better backend for kubernetes than Etcd is.
[+] ioquatix|7 years ago|reply
Here is an implementation of a Ruby based kv store build on top of rugged, which is built on top of libgit2:

https://github.com/ioquatix/relaxo-model

It's so much fun, but not that practical for scalable websites.

[+] hannob|7 years ago|reply
I don't see any info about a license.

Strongly recommend using some standard FOSS license before plenty of people add commits and it gets a big mess clearing up the licensing situation later.

[+] littlestymaar|7 years ago|reply
> Implementing git in rust for fun and education!

Also, not having a license file isn't a messy situation, that means “this project is protected under Berne Convention copyright“: the author is the only one holding every rights on the code and every use that is not explicitly allowed is a copyright infringement (unless it's fair use).

[+] josteink|7 years ago|reply
Easiest way to fix that is often just sending a PR with whatever is the “default” license for that particular eco-system.

For Rust that is (afaik) MIT. Why don’t you go try it? ;)

[+] _bxg1|7 years ago|reply
Rust seems like a good language for git given its performance and memory-safety, no?
[+] aidenn0|7 years ago|reply
Actually any high performance GC'd languages would be fine too because latency is a non-issue for long running git operations (you won't notice if your git clone pauses for 100ms, whereas you will notice if your UI does). Throughput of malloc() and GCd languages tends to be similar when latency isn't a concern.
[+] lelanthran|7 years ago|reply
Just how big is your repo that, other than cloning, git operations induce user-noticable performance problems?
[+] d33|7 years ago|reply
I like the changelog. Looks like a zero-effort way to publish something other people could make use of.
[+] Chris2048|7 years ago|reply
To be honest, I wish there was a movement for something like "literate changelog", where the CL was propely linked with something like a blog post, and specific repo versions. I guess Pull Requests sort of take that role.. But sometimes PR diffs aren't the same as annotated code in a blog post.
[+] chx|7 years ago|reply
No, currently they can't as there is no open source license.
[+] mises|7 years ago|reply
Can somebody tell me what is behind the recent rewrite-all-the-things-in-rust craze? I get it can have some benefits in terms of security, but it seems rewriting so many things in it just for the sake of it is a bit excessive.

I understand some of these are very likely for educational purposes (like this one and others; it's good for getting more familiar with the language), but it still seems to be a bit of a strange trend (especially since people who don't need to learn are doing it, seemingly just because "yay rust").

[+] emef|7 years ago|reply
Rewriting existing software in a new language is one of the best ways to learn a language.

> especially since people who don't need to learn are doing it

Don't need to learn?? There's always something to learn.

[+] adamnemecek|7 years ago|reply
I support RIIR 100%. It’s much easier for me to contribute to Rust projects. It’s not just the language (but that is definitely a part). I don’t need to worry about shit like “how do I build this project” or "my code might run on platforms x and y but I'm not sure about platform z". With c/cpp, the build process can be potentially very complicated. Missing headers, missing binaries. With Rust, I just run “cargo build”.

Furthermore, the resulting code feels just so sturdy. I can also expose it as C and it can be used from the likes of Python.

[+] jchw|7 years ago|reply
I scrolled down for this comment.

Actually there's a lot of great reasons to rewrite everything in every language. Git is an especially good piece of software to implement everywhere because it's relatively stable and it's pretty useful.

As for actual reasons, one good example is so you can keep your dependencies in the language, using the language package manager. For Go nobody even questions that this is worth it; it enables painless cross compiling and completely static, libc-free binaries. For Rust that may not be a thing, but you do at least get the benefits that you could integrate Git functionality without having to hack around in porcelain.

This one here is a learning experience by it's own description, but I would suggest people stop complaining about "rewriting everything" in $LANGUAGE. The opposite complaint is often cited as a reason why to not use the language (that, for example, basic programs haven't already been ported.) If we did build an alternate world with feature parity, unit testing, optimizations, in a memory safe language, I doubt many people would be complaining about the strange trend of rewriting things anymore.

[+] PrototypeNM1|7 years ago|reply
In addition to what has already been said, I think there's a lot of interest in reimplementing command line tools in Rust because there are a lot of useful support libraries for TUI development. Because of the lower barrier of entry (no fussing with build/linker issues to use convenience libraries) you're seeing an increase in people trying things just to try them.
[+] beatgammit|7 years ago|reply
For me, dealing with something written in Rust is less painful than dealing with something with bindings for Rust, and honestly I'd consider rewriting something for that reason. And that's the case for nearly any language.

For example, I rewrote `tar` in JavaScript because I wanted to use it in the browser, and I didn't want to fiddle with trying to compile the existing project to JS. It took me a weekend and it worked pretty well for the project I needed it for. That project has since died (completely redesigned), but the tar stuff still works.

These days I'm getting lazy, so for something like git, I'll often exec out to the CLI app instead of fiddling with bindings, especially if it's not a performance-critical part of my app. However, I'd definitely look for a rewrite first and clean bindings second to use as a lib, especially if the rewrite had a suitable license (anything not copyleft).

[+] ryanolsonx|7 years ago|reply
I started one in PHP (because why not). It's pretty fun!
[+] chris_mc|7 years ago|reply
I would like to see some sources like this that are language agnostic that give you the tools needed to implement your own popular tool. For example, where could I look to find a written description of the way git works from the ground up? Kind of like a "guide to implementing X" type of thing, but without code.
[+] SilasX|7 years ago|reply
What's with all those posts about "X implemented in Rust" today?
[+] johnklos|7 years ago|reply

[deleted]

[+] giancarlostoro|7 years ago|reply
Rust is pretty darn portable as it is though. It runs on the major platforms. Are you thinking its Assembly or something? Everywhere FireFox is compiled to Rust has to run on, which is a lot of platforms.

Maybe it wont run on your toaster but if you are making git commits through your toaster you got other issues.

[+] ufmace|7 years ago|reply
Eh, why not? Seems like a chicken-and-egg thing. If there's no Rust support for some platform, fewer people will want to write things in it because they won't be able to run them where they want. But the less Rust software there is, the less interest anyone would have in writing build tools for less popular platforms.

Break out of these patterns by writing useful software in it that people would like to have on less popular platforms, so more people feel motivated to build and maintain build tools for it.

[+] foreahl|7 years ago|reply
Unless you're being sarcastic and I'm just missing it, I think you'r missing the point here.

The author says quite clearly that it's "for fun and education".

[+] profquail|7 years ago|reply
If you really needed to run Rust code on some platform LLVM doesn’t natively support, it does allow you to compile to C. Presumably you could then compile that using whatever C compiler works for your platform.

Although Rust is not as portable as C, going through these hoops would mean that —- modulo codegen bugs —- the generated C code should still be as memory-safe as the original Rust code.

[+] Ygg2|7 years ago|reply
What do you mean by non-portable? Can't run on 32mb RAM?
[+] GoblinSlayer|7 years ago|reply
BTW is there opensource implementation of C on Windows?
[+] OpenBSD-supreme|7 years ago|reply
>rust this

>rust that

Why re-invent the wheel? Ada is superior. :^)

[+] k0t0n0|7 years ago|reply
awsm I was really interested in how could one go about implementing git like system. nice work OP