[EGIT PATCH 3/4] Add writeRef method and make writeSymref public.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The writeRef method is for creating tags and branches. writeSymref
is for creating symbols like HEAD.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---

 .../src/org/spearce/jgit/lib/Repository.java       |   31 ++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 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 b4d6473..0f2a900 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -349,7 +349,36 @@ public class Repository {
 		}
 	}
 
-	private void writeSymref(final String name, final String target)
+    public void writeRef(String name, ObjectId id) throws IOException {
+		File f = new File(gitDir, name);
+		File t = File.createTempFile("ref", null, gitDir);
+		FileWriter w = new FileWriter(t);
+		try {
+			w.write(id.toString());
+			w.write('\n');
+			w.close();
+			w = null;
+			if (!t.renameTo(f)) {
+				f.getParentFile().mkdirs();
+				if (!t.renameTo(f)) {
+					f.delete();
+					if (!t.renameTo(f)) {
+						t.delete();
+						throw new ObjectWritingException("Unable to"
+								+ " write ref " + name + " to point to "
+								+ id.toString());
+					}
+				}
+			}
+		} finally {
+			if (w != null) {
+				w.close();
+				t.delete();
+			}
+		}
+	}
+
+    public void writeSymref(final String name, final String target)
 			throws IOException {
 		final File s = new File(gitDir, name);
 		final File t = File.createTempFile("srf", null, gitDir);

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]