|
Lines 14-19
import java.io.File;
Link Here
|
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import java.net.URI; |
15 |
import java.net.URI; |
| 16 |
import java.net.URISyntaxException; |
16 |
import java.net.URISyntaxException; |
|
|
17 |
import java.security.MessageDigest; |
| 18 |
import java.security.NoSuchAlgorithmException; |
| 17 |
import java.util.*; |
19 |
import java.util.*; |
| 18 |
import java.util.Map.Entry; |
20 |
import java.util.Map.Entry; |
| 19 |
import javax.servlet.ServletException; |
21 |
import javax.servlet.ServletException; |
|
Lines 261-270
public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
Link Here
|
| 261 |
commit.put(ProtocolConstants.KEY_CONTENT_LOCATION, createCommitLocation(baseLocation, revCommit.getName(), "parts=body")); //$NON-NLS-1$ |
263 |
commit.put(ProtocolConstants.KEY_CONTENT_LOCATION, createCommitLocation(baseLocation, revCommit.getName(), "parts=body")); //$NON-NLS-1$ |
| 262 |
commit.put(GitConstants.KEY_DIFF, createDiffLocation(baseLocation, revCommit.getName(), null, null, isRoot)); |
264 |
commit.put(GitConstants.KEY_DIFF, createDiffLocation(baseLocation, revCommit.getName(), null, null, isRoot)); |
| 263 |
commit.put(ProtocolConstants.KEY_NAME, revCommit.getName()); |
265 |
commit.put(ProtocolConstants.KEY_NAME, revCommit.getName()); |
| 264 |
commit.put(GitConstants.KEY_AUTHOR_NAME, revCommit.getAuthorIdent().getName()); |
266 |
PersonIdent author = revCommit.getAuthorIdent(); |
| 265 |
commit.put(GitConstants.KEY_AUTHOR_EMAIL, revCommit.getAuthorIdent().getEmailAddress()); |
267 |
commit.put(GitConstants.KEY_AUTHOR_NAME, author.getName()); |
| 266 |
commit.put(GitConstants.KEY_COMMITTER_NAME, revCommit.getCommitterIdent().getName()); |
268 |
commit.put(GitConstants.KEY_AUTHOR_EMAIL, author.getEmailAddress()); |
| 267 |
commit.put(GitConstants.KEY_COMMITTER_EMAIL, revCommit.getCommitterIdent().getEmailAddress()); |
269 |
String authorImage = getImageLink(author.getEmailAddress()); |
|
|
270 |
if (authorImage != null) |
| 271 |
commit.put("AuthorImage", authorImage); |
| 272 |
PersonIdent committer = revCommit.getCommitterIdent(); |
| 273 |
commit.put(GitConstants.KEY_COMMITTER_NAME, committer.getName()); |
| 274 |
commit.put(GitConstants.KEY_COMMITTER_EMAIL, committer.getEmailAddress()); |
| 268 |
commit.put(GitConstants.KEY_COMMIT_TIME, ((long) revCommit.getCommitTime()) * 1000 /* time in milliseconds */); |
275 |
commit.put(GitConstants.KEY_COMMIT_TIME, ((long) revCommit.getCommitTime()) * 1000 /* time in milliseconds */); |
| 269 |
commit.put(GitConstants.KEY_COMMIT_MESSAGE, revCommit.getFullMessage()); |
276 |
commit.put(GitConstants.KEY_COMMIT_MESSAGE, revCommit.getFullMessage()); |
| 270 |
commit.put(ProtocolConstants.KEY_CHILDREN, toJSON(getTagsForCommit(db, revCommit))); |
277 |
commit.put(ProtocolConstants.KEY_CHILDREN, toJSON(getTagsForCommit(db, revCommit))); |
|
Lines 307-312
public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
Link Here
|
| 307 |
return commit; |
314 |
return commit; |
| 308 |
} |
315 |
} |
| 309 |
|
316 |
|
|
|
317 |
/** |
| 318 |
* Returns the URL of an image corresponding to the given email address. |
| 319 |
* Currently this is implemented using gravatar. |
| 320 |
*/ |
| 321 |
private String getImageLink(String emailAddress) { |
| 322 |
MessageDigest digest; |
| 323 |
try { |
| 324 |
digest = MessageDigest.getInstance("MD5"); //$NON-NLS-1$ |
| 325 |
} catch (NoSuchAlgorithmException e) { |
| 326 |
//without MD5 we can't compute gravatar hashes |
| 327 |
return null; |
| 328 |
} |
| 329 |
digest.update(emailAddress.trim().toLowerCase().getBytes()); |
| 330 |
byte[] digestValue = digest.digest(); |
| 331 |
StringBuffer result = new StringBuffer("http://www.gravatar.com/avatar/"); //$NON-NLS-1$ |
| 332 |
for (int i = 0; i < digestValue.length; i++) { |
| 333 |
String current = Integer.toHexString((digestValue[i] & 0xFF)); |
| 334 |
//left pad with zero |
| 335 |
if (current.length() == 1) |
| 336 |
result.append('0'); |
| 337 |
result.append(current); |
| 338 |
} |
| 339 |
//Default to "mystery man" icon if the user has no gravatar |
| 340 |
result.append("?d=mm"); //$NON-NLS-1$ |
| 341 |
return result.toString(); |
| 342 |
} |
| 343 |
|
| 310 |
private JSONArray toJSON(Map<String, Ref> revTags) throws JSONException { |
344 |
private JSONArray toJSON(Map<String, Ref> revTags) throws JSONException { |
| 311 |
JSONArray children = new JSONArray(); |
345 |
JSONArray children = new JSONArray(); |
| 312 |
for (Entry<String, Ref> revTag : revTags.entrySet()) { |
346 |
for (Entry<String, Ref> revTag : revTags.entrySet()) { |