Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitWrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Georg Seibt
GitWrapper
Commits
a3e4f1dd
Commit
a3e4f1dd
authored
8 years ago
by
Florian Heck
Browse files
Options
Downloads
Patches
Plain Diff
added getter for commit information
parent
f55c469a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/de/uni_passau/fim/seibt/gitwrapper/repo/Commit.java
+69
-0
69 additions, 0 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Commit.java
with
69 additions
and
0 deletions
src/de/uni_passau/fim/seibt/gitwrapper/repo/Commit.java
+
69
−
0
View file @
a3e4f1dd
...
...
@@ -16,11 +16,19 @@ public class Commit {
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
Commit
.
class
.
getCanonicalName
());
// since there is no porcelain format for this command, this regex is might depend on the git version
private
static
final
Pattern
commitInfoPattern
=
Pattern
.
compile
(
"tree (.{40})\\nparent (.{40})\\nauthor (.*?)<(.*?)> (\\d+) ([+-]\\d{4})\\ncommitter (.*?)<(.*?)> (\\d+) ([+-]\\d{4})\\n.*?\\n(.*)"
);
private
GitWrapper
git
;
private
Repository
repo
;
private
String
id
;
private
String
author
;
private
String
authorMail
;
private
Date
authorTime
;
/**
* Constructs a new {@link Commit} with the given <code>id</code> made in the <code>repo</code>.
*
...
...
@@ -100,6 +108,67 @@ public class Commit {
return
id
;
}
/**
* Returns the author of this commit.
*
* @return the author
*/
public
String
getAuthor
()
{
if
(
author
==
null
)
{
getCommitInfo
();
}
return
author
;
}
/**
* Returns the author mail of this commit.
*
* @return the author mail
*/
public
String
getAuthorMail
()
{
if
(
authorMail
==
null
)
{
getCommitInfo
();
}
return
authorMail
;
}
/**
* Returns the author time of this commit in committer-local time
*
* @return the author time
*/
public
Date
getAuthorTime
()
{
if
(
authorTime
==
null
)
{
getCommitInfo
();
}
return
authorTime
;
}
/**
* Reads the author information (author, author mail, author time) about this commit and saves it in the
* {@link Commit}.
*/
private
void
getCommitInfo
()
{
Optional
<
ExecRes
>
commitInfo
=
git
.
exec
(
repo
.
getDir
(),
"cat-file"
,
"-p"
,
id
);
commitInfo
.
map
(
execRes
->
{
if
(
git
.
failed
(
execRes
))
{
LOG
.
warning
(()
->
String
.
format
(
"Failed to obtain information about commit %s."
,
this
));
return
null
;
}
String
result
=
execRes
.
stdOut
.
trim
();
Matcher
matcher
=
commitInfoPattern
.
matcher
(
result
);
if
(!
matcher
.
find
())
{
LOG
.
warning
(()
->
String
.
format
(
"Unexpected output while getting commit info for %s."
,
this
));
}
else
{
author
=
matcher
.
group
(
3
);
authorMail
=
matcher
.
group
(
4
);
authorTime
=
new
Date
(
Long
.
parseLong
(
matcher
.
group
(
5
)));
}
return
null
;
});
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment