Skip to content

Commit

Permalink
#18 Short commits are also authorized
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Aug 29, 2014
1 parent ca740cd commit 50357eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@Component
public class GitCommitSearchExtension extends AbstractExtension implements SearchExtension {

private final Pattern shaPattern = Pattern.compile("[a-f0-9]{40}|[a-f0-9]{7}");

private final GitService gitService;
private final URIBuilder uriBuilder;

Expand All @@ -46,7 +48,7 @@ public GitCommitSearchProvider() {

@Override
public boolean isTokenSearchable(String token) {
return Pattern.matches("[a-f0-9]{40}", token);
return shaPattern.matcher(token).matches();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ public boolean isCommitDefined(String commit) {
public GitCommit getCommitFor(String commit) {
try {
Repository repo = repository.git().getRepository();
return toCommit(
new RevWalk(repo).parseCommit(
repo.resolve(commit + "^0")
)
);
ObjectId objectId = repo.resolve(commit + "^0");
if (objectId != null) {
return toCommit(new RevWalk(repo).parseCommit(objectId));
} else {
return null;
}
} catch (IOException e) {
return null;
}
Expand Down

0 comments on commit 50357eb

Please sign in to comment.