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

Re: [JGIT PATCH] Create a debugging tool "jgit rebuild-commitgraph"

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 16, 2009, 14:44 UTC
Message-ID
<20090316144450.GN22920@spearce.org>
In-Reply-To
<200903151234.39367.robin.rosenberg@dewire.com>
Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> 
> I'd hate to put such a dangerous thing in the list of normal tools. If the user
> want to shoot him/her-self in the foot they should get a license first.
How about squashing this in?
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RebuildCommitGraph.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RebuildCommitGraph.java
index ccee997..cc23438 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RebuildCommitGraph.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RebuildCommitGraph.java
@@ -50,6 +50,7 @@
 import java.util.Map;
 
 import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
 import org.spearce.jgit.errors.MissingObjectException;
 import org.spearce.jgit.errors.ObjectWritingException;
 import org.spearce.jgit.lib.Commit;
@@ -85,6 +86,11 @@
  * <p>
  */
 class RebuildCommitGraph extends TextBuiltin {
+	private final String REALLY = "--destroy-this-repository";
+
+	@Option(name = REALLY, usage = "approve destruction of repository")
+	boolean really;
+
 	@Argument(index = 0, required = true, metaVar = "REFS", usage = "for-each-ref output")
 	File refList;
 
@@ -97,6 +103,30 @@
 
 	@Override
 	protected void run() throws Exception {
+		if (!really && !db.getAllRefs().isEmpty()) {
+			final StringBuilder m = new StringBuilder();
+			m.append("fatal: ");
+			m.append("This program will destroy the repository:");
+			m.append("\n");
+			m.append("fatal:\n");
+			m.append("fatal:    ");
+			m.append(db.getDirectory().getAbsolutePath());
+			m.append("\n");
+			m.append("fatal:\n");
+			m.append("fatal: ");
+			m.append("To continue, add ");
+			m.append(REALLY);
+			m.append(" to the command line");
+			m.append("\n");
+			m.append("fatal:");
+			System.err.println(m);
+			throw die("Need approval to destroy current repository");
+		}
+		if (!refList.isFile())
+			throw die("no such file: " + refList.getPath());
+		if (!graph.isFile())
+			throw die("no such file: " + graph.getPath());
+
 		recreateCommitGraph();
 		detachHead();
 		deleteAllRefs();
-- 
Shawn.
Previous: Robin RosenbergNext: Robin Rosenberg
Message 5 of 8 in “Create a debugging tool "jgit rebuild-commitgraph"”
  1. Create a debugging tool "jgit rebuild-commitgraph"Shawn O. Pearce, Mar 13, 2009
  2. Johannes SchindelinMar 13, 2009
  3. Shawn O. PearceMar 13, 2009
  4. Robin RosenbergMar 15, 2009
  5. Shawn O. PearceMar 16, 2009
  6. Robin RosenbergMar 16, 2009
  7. Shawn O. PearceMar 16, 2009
  8. Create a debugging tool "jgit debug-rebuild-commitgraph"Shawn O. Pearce, Mar 16, 2009

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.