Contact Info

sean [at] coreitpro [dot] com gpg key

sc68cal on Libera

Git-Tfs and LibGit2Sharp - Areas for Improvement

Background

Git-Tfs replaced GitSharp with LibGit2Sharp, because the GitSharp project had become stagnant, and memory issues remained unfixed, which forced one the maintainers of Git-Tfs, Matt Burke, to fork the project and carry his own patches (they were eventually upstreamed, but years after the fact).

The work to replace GitSharp with LibGit2Sharp was relatively straight forward. Git-Tfs used classes in-tree to represent Git objects with private members that mapped back to the GitSharp classes returned from GitSharp API calls. Replacing GitSharp was just a matter of finding the correct LibGit2Sharp equivalents and updating the Git-Tfs classes.

The original structure of the project was not updated to fully utilize the APIs that LibGit2Sharp provided at the time, as well as subsequent additions.

Git-Tfs and the Index

Git-Tfs still uses a small amount of shell commands, which requires the use of the git binary. One of the main portions of code that still relies on shell commands, is the indexing code. In order to import changesets from TFS into the Git repository, without affecting the working directroy, Git-Tfs launches the git binary and populates the GIT_INDEX_FILE environment variable, which is honored by Git.

Git-Tfs uses LibGit2Sharp (and GitSharp before LibGit2Sharp) to hash and insert files fetched from TFS, and the hashes of the files are written into the temporary index file.

The Next Steps

By replacing WithTemporaryIndex with calls to LibGit2Sharp’s TreeDefinition API, we can programatically build up trees and create commits with the LibGit2Sharp API.

There are advantages to this change:

  • Better performance, by not creating new processes and executing Git in a subcommand
  • Better maintainability: The code will be more explicit about how commits are created