fabric8 gitective core

fabric8 gitective core library

License

License

GroupId

GroupId

io.fabric8
ArtifactId

ArtifactId

gitective-core
Last Version

Last Version

0.9.54
Release Date

Release Date

Type

Type

jar
Description

Description

fabric8 gitective core
fabric8 gitective core library
Project URL

Project URL

https://github.com/fabric8io/gitective
Source Code Management

Source Code Management

https://github.com/fabric8io/gitective

Download gitective-core

How to add to project

<!-- https://jarcasting.com/artifacts/io.fabric8/gitective-core/ -->
<dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>gitective-core</artifactId>
    <version>0.9.54</version>
</dependency>
// https://jarcasting.com/artifacts/io.fabric8/gitective-core/
implementation 'io.fabric8:gitective-core:0.9.54'
// https://jarcasting.com/artifacts/io.fabric8/gitective-core/
implementation ("io.fabric8:gitective-core:0.9.54")
'io.fabric8:gitective-core:jar:0.9.54'
<dependency org="io.fabric8" name="gitective-core" rev="0.9.54">
  <artifact name="gitective-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.fabric8', module='gitective-core', version='0.9.54')
)
libraryDependencies += "io.fabric8" % "gitective-core" % "0.9.54"
[io.fabric8/gitective-core "0.9.54"]

Dependencies

compile (1)

Group / Artifact Type Version
org.eclipse.jgit : org.eclipse.jgit jar 5.0.3.201809091024-r

test (1)

Group / Artifact Type Version
junit : junit jar 4.8

Project Modules

There are no modules declared in this project.

gitective - Find the commits you're looking for

gitective is a Java library built on top of JGit that makes investigating Git repositories simpler and easier. Gitective makes it straight-forward to find interesting commits in a Git repository through combining the included filters.

This library is available from Maven Central

<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>gitective-core</artifactId>
  <version>0.9.50</version>
</dependency>

Javadocs are available here.

Details

gitective supports finding commits through registering filters that first select commits and then run matchers against those commits.

The included filters can be used interchangebly for matching and selecting commits. This allows you to collect data on all commits visited as well as the commits that match filters.

Suppose you want to find all the commits that fix bugs to Java source files. But you also want to know the total number of commits that fix bugs so you can track what subset of all the fixes are fixes to Java source files.

You would find this using the following steps:

  1. Create a filter that selects commits that reference a bug in the message.
  2. Create a filter that selects commits that alter a .java file.
  3. Create a filter that counts the number of commits that are selected.
CommitCountFilter bugCommits = new CommitCountFilter();
CommitCountFilter javaBugCommits = new CommitCountFilter();
CommitFinder finder = new CommitFinder("/repos/myrepo/.git");

finder.setFilter(new AndCommitFilter(new BugFilter(), bugCommits));
finder.setFilter(PathFilterUtils.andSuffix(".java"));
finder.setMatcher(javaBugCommits);
finder.find();

System.out.println(javaBugCommits.getCount() + " java bugs fixed");
System.out.println(bugCommits.getCount() + " total bugs fixed");

Why would you use gitective?

  • You are new to Git and/or JGit and need to write an application that uses revision history. Gitective aims to be simple enough to not require a deep understanding of Git or JGit in order to construct a filter to locate the commits you are looking for in a Git Repository.

  • You need to write an application that searches for commit information from multiple Git repositories. Gitective supports re-using filters across repositories as well as multiple commit searches of the same repository.

  • You want to generate stats or reports based on the commit activity in Git repositories and are looking to use Java/JGit and want a head-start in writing the code that finds the commits needed.

Commit Examples

Shown below are several examples of using the gitective filters and commit service classes, more examples can be found in the unit tests.

Get the HEAD commit in a repository

Repository repo = new FileRepository("/repos/myrepo/.git");
RevCommit latestCommit = CommitUtils.getHead(repo);
System.out.println("HEAD commit is " + latestCommit.name());

Find the number of commits you authored but weren't the committer of

This case is common when doing peer code review or using a code review system.

PersonIdent person = new PersonIdent("Michael Bluth", "[email protected]");
CommitCountFilter count = new CommitCountFilter();
AndCommitFilter filters = new AndCommitFilter();

filters.add(new AuthorFilter(person));
filters.add(new CommitterFilter(person).negate());
filters.add(count);

CommitFinder finder = new CommitFinder("/repos/myrepo/.git");
finder.setFilter(filters).find();
System.out.println(count.getCount());

Find everyone who has authored commits that were 10-way merges

This example may seem uncommon but it will return 6 different users when run against the linux kernel repository.

AuthorSetFilter authors = new AuthorSetFilter();
AndCommitFilter filters = new AndCommitFilter();
filters.add(new ParentCountFilter(10), authors);

CommitFinder finder = new CommitFinder("/repos/linux-2.6/.git");
finder.setFilter(filters).find();

for (PersonIdent author : authors.getPersons())
     System.out.println(author);

Find the number of commits that occurred in master since a branch was created

This example assumes two current branches, master and a release1 branch that was created from master some time ago. Both branches have had subsequent commits since the release1 branch was created.

Repository repo = new FileRepository("/repos/productA/.git");
RevCommit base = CommitUtils.getBase(repo, "master", "release1");

CommitCountFilter count = new CommitCountFilter();
CommitFinder finder = new CommitFinder(repo).setFilter(count);

finder.findBetween("master", base);
System.out.println("Commits in master since release1 was branched: " + count.getCount());

count.reset();
finder.findBetween("release1", base);
System.out.println("Commits in release1 since branched from master: " + count.getCount());

What fraction of commits have a Gerrit Change-Id?

This example finds the number of commits in a repository that contain a Gerrit Change-Id entry in the commit message.

CommitCountFilter all = new CommitCountFilter();
CommitCountFilter gerrit = new CommitCountFilter();
AllCommitFilter filters = new AllCommitFilter();
filters.add(new AndCommitFilter(new ChangeIdFilter(), gerrit), all);

CommitFinder finder = new CommitFinder("/repos/egit/.git");
finder.setFilter(filters).find();

System.out.println(MessageFormat.format(
     "{0} out of {1} commits have Gerrit change ids",
     gerrit.getCount(),	all.getCount()));

Get commits in blocks of 100

This example collects commits into a list of a configured size and iteratively processes subsequent commit blocks.

CommitListFilter block = new CommitListFilter();
CommitFilter limit = new CommitLimitFilter(100).setStop(true);
AndCommitFilter filters = new AndCommitFilter(limit, block);
CommitCursorFilter cursor = new CommitCursorFilter(filters);

Repository repo = new FileRepository("/repos/jgit/.git");
CommitFinder finder = new CommitFinder(repo);
finder.setFilter(cursor);

RevCommit commit = CommitUtils.getHead(repo);
while (commit != null) {
     finder.findFrom(commit);

     // block filter now contains a new block of commits

     commit = cursor.getLast();
     cursor.reset();
}

Find commits referencing bugs

This example collects all the commits that have a 'Bug: XXXXXXX' line in the commit message.

CommitListFilter commits = new CommitListFilter();
AndCommitFilter filter = new AndCommitFilter(new BugFilter(), commits);

CommitFinder finder = new CommitFinder("/repos/jgit/.git");
finder.setFilter(filter).find();

Find files modified during a merge

This example visits all the files that were modified as part of a merge.

CommitDiffFilter diffs = new CommitDiffFilter() {

     protected boolean include(RevCommit commit, Collection<DiffEntry> diffs) {
          // Diffs collection contains all files modified during merge
     }

};
AndCommitFilter filter = new AndCommitFilter(new ParentCountFilter(), diff);

CommitFinder finder = new CommitFinder("/repos/jgit/.git");
finder.setFilter(filter).find();

Inspect notes associated with commits

This example visits all Git notes associated with each commit visited.

NoteContentFilter notes = new NoteContentFilter() {

     protected boolean include(RevCommit commit, Note note, String content) {
          // Content string contains text of note associated with commit
     }

};

CommitFinder finder = new CommitFinder("/repos/jgit/.git");
finder.setFilter(notes).find();

Generate commit histogram

This examples prints out how many commits happened each year in August.

AuthorHistogramFilter filter = new AuthorHistogramFilter();
CommitFinder finder = new CommitFinder("/repos/redis/.git");
finder.setFilter(filter).find();

UserCommitActivity[] activity = filter.getHistogram().getUserActivity();
CommitCalendar commits = new CommitCalendar(activity);

for(YearCommitActivity year : commits.getYears())
     System.out.println(year.getMonthCount(Month.AUGUST)
                          + " commits in August, " + year.getYear());

Blob Examples

Get content of file in HEAD commit

Repository repo = new FileRepository("/repos/jgit/.git");
String content = BlobUtils.getHeadContent(repo, "src/Buffer.java");

Diff two files

Repository repo = new FileRepository("/repos/jgit/.git");

ObjectId current = BlobUtils.getId(repo, "master", "Main.java");
ObjectId previous = BlobUtils.getId(repo, "master~1", "Main.java");

Collection<Edit> edit = BlobUtils.diff(repo, previous, current);

Building from source

gitective can be built using Maven. The pom.xml to build the core plug-in is located at the root of the org.gitective.core folder.

cd gitective/org.gitective.core
mvn clean install

Dependencies

JGit 1.0+

License

MIT License

Contributors

io.fabric8

fabric8

open source development platform for kubernetes

Versions

Version
0.9.54
0.9.53
0.9.52
0.9.51
0.9.50
0.9.37
0.9.30
0.9.23
0.9.22
0.9.21
0.9.20
0.9.19
0.9.18
0.9.17
0.9.16
0.9.15
0.9.14
0.9.13
0.9.12
0.9.11
0.9.10