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 static org.junit.Assert.fail; 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 @@ public abstract class LocalDiskRepositoryTestCase { 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
- * 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