From: Florian Koeberle Date: Fri, 13 Jun 2008 18:35:17 GMT Subject: [JGIT PATCH v4 20/24] Formatted Repository class. Message-ID: <1213382121-19786-20-git-send-email-florianskarten@web.de> In-Reply-To: <4852BCCA.4030404@web.de> Signed-off-by: Florian Koeberle --- .../src/org/spearce/jgit/lib/Repository.java | 285 +++++++++++--------- 1 files changed, 160 insertions(+), 125 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 5a21c6e..d7c3b13 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -66,16 +66,17 @@ import org.spearce.jgit.util.FS; * * * - * This implementation only handles a subtly undocumented subset of git features. + * This implementation only handles a subtly undocumented subset of git + * features. * */ public class Repository { @@ -93,7 +94,7 @@ public class Repository { /** * Construct a representation of a Git repository. - * + * * @param d * GIT_DIR (the location of the repository metadata). * @throws IOException @@ -106,7 +107,8 @@ public class Repository { objectsDirs = readObjectsDirs(FS.resolve(gitDir, "objects"), new ArrayList()).toArray(new File[0]); } catch (IOException e) { - IOException ex = new IOException("Cannot find all object dirs for " + gitDir); + IOException ex = new IOException("Cannot find all object dirs for " + + gitDir); ex.initCause(e); throw ex; } @@ -130,12 +132,13 @@ public class Repository { scanForPacks(); } - private Collection readObjectsDirs(File objectsDir, Collection ret) throws IOException { + private Collection readObjectsDirs(File objectsDir, + Collection ret) throws IOException { ret.add(objectsDir); final File altFile = FS.resolve(objectsDir, "info/alternates"); if (altFile.exists()) { BufferedReader ar = new BufferedReader(new FileReader(altFile)); - for (String alt=ar.readLine(); alt!=null; alt=ar.readLine()) { + for (String alt = ar.readLine(); alt != null; alt = ar.readLine()) { readObjectsDirs(FS.resolve(objectsDir, alt), ret); } ar.close(); @@ -204,9 +207,9 @@ public class Repository { */ public File toFile(final AnyObjectId objectId) { final String n = objectId.toString(); - String d=n.substring(0, 2); - String f=n.substring(2); - for (int i=0; i - *
  • SHA-1 - a SHA-1
  • - *
  • refs/... - a ref name
  • - *
  • ref^n - nth parent reference
  • - *
  • ref~n - distance via parent reference
  • - *
  • ref@{n} - nth version of ref
  • - *
  • ref^{tree} - tree references by ref
  • - *
  • ref^{commit} - commit references by ref
  • + *
  • SHA-1 - a SHA-1
  • + *
  • refs/... - a ref name
  • + *
  • ref^n - nth parent reference
  • + *
  • ref~n - distance via parent reference
  • + *
  • ref@{n} - nth version of ref
  • + *
  • ref^{tree} - tree references by ref
  • + *
  • ref^{commit} - commit references by ref
  • * * * Not supported is @@ -481,9 +499,11 @@ public class Repository { *
  • abbreviated SHA-1's
  • * * - * @param revstr A git object references expression + * @param revstr + * A git object references expression * @return an ObjectId - * @throws IOException on serious errors + * @throws IOException + * on serious errors */ public ObjectId resolve(final String revstr) throws IOException { char[] rev = revstr.toCharArray(); @@ -493,7 +513,7 @@ public class Repository { switch (rev[i]) { case '^': if (refId == null) { - String refstr = new String(rev,0,i); + String refstr = new String(rev, 0, i); refId = resolveSimple(refstr); if (refId == null) return null; @@ -513,23 +533,24 @@ public class Repository { int j; ref = mapObject(refId, null); if (!(ref instanceof Commit)) - throw new IncorrectObjectTypeException(refId, Constants.TYPE_COMMIT); - for (j=i+1; j= 0) { - refId = ((Commit)ref).getParentIds()[0]; + refId = ((Commit) ref).getParentIds()[0]; ref = mapCommit(refId); --dist; } @@ -619,14 +641,16 @@ public class Repository { case '@': int m; String time = null; - for (m=i+2; m p = new ArrayList(); - for (int i=0; i getAppliedPatches() throws IOException { - Map ret = new HashMap(); + public Map getAppliedPatches() throws IOException { + Map ret = new HashMap(); if (isStGitMode()) { - File patchDir = new File(new File(getDirectory(),"patches"),getBranch()); - BufferedReader apr = new BufferedReader(new FileReader(new File(patchDir,"applied"))); - for (String patchName=apr.readLine(); patchName!=null; patchName=apr.readLine()) { - File topFile = new File(new File(new File(patchDir,"patches"), patchName), "top"); + File patchDir = new File(new File(getDirectory(), "patches"), + getBranch()); + BufferedReader apr = new BufferedReader(new FileReader(new File( + patchDir, "applied"))); + for (String patchName = apr.readLine(); patchName != null; patchName = apr + .readLine()) { + File topFile = new File(new File(new File(patchDir, "patches"), + patchName), "top"); BufferedReader tfr = new BufferedReader(new FileReader(topFile)); String objectId = tfr.readLine(); ObjectId id = ObjectId.fromString(objectId); @@ -881,7 +911,7 @@ public class Repository { } return ret; } - + /** Clean up stale caches */ public void refreshFromDisk() { refs.clearCache(); @@ -904,7 +934,7 @@ public class Repository { static byte[] gitInternalSlash(byte[] bytes) { if (File.separatorChar == '/') return bytes; - for (int i=0; i