One of the problems I faced during my recent work on Pumpkin was to check, whether it has to pull a new version of a repository. Using only git commands it's a nice and easy task, from C# code perspective it requires a bit more gymnastics.
Currently Pumpkin uses libgit2sharp library to communicate with each git repository so I was constrained to use its API. The first thing I thought about was to use git status command:
using (var repo = new Repository("foo/bar"))
{
foreach (var item in repo.RetrieveStatus())
{
}
}
but though it gives a perfect info about status of a local repository, it doesn't touch remote. Dead end.
Another idea was to use git diff because of plenty of different overloads, which seemed to be feasible to get desired result:
using (var repo = new Repository("foo/bar"))
{
foreach (TreeEntryChanges c in repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.Index))
{
}
}
but from the performance point of view I decided, that preparing a diff and analyzing it, is not the best option, if I can find a better one.
The easiest and the best option seemed to compare SHAs of head commits from the local and the remote. It was easier than I thought:
using (var repo = new Repository("foo/bar"))
{
var current = repo.Head.Tip.Sha;
var remote = repo.Branches["origin/branch"].Tip.Sha;
}
With such approach I can operate on the very basic info of a repository, without a need to call additional git command.
For the last few months I've been trying to create a map of all areas in software development, which I'd like to know better. Having so many talented people around you doesn't help - you'd like to learn some low-level stuff, memory management, software theory and many, many more topics, which are extremely interesting. Getting all that knowledge only "in theory" seems impractical and tiresome - that's why I decided to start a new OSS project, which will serve as my "testing ground".
Pumpkin is a .NET build server, which is designed to be as lightweight and extensible as possible. Why did I decide to go with so complicated topic? My reasoning was pretty simple:
- building such thing forces me to use various different technologies, approaches and techniques
- it touches different aspects of building an application - multithreading, concurrency, different environments
- it encourages me to read code of libraries I use, to make sure I fully understand what they do under the hood
- I can try out even the craziest ideas I think about
Will it work? I don't know. What I know, is that doing such thing is the essence of software development - each and every problem you face will make you a better professional. You may disagree but this is, what I believe is the best part of it.