1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.revwalk.filter;
12
13 import java.util.regex.Pattern;
14
15 import org.eclipse.jgit.internal.JGitText;
16 import org.eclipse.jgit.revwalk.RevCommit;
17 import org.eclipse.jgit.util.RawCharSequence;
18 import org.eclipse.jgit.util.RawParseUtils;
19
20
21
22
23 public class CommitterRevFilter {
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public static RevFilter create(String pattern) {
40 if (pattern.length() == 0)
41 throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
42 if (SubStringRevFilter.safe(pattern))
43 return new SubStringSearch(pattern);
44 return new PatternSearch(pattern);
45 }
46
47 private CommitterRevFilter() {
48
49 }
50
51 static RawCharSequence textFor(RevCommit cmit) {
52 final byte[] raw = cmit.getRawBuffer();
53 final int b = RawParseUtils.committer(raw, 0);
54 if (b < 0)
55 return RawCharSequence.EMPTY;
56 final int e = RawParseUtils.nextLF(raw, b, '>');
57 return new RawCharSequence(raw, b, e);
58 }
59
60 private static class PatternSearch extends PatternMatchRevFilter {
61 PatternSearch(String patternText) {
62 super(patternText, true, true, Pattern.CASE_INSENSITIVE);
63 }
64
65 @Override
66 protected CharSequence text(RevCommit cmit) {
67 return textFor(cmit);
68 }
69
70 @Override
71 public RevFilter clone() {
72 return new PatternSearch(pattern());
73 }
74 }
75
76 private static class SubStringSearch extends SubStringRevFilter {
77 SubStringSearch(String patternText) {
78 super(patternText);
79 }
80
81 @Override
82 protected RawCharSequence text(RevCommit cmit) {
83 return textFor(cmit);
84 }
85 }
86 }