From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Koeberle Subject: [JGIT PATCH v4 20/24] Formatted Repository class. Date: Fri, 13 Jun 2008 20:35:17 +0200 Message-ID: <1213382121-19786-20-git-send-email-florianskarten@web.de> References: <4852BCCA.4030404@web.de> Cc: Florian Koeberle To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Jun 13 20:38:31 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1K7EAQ-0005zA-Nh for gcvg-git-2@gmane.org; Fri, 13 Jun 2008 20:38:31 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753201AbYFMSgC (ORCPT ); Fri, 13 Jun 2008 14:36:02 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753080AbYFMSgB (ORCPT ); Fri, 13 Jun 2008 14:36:01 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:43439 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752779AbYFMSfe (ORCPT ); Fri, 13 Jun 2008 14:35:34 -0400 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id D3F3AE184E02 for ; Fri, 13 Jun 2008 20:35:33 +0200 (CEST) Received: from [84.150.79.9] (helo=localhost.localdomain) by smtp08.web.de with asmtp (WEB.DE 4.109 #226) id 1K7E7Y-0000eI-02; Fri, 13 Jun 2008 20:35:33 +0200 X-Mailer: git-send-email 1.5.5.1 In-Reply-To: <4852BCCA.4030404@web.de> In-Reply-To: <4852BCCA.4030404@web.de> References: <4852BCCA.4030404@web.de> X-Sender: florianskarten@web.de X-Provags-ID: V01U2FsdGVkX18S2I+2Fn1NjOArBKdnR8G8Se9LzaOSlcpw5lfB P4qgRADD81Jx4u4bKQJp4ALsZqnKpI53tKp7QJeMEg5ezcitbS SJRNwfQD4sGgJae2/sJg== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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; * *
    *
  • GIT_DIR - *
      - *
    • objects/ - objects
    • - *
    • refs/ - tags and heads
    • - *
    • config - configuration
    • - *
    • info/ - more configurations
    • - *
    + *
      + *
    • objects/ - objects
    • + *
    • refs/ - tags and heads
    • + *
    • config - configuration
    • + *
    • info/ - more configurations
    • + *
    *
  • *
* - * 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