From ce56c5dcc979ca415ba61cca02856ad8547d1f83 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 12 Jun 2010 15:31:04 +0200 Subject: [PATCH 01/10] Extend DiffFormatter API to simplify styling Refactor and extend the internals so users can override and intervene during formatting, e.g. to colorize output. Change-Id: Ia1cf40cfd4a5ed7dfb6503f8dfc617237bee0659 Signed-off-by: Robin Rosenberg --- .../org/eclipse/jgit/diff/DiffFormatter.java | 102 +++++++++++++++--- 1 file changed, 90 insertions(+), 12 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java index 2d552d40d..c40d3b700 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java @@ -139,15 +139,15 @@ public class DiffFormatter { while (aCur < aEnd || bCur < bEnd) { if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) { - writeLine(out, ' ', a, aCur); + writeContextLine(out, a, aCur, isEndOfLineMissing(a, aCur)); aCur++; bCur++; - } else if (aCur < curEdit.getEndA()) { - writeLine(out, '-', a, aCur++); - + writeRemovedLine(out, a, aCur, isEndOfLineMissing(a, aCur)); + aCur++; } else if (bCur < curEdit.getEndB()) { - writeLine(out, '+', b, bCur++); + writeAddedLine(out, b, bCur, isEndOfLineMissing(b, bCur)); + bCur++; } if (end(curEdit, aCur, bCur) && ++curIdx < edits.size()) @@ -156,12 +156,85 @@ public class DiffFormatter { } } - private void writeHunkHeader(final OutputStream out, int aCur, int aEnd, - int bCur, int bEnd) throws IOException { + /** + * Output a line of diff context + * + * @param out + * OutputStream + * @param text + * RawText for accessing raw data + * @param line + * the line number within text + * @param endOfLineMissing + * true if we should add the GNU end of line missing warning + * @throws IOException + */ + protected void writeContextLine(final OutputStream out, final RawText text, + final int line, boolean endOfLineMissing) throws IOException { + writeLine(out, ' ', text, line, endOfLineMissing); + } + + private boolean isEndOfLineMissing(final RawText text, final int line) { + return line + 1 == text.size() && text.isMissingNewlineAtEnd(); + } + + /** + * Output an added line + * + * @param out + * OutputStream + * @param text + * RawText for accessing raw data + * @param line + * the line number within text + * @param endOfLineMissing + * true if we should add the gnu end of line missing warning + * @throws IOException + */ + protected void writeAddedLine(final OutputStream out, final RawText text, final int line, boolean endOfLineMissing) + throws IOException { + writeLine(out, '+', text, line, endOfLineMissing); + } + + /** + * Output a removed line + * + * @param out + * OutputStream + * @param text + * RawText for accessing raw data + * @param line + * the line number within text + * @param endOfLineMissing + * true if we should add the gnu end of line missing warning + * @throws IOException + */ + protected void writeRemovedLine(final OutputStream out, final RawText text, + final int line, boolean endOfLineMissing) throws IOException { + writeLine(out, '-', text, line, endOfLineMissing); + } + + /** + * Output a hunk header + * + * @param out + * OutputStream + * @param aStartLine + * within first source + * @param aEndLine + * within first source + * @param bStartLine + * within second source + * @param bEndLine + * within second source + * @throws IOException + */ + protected void writeHunkHeader(final OutputStream out, int aStartLine, int aEndLine, + int bStartLine, int bEndLine) throws IOException { out.write('@'); out.write('@'); - writeRange(out, '-', aCur + 1, aEnd - aCur); - writeRange(out, '+', bCur + 1, bEnd - bCur); + writeRange(out, '-', aStartLine + 1, aEndLine - aStartLine); + writeRange(out, '+', bStartLine + 1, bEndLine - bStartLine); out.write(' '); out.write('@'); out.write('@'); @@ -199,12 +272,17 @@ public class DiffFormatter { } private static void writeLine(final OutputStream out, final char prefix, - final RawText text, final int cur) throws IOException { + final RawText text, final int cur, boolean noNewLineIndicator) throws IOException { out.write(prefix); text.writeLine(out, cur); out.write('\n'); - if (cur + 1 == text.size() && text.isMissingNewlineAtEnd()) - out.write(noNewLine); + if (noNewLineIndicator) + writeNoNewLine(out); + } + + private static void writeNoNewLine(final OutputStream out) + throws IOException { + out.write(noNewLine); } private int findCombinedEnd(final List edits, final int i) { From 292fe88c505060808908c7229a5dde78c9783b35 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:12:41 +0200 Subject: [PATCH 02/10] Removed unused repo field in WorkDirCheckout Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/lib/WorkDirCheckout.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkDirCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkDirCheckout.java index ee7820286..cead0f2b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkDirCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkDirCheckout.java @@ -64,8 +64,6 @@ import org.eclipse.jgit.lib.GitIndex.Entry; * Three-way merges are no performed. See {@link #setFailOnConflict(boolean)}. */ public class WorkDirCheckout { - Repository repo; - File root; GitIndex index; @@ -87,7 +85,6 @@ public class WorkDirCheckout { WorkDirCheckout(Repository repo, File workDir, GitIndex oldIndex, GitIndex newIndex) throws IOException { - this.repo = repo; this.root = workDir; this.index = oldIndex; this.merge = repo.mapTree(newIndex.writeTree()); @@ -103,7 +100,6 @@ public class WorkDirCheckout { */ public WorkDirCheckout(Repository repo, File root, GitIndex index, Tree merge) { - this.repo = repo; this.root = root; this.index = index; this.merge = merge; From 3a2a43a1dcc27fd5c40a9b5fcbcd185c0a20769c Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:13:57 +0200 Subject: [PATCH 03/10] Remove unused parent field in PlotLane Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/revplot/PlotCommitList.java | 2 -- org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotLane.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java index 61eed3fa9..55d0206c0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java @@ -139,7 +139,6 @@ public class PlotCommitList extends rObj.addPassingLane(c.lane); } currCommit.lane = c.lane; - currCommit.lane.parent = currCommit; } else { // More than one child, or our child is a merge. // Use a different lane. @@ -154,7 +153,6 @@ public class PlotCommitList extends } currCommit.lane = nextFreeLane(); - currCommit.lane.parent = currCommit; activeLanes.add(currCommit.lane); int remaining = nChildren; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotLane.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotLane.java index 9d08455ce..ff22b6473 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotLane.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotLane.java @@ -49,8 +49,6 @@ package org.eclipse.jgit.revplot; * Commits are strung onto a lane. For many UIs a lane represents a column. */ public class PlotLane { - PlotCommit parent; - int position; /** From 3bf96dd04bc9bcd59765e9f448473868aa493bb7 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:16:32 +0200 Subject: [PATCH 04/10] Cache filemode in GitIndex Apparently this was the intention, but never happened Signed-off-by: Robin Rosenberg --- org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java index d5cab0e4c..5da33fd6b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java @@ -353,7 +353,8 @@ public class GitIndex { if (filemode != null) return filemode.booleanValue(); RepositoryConfig config = db.getConfig(); - return config.getBoolean("core", null, "filemode", true); + filemode = Boolean.valueOf(config.getBoolean("core", null, "filemode", true)); + return filemode.booleanValue(); } /** An index entry */ From 6f4cf8daec4e4450706727fff1084f9c62423d26 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:19:47 +0200 Subject: [PATCH 05/10] Make inner classes static in http code Static classes are preferrable to keep unwanted dependencies away, and they have one less member field. Signed-off-by: Robin Rosenberg --- .../tst/org/eclipse/jgit/http/test/AsIsServiceTest.java | 2 +- .../eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java | 2 +- .../eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java index ea937481d..2650db2fa 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java @@ -112,7 +112,7 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase { service.access(new R("bob", "1.2.3.4"), db); } - private final class R extends HttpServletRequestWrapper { + private static final class R extends HttpServletRequestWrapper { private final String user; private final String host; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java index 5338caaa4..4d05a085c 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java @@ -174,7 +174,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { assertNotNull("have ReceivePack", rp); } - private final class R extends HttpServletRequestWrapper { + private static final class R extends HttpServletRequestWrapper { private final String user; private final String host; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java index 8f57d40af..423361e06 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java @@ -136,7 +136,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { assertSame(db, up.getRepository()); } - private final class R extends HttpServletRequestWrapper { + private static final class R extends HttpServletRequestWrapper { private final String user; private final String host; From f396326e0b6c41b92fefb946b943aa82c603a3a6 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:27:06 +0200 Subject: [PATCH 06/10] Make constant static in RebuildCommitGraph Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index 38df04101..1681dbc96 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -96,7 +96,7 @@ import org.eclipse.jgit.revwalk.RevWalk; *

*/ class RebuildCommitGraph extends TextBuiltin { - private final String REALLY = "--destroy-this-repository"; + private static final String REALLY = "--destroy-this-repository"; @Option(name = REALLY, usage = "usage_approveDestructionOfRepository") boolean really; From e7c9db836bb3b7b33f3e7894c0a3de6f9aeab621 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:28:04 +0200 Subject: [PATCH 07/10] Make sure a Stream is closed upon errors in IpLogGenerator Signed-off-by: Robin Rosenberg --- .../eclipse/jgit/iplog/IpLogGenerator.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java b/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java index 28df8b7f5..f64c32984 100644 --- a/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java +++ b/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java @@ -236,36 +236,40 @@ public class IpLogGenerator { SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); File list = new File(repo.getDirectory(), "gerrit_committers"); BufferedReader br = new BufferedReader(new FileReader(list)); - String line; - - while ((line = br.readLine()) != null) { - String[] field = line.trim().split(" *\\| *"); - String user = field[1]; - String name = field[2]; - String email = field[3]; - Date begin = parseDate(dt, field[4]); - Date end = parseDate(dt, field[5]); - - if (user.startsWith("username:")) - user = user.substring("username:".length()); - - Committer who = committersById.get(user); - if (who == null) { - who = new Committer(user); - int sp = name.indexOf(' '); - if (0 < sp) { - who.setFirstName(name.substring(0, sp).trim()); - who.setLastName(name.substring(sp + 1).trim()); - } else { - who.setFirstName(name); - who.setLastName(null); + try { + String line; + + while ((line = br.readLine()) != null) { + String[] field = line.trim().split(" *\\| *"); + String user = field[1]; + String name = field[2]; + String email = field[3]; + Date begin = parseDate(dt, field[4]); + Date end = parseDate(dt, field[5]); + + if (user.startsWith("username:")) + user = user.substring("username:".length()); + + Committer who = committersById.get(user); + if (who == null) { + who = new Committer(user); + int sp = name.indexOf(' '); + if (0 < sp) { + who.setFirstName(name.substring(0, sp).trim()); + who.setLastName(name.substring(sp + 1).trim()); + } else { + who.setFirstName(name); + who.setLastName(null); + } + committersById.put(who.getID(), who); } - committersById.put(who.getID(), who); - } - who.addEmailAddress(email); - who.addActiveRange(new ActiveRange(begin, end)); - committersByEmail.put(email, who); + who.addEmailAddress(email); + who.addActiveRange(new ActiveRange(begin, end)); + committersByEmail.put(email, who); + } + } finally { + br.close(); } } From 3e8bd245808f68623a06e89025c5cd354b5caf54 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:30:10 +0200 Subject: [PATCH 08/10] Override equals for SwingLane since super class PlotLane defines it Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/awtui/SwingCommitList.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java index 4a1196447..b58547a9e 100644 --- a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java +++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java @@ -83,5 +83,9 @@ class SwingCommitList extends PlotCommitList { static class SwingLane extends PlotLane { Color color; + @Override + public boolean equals(Object o) { + return super.equals(o) && color.equals(((SwingLane)o).color); + } } } From 3a899a3af983fee19fc614445e9a11b72e8ecf3a Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 13 Jun 2010 03:31:52 +0200 Subject: [PATCH 09/10] Prefer static inner classes Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/awtui/CommitGraphPane.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java index effe6e575..13d408f19 100644 --- a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java +++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java @@ -176,7 +176,7 @@ public class CommitGraphPane extends JTable { } } - class NameCellRender extends DefaultTableCellRenderer { + static class NameCellRender extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(final JTable table, @@ -194,7 +194,7 @@ public class CommitGraphPane extends JTable { } } - class DateCellRender extends DefaultTableCellRenderer { + static class DateCellRender extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; private final DateFormat fmt = new SimpleDateFormat( @@ -215,7 +215,7 @@ public class CommitGraphPane extends JTable { } } - class GraphCellRender extends DefaultTableCellRenderer { + static class GraphCellRender extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; private final AWTPlotRenderer renderer = new AWTPlotRenderer(this); From 6d5241110bc22f69287dc285a6793301075bb3dc Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Mon, 14 Jun 2010 23:33:02 +0200 Subject: [PATCH 10/10] git-servlet: Fix comparing uploadFactory with the wrong DISABLED instance Change-Id: I53f71dc0e3c68839da5ff5a2e0f3eeb8340e4793 Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/http/server/GitServlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java index cc4cf6a80..e28e4eeb2 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java @@ -185,7 +185,7 @@ public class GitServlet extends MetaServlet { initialized = true; - if (uploadPackFactory != ReceivePackFactory.DISABLED) { + if (uploadPackFactory != UploadPackFactory.DISABLED) { serve("*/git-upload-pack")// .with(new UploadPackServlet(uploadPackFactory)); }