From 37a1e4beaa9e31e642be3aef645f060eb96b1b86 Mon Sep 17 00:00:00 2001 From: Chris Price Date: Tue, 7 Jul 2015 13:06:50 +0100 Subject: [PATCH] Move `RepositoryTestCase.indexState` to parent class The test helper method `indexState` in `RepositoryTestCase` is very useful for writing tests, even in cases where we need to do things like create more than one repository for a test and thus we don't want to use the built-in `db` member variable that exists in `RepositoryTestCase`. Since the method is static, we can move it up to the parent class `LocalDiskRepositoryTestCase`, where it can be used by tests that aren't a great fit for inheriting directly from `RepositoryTestCase`. Bug: 436200 Change-Id: I2b6de75c001d2d77ddb607488af246548784a67f Signed-off-by: Chris Price --- .../junit/LocalDiskRepositoryTestCase.java | 109 ++++++++++++++++-- .../jgit/junit/RepositoryTestCase.java | 97 ---------------- 2 files changed, 100 insertions(+), 106 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index b98db7d18..b5348f998 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -50,18 +50,13 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.TimeUnit; +import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.internal.storage.file.FileRepository; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.PersonIdent; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryCache; +import org.eclipse.jgit.lib.*; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.util.FS; @@ -229,6 +224,102 @@ private static void reportDeleteFailure(boolean failOnError, File e) { System.err.println(msg); } + public static final int MOD_TIME = 1; + + public static final int SMUDGE = 2; + + public static final int LENGTH = 4; + + public static final int CONTENT_ID = 8; + + public static final int CONTENT = 16; + + public static final int ASSUME_UNCHANGED = 32; + + /** + * Represent the state of the index in one String. This representation is + * useful when writing tests which do assertions on the state of the index. + * By default information about path, mode, stage (if different from 0) is + * included. A bitmask controls which additional info about + * modificationTimes, smudge state and length is included. + *

+ * The format of the returned string is described with this BNF: + * + *

+	 * result = ( "[" path mode stage? time? smudge? length? sha1? content? "]" )* .
+	 * mode = ", mode:" number .
+	 * stage = ", stage:" number .
+	 * time = ", time:t" timestamp-index .
+	 * smudge = "" | ", smudged" .
+	 * length = ", length:" number .
+	 * sha1 = ", sha1:" hex-sha1 .
+	 * content = ", content:" blob-data .
+	 * 
+ * + * 'stage' is only presented when the stage is different from 0. All + * reported time stamps are mapped to strings like "t0", "t1", ... "tn". The + * smallest reported time-stamp will be called "t0". This allows to write + * assertions against the string although the concrete value of the time + * stamps is unknown. + * + * @param repo + * the repository the index state should be determined for + * + * @param includedOptions + * a bitmask constructed out of the constants {@link #MOD_TIME}, + * {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and + * {@link #CONTENT} controlling which info is present in the + * resulting string. + * @return a string encoding the index state + * @throws IllegalStateException + * @throws IOException + */ + public static String indexState(Repository repo, int includedOptions) + throws IllegalStateException, IOException { + DirCache dc = repo.readDirCache(); + StringBuilder sb = new StringBuilder(); + TreeSet timeStamps = null; + + // iterate once over the dircache just to collect all time stamps + if (0 != (includedOptions & MOD_TIME)) { + timeStamps = new TreeSet(); + for (int i=0; i - * The format of the returned string is described with this BNF: - * - *
-	 * result = ( "[" path mode stage? time? smudge? length? sha1? content? "]" )* .
-	 * mode = ", mode:" number .
-	 * stage = ", stage:" number .
-	 * time = ", time:t" timestamp-index .
-	 * smudge = "" | ", smudged" .
-	 * length = ", length:" number .
-	 * sha1 = ", sha1:" hex-sha1 .
-	 * content = ", content:" blob-data .
-	 * 
- * - * 'stage' is only presented when the stage is different from 0. All - * reported time stamps are mapped to strings like "t0", "t1", ... "tn". The - * smallest reported time-stamp will be called "t0". This allows to write - * assertions against the string although the concrete value of the time - * stamps is unknown. - * - * @param repo - * the repository the index state should be determined for - * - * @param includedOptions - * a bitmask constructed out of the constants {@link #MOD_TIME}, - * {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and - * {@link #CONTENT} controlling which info is present in the - * resulting string. - * @return a string encoding the index state - * @throws IllegalStateException - * @throws IOException - */ - public static String indexState(Repository repo, int includedOptions) - throws IllegalStateException, IOException { - DirCache dc = repo.readDirCache(); - StringBuilder sb = new StringBuilder(); - TreeSet timeStamps = null; - - // iterate once over the dircache just to collect all time stamps - if (0 != (includedOptions & MOD_TIME)) { - timeStamps = new TreeSet(); - for (int i=0; i