git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Apr 22, 2007, 21:36 UTC
Message-ID
<20070422213608.26396.16129.stgit@lathund.dewire.com>
In-Reply-To
<20070422212907.26396.12810.stgit@lathund.dewire.com>

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

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../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);
Previous: Shawn O. PearceNext: Robin Rosenberg
Message 6 of 8 in “Unit test for plugin and then some”
  1. 0/4 Unit test for plugin and then someRobin Rosenberg, Apr 22, 2007
  2. 1/4 Drop unneeded GitTreeStorageRobin Rosenberg, Apr 22, 2007
  3. 2/4 Use the Git sort order.Robin Rosenberg, Apr 22, 2007
  4. Robin RosenbergApr 23, 2007
  5. Shawn O. PearceApr 24, 2007
  6. 3/4 Add writeRef method and make writeSymref public.Robin Rosenberg, Apr 22, 2007
  7. 4/4 Add a JUnit test project for egit.Robin Rosenberg, Apr 22, 2007
  8. Robin RosenbergApr 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.