SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Embedding JGit
Alex Blewitt
@alblue
Level Zero
• JGit is a command line-program
• java -jar jgit.sh ...
JGit.sh is a shell script
./jgit.sh ...
•
with an additional
• System.getRuntime().exec(“java -jar jgit.sh”)
!

Not ‘embedded’ - but useful for memory
constrained or GC sensitive applications
Level Zero
•

Advantages

•

Disadvantages

•

You already know
how to use this

•

No re-use between
runs

•

No new commands
needed

•

Spawns a new JVM
each time

•
•

Simple

•

Have to parse the
results via text stream

Useful if in-process
memory is limited
Level One
• The jgit command line processor is in 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
Level One
•
•
•
•
•
•
•
•
•
•
•
•
•
•

add
archive
blame
branch
checkout
clone
commit
config
daemon
diff
diff-tree
fetch
gc
glog

•
•
•
•
•
•
•
•
•
•
•
•
•
•

init
log
ls-remote
ls-tree
merge
push
reflog
reset
rev-list
rev-parse
rm
show
show-ref
status
Level One
•

Advantages

•
•
•

Easy to remember
Uses existing
commands
In-process allows for
repeated runs

•

Disadvantages

•
•
•

High level
Have to parse output
Does not allow for
optimisations
between runs
Level Two
• Create/use Git and built-in porcelain
commands

• Git git = org.eclipse.jgit.api.Git.

open(new File(“/path/to/.git”))

• git.clean()
• git.log()
• git.lsRemote()
Level Two
• Commands use builder pattern
• git.clean().setCleanDirectories(true).
setIgnore(true).call()

• git.lsRemote().setRemote().setTags(true).
setHeads(true).call()

i

Builder pattern allows for new
‘arguments’ to be added over time
Level Two
•

Advantages

•
•

Allows commands to
be compile-time
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
Level Three
• Work directly with the repository
• repository = FileRepositoryBuilder.create(
new File(“...”))

• builder also handles cases like GIT_

environment variables and .git in parent
directories

• Repository provides object and ref
databases
Level Three
• repository.getTags()
• repository.getAllRefs()
• repository.getBranch() (current branch)
• repository.getRef(...)
• HEAD = repository.getRef(“HEAD”)
• repository.open(HEAD.getObjectId()).
copyTo(System.out)
Level Three
•

Advantages

•

Disadvantages

•

Can use caches like
RepositoryCache

•

Limited direct API on
repository

•

Can work with/
update references
directly

•

Have to work with
lower level APIs
Level Four
• Repositories are processed by walkers
• Git 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)
Level Four
RevWalk rw = new RevWalk(repository);
HEAD = repository.resolve(“HEAD”)
rw.markStart(rw.parseCommit(HEAD))
Iterator<RevCommit> it = rw.iterator()
while(it.hasNext())
RevCommit commit = it.next()
System.out.println(
commit.abbreivate(6) .name() + “ ” +
commit.getShortMessage())
Level Four
TreeWalk tw = new TreeWalk(repository);
tree = repository.resolve(“HEAD^{tree}”)
tw.addTree(tree) // tree ‘0’
tw.setRecursive(true)
tw.setFilter(PathFilter.create(“some/file”))
while(tw.next())
id = tw.getObjectId(0)
repository.open(id).copyTo(System.out)
Level Four
•

Advantages

•

Disadvantages

•

Can construct
complex filters

•

Lacks a simple API to
‘get this file’

•

Can walk commits
between ranges

•

Seems confusing at
first

•

Can walk multiple
trees at once (e.g. for
diffing)

•

Dispose to release
resources before reuse

!

Walkers are not thread safe, so create
separate ones if needed
Level Five
• ObjectInserter and ObjectReader are used
to put and get data from repositories

• id = repository.newObjectInserter(
Constants.OJB_BLOB,
“hello world”.getBytes(“UTF-8”))

• repository.newObjectReader().open(id).
copyTo(System.out)
Level Five
•

Advantages

•
•

Ultimate flexibility

•

Use a ‘notes-like’
approach to store
additional metadata

Can store any
content needed

•

Disadvantages

•
•

Complex to use
Need to build trees
and commits to
prevent being garbage
collected
Levels of Embedding
0. System.exec(“java -jar jgit.sh ...”)
1. Main.main([]“--git-dir”, “/path/.git”, “...”)
2. Git.open(new File(“.../.git”)).clean().call()
3. FileRepositoryBuilder.create(...).getRef()
4. new TreeWalk/RevWalk(repository)
5. repository.newObjectInserter/Reader
Thankyou
Alex Blewitt
@alblue

Winners of Eclipse 4 Plug-in development
Lorenzo Bettini

Vincenzo Caselli

@lorenzo_bettini

@vcaselli

Contenu connexe

Tendances

PharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus DenkerPharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus DenkerPharo
 
Infinum Android Talks #02 - How to write an annotation processor in Android
Infinum Android Talks #02 - How to write an annotation processor in AndroidInfinum Android Talks #02 - How to write an annotation processor in Android
Infinum Android Talks #02 - How to write an annotation processor in AndroidInfinum
 
JavaScript unit testing with Jasmine
JavaScript unit testing with JasmineJavaScript unit testing with Jasmine
JavaScript unit testing with JasmineYuval Dagai
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective SystemMarcus Denker
 
Harmony first step
Harmony first stepHarmony first step
Harmony first steptwizol
 
Infinum Android Talks #02 - ActiveAndroid
Infinum Android Talks #02 - ActiveAndroidInfinum Android Talks #02 - ActiveAndroid
Infinum Android Talks #02 - ActiveAndroidInfinum
 
AEM Meetup Sydney - Content Migration with CRX2Oak
AEM Meetup Sydney - Content Migration with CRX2OakAEM Meetup Sydney - Content Migration with CRX2Oak
AEM Meetup Sydney - Content Migration with CRX2OakMichael Henderson
 
CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5neilbowers
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5Marcus Denker
 
ONOS System Test - ONS2016
ONOS System Test - ONS2016ONOS System Test - ONS2016
ONOS System Test - ONS2016Suibin Zhang
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Ryan Cuprak
 
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)Robbie Averill
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command linefedefortin
 
Engage 2014 OpenNTF Domino API Slides
Engage 2014 OpenNTF Domino API SlidesEngage 2014 OpenNTF Domino API Slides
Engage 2014 OpenNTF Domino API SlidesPaul Withers
 
REST::Neo4p - Talk @ DC Perl Mongers
REST::Neo4p - Talk @ DC Perl MongersREST::Neo4p - Talk @ DC Perl Mongers
REST::Neo4p - Talk @ DC Perl MongersMark Jensen
 
Neo4p dcbpw-2015
Neo4p dcbpw-2015Neo4p dcbpw-2015
Neo4p dcbpw-2015Mark Jensen
 
Reviewing CPAN modules
Reviewing CPAN modulesReviewing CPAN modules
Reviewing CPAN modulesneilbowers
 
Introduction to Drupal 7 - Updating core, themes and modules. applying patches
Introduction to Drupal 7 - Updating core, themes and modules. applying patchesIntroduction to Drupal 7 - Updating core, themes and modules. applying patches
Introduction to Drupal 7 - Updating core, themes and modules. applying patchesKalin Chernev
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 

Tendances (20)

PharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus DenkerPharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus Denker
 
Infinum Android Talks #02 - How to write an annotation processor in Android
Infinum Android Talks #02 - How to write an annotation processor in AndroidInfinum Android Talks #02 - How to write an annotation processor in Android
Infinum Android Talks #02 - How to write an annotation processor in Android
 
JavaScript unit testing with Jasmine
JavaScript unit testing with JasmineJavaScript unit testing with Jasmine
JavaScript unit testing with Jasmine
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 
Harmony first step
Harmony first stepHarmony first step
Harmony first step
 
Infinum Android Talks #02 - ActiveAndroid
Infinum Android Talks #02 - ActiveAndroidInfinum Android Talks #02 - ActiveAndroid
Infinum Android Talks #02 - ActiveAndroid
 
AEM Meetup Sydney - Content Migration with CRX2Oak
AEM Meetup Sydney - Content Migration with CRX2OakAEM Meetup Sydney - Content Migration with CRX2Oak
AEM Meetup Sydney - Content Migration with CRX2Oak
 
CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
ONOS System Test - ONS2016
ONOS System Test - ONS2016ONOS System Test - ONS2016
ONOS System Test - ONS2016
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)
Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command line
 
Engage 2014 OpenNTF Domino API Slides
Engage 2014 OpenNTF Domino API SlidesEngage 2014 OpenNTF Domino API Slides
Engage 2014 OpenNTF Domino API Slides
 
REST::Neo4p - Talk @ DC Perl Mongers
REST::Neo4p - Talk @ DC Perl MongersREST::Neo4p - Talk @ DC Perl Mongers
REST::Neo4p - Talk @ DC Perl Mongers
 
Neo4p dcbpw-2015
Neo4p dcbpw-2015Neo4p dcbpw-2015
Neo4p dcbpw-2015
 
Reviewing CPAN modules
Reviewing CPAN modulesReviewing CPAN modules
Reviewing CPAN modules
 
Introduction to Drupal 7 - Updating core, themes and modules. applying patches
Introduction to Drupal 7 - Updating core, themes and modules. applying patchesIntroduction to Drupal 7 - Updating core, themes and modules. applying patches
Introduction to Drupal 7 - Updating core, themes and modules. applying patches
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 

Similaire à Embedding JGit

Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularityelliando dias
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentationManav Prasad
 
2017 jenkins world
2017 jenkins world2017 jenkins world
2017 jenkins worldBrent Laster
 
Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your codeElizabeth Smith
 
White and Black Magic on the JVM
White and Black Magic on the JVMWhite and Black Magic on the JVM
White and Black Magic on the JVMIvaylo Pashov
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Lecture05.pptx
Lecture05.pptxLecture05.pptx
Lecture05.pptxMrVMNair
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan Krylov
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesBrett Meyer
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITPouriaQashqai1
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.Luigi Viggiano
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 

Similaire à Embedding JGit (20)

Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularity
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
 
2017 jenkins world
2017 jenkins world2017 jenkins world
2017 jenkins world
 
Git uptospeed
Git uptospeedGit uptospeed
Git uptospeed
 
Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your code
 
White and Black Magic on the JVM
White and Black Magic on the JVMWhite and Black Magic on the JVM
White and Black Magic on the JVM
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Lecture05.pptx
Lecture05.pptxLecture05.pptx
Lecture05.pptx
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance Techniques
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GIT
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 

Dernier

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Embedding JGit

  • 2. Level Zero • JGit is a command line-program • java -jar jgit.sh ... JGit.sh is a shell script ./jgit.sh ... • with an additional • System.getRuntime().exec(“java -jar jgit.sh”) ! Not ‘embedded’ - but useful for memory constrained or GC sensitive applications
  • 3. Level Zero • Advantages • Disadvantages • You already know how to use this • No re-use between runs • No new commands needed • Spawns a new JVM each time • • Simple • Have to parse the results via text stream Useful if in-process memory is limited
  • 4. Level One • The jgit command line processor is in 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
  • 6. Level One • Advantages • • • Easy to remember Uses existing commands In-process allows for repeated runs • Disadvantages • • • High level Have to parse output Does not allow for optimisations between runs
  • 7. Level Two • Create/use Git and built-in porcelain commands • Git git = org.eclipse.jgit.api.Git. open(new File(“/path/to/.git”)) • git.clean() • git.log() • git.lsRemote()
  • 8. Level Two • Commands use builder pattern • git.clean().setCleanDirectories(true). setIgnore(true).call() • git.lsRemote().setRemote().setTags(true). setHeads(true).call() i Builder pattern allows for new ‘arguments’ to be added over time
  • 9. Level Two • Advantages • • Allows commands to be compile-time 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
  • 10. Level Three • Work directly with the repository • repository = FileRepositoryBuilder.create( new File(“...”)) • builder also handles cases like GIT_ environment variables and .git in parent directories • Repository provides object and ref databases
  • 11. Level Three • repository.getTags() • repository.getAllRefs() • repository.getBranch() (current branch) • repository.getRef(...) • HEAD = repository.getRef(“HEAD”) • repository.open(HEAD.getObjectId()). copyTo(System.out)
  • 12. Level Three • Advantages • Disadvantages • Can use caches like RepositoryCache • Limited direct API on repository • Can work with/ update references directly • Have to work with lower level APIs
  • 13. Level Four • Repositories are processed by walkers • Git 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)
  • 14. Level Four RevWalk rw = new RevWalk(repository); HEAD = repository.resolve(“HEAD”) rw.markStart(rw.parseCommit(HEAD)) Iterator<RevCommit> it = rw.iterator() while(it.hasNext()) RevCommit commit = it.next() System.out.println( commit.abbreivate(6) .name() + “ ” + commit.getShortMessage())
  • 15. Level Four TreeWalk tw = new TreeWalk(repository); tree = repository.resolve(“HEAD^{tree}”) tw.addTree(tree) // tree ‘0’ tw.setRecursive(true) tw.setFilter(PathFilter.create(“some/file”)) while(tw.next()) id = tw.getObjectId(0) repository.open(id).copyTo(System.out)
  • 16. Level Four • Advantages • Disadvantages • Can construct complex filters • Lacks a simple API to ‘get this file’ • Can walk commits between ranges • Seems confusing at first • Can walk multiple trees at once (e.g. for diffing) • Dispose to release resources before reuse ! Walkers are not thread safe, so create separate ones if needed
  • 17. Level Five • ObjectInserter and ObjectReader are used to put and get data from repositories • id = repository.newObjectInserter( Constants.OJB_BLOB, “hello world”.getBytes(“UTF-8”)) • repository.newObjectReader().open(id). copyTo(System.out)
  • 18. Level Five • Advantages • • Ultimate flexibility • Use a ‘notes-like’ approach to store additional metadata Can store any content needed • Disadvantages • • Complex to use Need to build trees and commits to prevent being garbage collected
  • 19. Levels of Embedding 0. System.exec(“java -jar jgit.sh ...”) 1. Main.main([]“--git-dir”, “/path/.git”, “...”) 2. Git.open(new File(“.../.git”)).clean().call() 3. FileRepositoryBuilder.create(...).getRef() 4. new TreeWalk/RevWalk(repository) 5. repository.newObjectInserter/Reader
  • 20. Thankyou Alex Blewitt @alblue Winners of Eclipse 4 Plug-in development Lorenzo Bettini Vincenzo Caselli @lorenzo_bettini @vcaselli