-jar jgit.sh ... • ./jgit.sh ... • System.getRuntime().exec(“java -jar jgit.sh”) JGit.sh is a shell script with an additional ! Not ‘embedded’ - but useful for memory constrained or GC sensitive applications
use this • No new commands needed • Simple • Useful if in-process memory is limited • Disadvantages • No re-use between runs • Spawns a new JVM each time • Have to parse the results via text stream
the ‘pgm’ jar and can be invoked directly • org.eclipse.jgit.pgm.Main. main(new String[] {...}) • --git-dir /path/to/.git ls-tree HEAD • --git-dir /path/to/.git show HEAD
existing commands • In-process allows for repeated runs • Disadvantages • High level • Have to parse output • Does not allow for optimisations between runs
checked • Does not involve text processing • Can interpret/process results • Can invoke many commands on repo • Disadvantages • Required arguments may be missing • Limited to provided command API • May be more optimal to go deeper in some cases
= FileRepositoryBuilder.create( new File(“...”)) • builder also handles cases like GIT_ environment variables and .git in parent directories • Repository provides object and ref databases
repository content • References point to Commits (and tags,refs) • Commits point to Commits and Trees • Trees point to Trees and Blobs • Think of it as a Commit Iterator (RevWalk) or Directory/File Iterator (TreeWalk)
Can walk commits between ranges • Can walk multiple trees at once (e.g. for diffing) • Disadvantages • Lacks a simple API to ‘get this file’ • Seems confusing at first • Dispose to release resources before re- use ! Walkers are not thread safe, so create separate ones if needed
and get data from repositories • id = repository.newObjectInserter( Constants.OJB_BLOB, “hello world”.getBytes(“UTF-8”)) • repository.newObjectReader().open(id). copyTo(System.out)
any content needed • Use a ‘notes-like’ approach to store additional metadata • Disadvantages • Complex to use • Need to build trees and commits to prevent being garbage collected