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

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Dernier (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

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