From: Robin Rosenberg <robin.rosenberg@gmail.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH] Improve error handling for writing FETCH_HEAD
Date: Tue, 11 Aug 2009 07:48:06 +0200 [thread overview]
Message-ID: <1249969686-11232-1-git-send-email-robin.rosenberg@dewire.com> (raw)
PrintWriter hides error handling from us and we want it. We
also want \n as line terminator so Writer is just as simple. Try-
finally blocks added for cleanup on failure.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../spearce/jgit/transport/FetchHeadRecord.java | 25 +++++++++---------
.../org/spearce/jgit/transport/FetchProcess.java | 27 ++++++++++---------
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/FetchHeadRecord.java b/org.spearce.jgit/src/org/spearce/jgit/transport/FetchHeadRecord.java
index d957028..62ec38a 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/FetchHeadRecord.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/FetchHeadRecord.java
@@ -41,7 +41,8 @@
import static org.spearce.jgit.lib.Constants.R_REMOTES;
import static org.spearce.jgit.lib.Constants.R_TAGS;
-import java.io.PrintWriter;
+import java.io.IOException;
+import java.io.Writer;
import org.spearce.jgit.lib.ObjectId;
@@ -54,7 +55,7 @@
URIish sourceURI;
- void write(final PrintWriter pw) {
+ void write(final Writer pw) throws IOException {
final String type;
final String name;
if (sourceName.startsWith(R_HEADS)) {
@@ -71,16 +72,16 @@ void write(final PrintWriter pw) {
name = sourceName;
}
- pw.print(newValue.name());
- pw.print('\t');
+ pw.write(newValue.name());
+ pw.write('\t');
if (notForMerge)
- pw.print("not-for-merge");
- pw.print('\t');
- pw.print(type);
- pw.print(" '");
- pw.print(name);
- pw.print("' of ");
- pw.print(sourceURI);
- pw.println();
+ pw.write("not-for-merge");
+ pw.write('\t');
+ pw.write(type);
+ pw.write(" '");
+ pw.write(name);
+ pw.write("' of ");
+ pw.write(sourceURI.toString());
+ pw.write("\n");
}
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/FetchProcess.java b/org.spearce.jgit/src/org/spearce/jgit/transport/FetchProcess.java
index 08d7d65..c899c8c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/FetchProcess.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/FetchProcess.java
@@ -41,7 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -264,20 +264,21 @@ private void removeFetchHeadRecord(final ObjectId want) {
private void updateFETCH_HEAD(final FetchResult result) throws IOException {
final LockFile lock = new LockFile(new File(transport.local
.getDirectory(), "FETCH_HEAD"));
- if (lock.lock()) {
- final PrintWriter pw = new PrintWriter(new OutputStreamWriter(lock
- .getOutputStream())) {
- @Override
- public void println() {
- print('\n');
+ try {
+ if (lock.lock()) {
+ final Writer w = new OutputStreamWriter(lock.getOutputStream());
+ try {
+ for (final FetchHeadRecord h : fetchHeadUpdates) {
+ h.write(w);
+ result.add(h);
+ }
+ } finally {
+ w.close();
}
- };
- for (final FetchHeadRecord h : fetchHeadUpdates) {
- h.write(pw);
- result.add(h);
+ lock.commit();
}
- pw.close();
- lock.commit();
+ } finally {
+ lock.unlock();
}
}
--
1.6.3.2.199.g7340d
reply other threads:[~2009-08-11 14:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1249969686-11232-1-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@gmail.com \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).