[EGIT PATCH1/2] fix-CommitTimeRevFilter-by-adding-a-Between-filter

From: Mark Struberg <hidden>
Date: 2016-06-15 22:46:57
Subsystem: the rest · Maintainer: Linus Torvalds

From 0a5e2d469972791cdc2e1db00602142980050af8 Mon Sep 17 00:00:00 2001
From: Mark Struberg <redacted>
Date: Mon, 15 Jun 2009 01:25:25 +0200
Subject: [PATCH] fix CommitTimeRevFilter by adding a Between filter subclass

---
 .../jgit/revwalk/filter/CommitTimeRevFilter.java   |   29 ++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
index a3751b8..0aaa78d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
@@ -70,6 +70,18 @@ public static final RevFilter after(final Date ts) {
 		return new After(ts.getTime());
 	}
 
+	/**
+	 * Create a new filter to select commits after or equal a given date/time <code>since</code> 
+	 * and before or equal a given date/time <code>until</code>.
+	 * 
+	 * @param since the point in time to cut on.
+	 * @param until the point in time to cut off.
+	 * @return a new filter to select commits between the given date/times.
+	 */
+	public static final RevFilter between(final Date since, final Date until) {
+		return new Between(since.getTime(), until.getTime());
+	}
+
 	final int when;
 
 	CommitTimeRevFilter(final long ts) {
@@ -117,4 +129,21 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
 			return true;
 		}
 	}
+
+	private static class Between extends CommitTimeRevFilter {
+		private final int until;
+
+		Between(final long since, final long until) {
+			super(since);
+			this.until = (int) (until / 1000); 
+		}
+
+		@Override
+		public boolean include(final RevWalk walker, final RevCommit cmit)
+				throws StopWalkException, MissingObjectException,
+				IncorrectObjectTypeException, IOException {
+			return cmit.getCommitTime() <= until && cmit.getCommitTime() >= when;
+		}
+	}
+
 }
-- 
1.6.0.6



      
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help