1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.revwalk.filter;
13
14 import java.io.IOException;
15 import java.util.Date;
16
17 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
18 import org.eclipse.jgit.errors.MissingObjectException;
19 import org.eclipse.jgit.errors.StopWalkException;
20 import org.eclipse.jgit.revwalk.RevCommit;
21 import org.eclipse.jgit.revwalk.RevWalk;
22
23
24
25
26 public abstract class CommitTimeRevFilter extends RevFilter {
27
28
29
30
31
32
33
34 public static final RevFilter before(Date ts) {
35 return before(ts.getTime());
36 }
37
38
39
40
41
42
43
44
45 public static final RevFilter before(long ts) {
46 return new Before(ts);
47 }
48
49
50
51
52
53
54
55
56 public static final RevFilter after(Date ts) {
57 return after(ts.getTime());
58 }
59
60
61
62
63
64
65
66
67 public static final RevFilter after(long ts) {
68 return new After(ts);
69 }
70
71
72
73
74
75
76
77
78
79 public static final RevFilter between(Date since, Date until) {
80 return between(since.getTime(), until.getTime());
81 }
82
83
84
85
86
87
88
89
90
91 public static final RevFilter between(long since, long until) {
92 return new Between(since, until);
93 }
94
95 final int when;
96
97 CommitTimeRevFilter(long ts) {
98 when = (int) (ts / 1000);
99 }
100
101
102 @Override
103 public RevFilter clone() {
104 return this;
105 }
106
107
108 @Override
109 public boolean requiresCommitBody() {
110 return false;
111 }
112
113 private static class Before extends CommitTimeRevFilter {
114 Before(long ts) {
115 super(ts);
116 }
117
118 @Override
119 public boolean include(RevWalk walker, RevCommit cmit)
120 throws StopWalkException, MissingObjectException,
121 IncorrectObjectTypeException, IOException {
122 return cmit.getCommitTime() <= when;
123 }
124
125 @SuppressWarnings("nls")
126 @Override
127 public String toString() {
128 return super.toString() + "(" + new Date(when * 1000L) + ")";
129 }
130 }
131
132 private static class After extends CommitTimeRevFilter {
133 After(long ts) {
134 super(ts);
135 }
136
137 @Override
138 public boolean include(RevWalk walker, RevCommit cmit)
139 throws StopWalkException, MissingObjectException,
140 IncorrectObjectTypeException, IOException {
141
142
143
144
145 if (cmit.getCommitTime() < when)
146 throw StopWalkException.INSTANCE;
147 return true;
148 }
149
150 @SuppressWarnings("nls")
151 @Override
152 public String toString() {
153 return super.toString() + "(" + new Date(when * 1000L) + ")";
154 }
155 }
156
157 private static class Between extends CommitTimeRevFilter {
158 private final int until;
159
160 Between(long since, long until) {
161 super(since);
162 this.until = (int) (until / 1000);
163 }
164
165 @Override
166 public boolean include(RevWalk walker, RevCommit cmit)
167 throws StopWalkException, MissingObjectException,
168 IncorrectObjectTypeException, IOException {
169 return cmit.getCommitTime() <= until && cmit.getCommitTime() >= when;
170 }
171
172 @SuppressWarnings("nls")
173 @Override
174 public String toString() {
175 return super.toString() + "(" + new Date(when * 1000L) + " - "
176 + new Date(until * 1000L) + ")";
177 }
178
179 }
180
181 }