threads / patch / 21034

patch, 2 partsadd support for core.logAllRefUpdates configuration parameter

Subject: [JGIT PATCH 1/2] add support for core.logAllRefUpdates configuration parameter

## tl;dr

3 messages between Sep 23, 2009 and Sep 25, 2009. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Halstrick, Christian· Sep 23, 2009, 16:42 UTC · lore
From: Christian Halstrick <christian.halstrick@sap.com>
JGit should understand configuration parameter logAllRefUpdates and should
only log updates of refs when
  either the log file for this ref is already present
  or this configuration parameter is set to true
Before this commit JGit was always writing logs, regardless of this
parameter or existence of logfiles.
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
---
 .../src/org/spearce/jgit/lib/CoreConfig.java       |   10 ++++++++++
 .../src/org/spearce/jgit/lib/RefLogWriter.java     |   18 ++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)
Show changes to 2 files +20 −8

org.spearce.jgit/src/org/spearce/jgit/lib/CoreConfig.java, org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/CoreConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/CoreConfig.java
index ed3827b..ecd9544 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/CoreConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/CoreConfig.java
@@ -56,10 +56,13 @@ public CoreConfig parse(final Config cfg) {
 	private final int compression;
 
 	private final int packIndexVersion;
+	
+	private final boolean logAllRefUpdates;
 
 	private CoreConfig(final Config rc) {
 		compression = rc.getInt("core", "compression", DEFAULT_COMPRESSION);
 		packIndexVersion = rc.getInt("pack", "indexversion", 2);
+		logAllRefUpdates = rc.getBoolean("core", "logAllRefUpdates", false);
 	}
 
 	/**
@@ -77,4 +80,11 @@ public int getCompression() {
 	public int getPackIndexVersion() {
 		return packIndexVersion;
 	}
+	
+	/**
+	 * @return whether to log all refUpdates 
+	 */
+	public boolean isLogAllRefUpdates() {
+		return logAllRefUpdates;
+	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java
index 4aad809..1e5155c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefLogWriter.java
@@ -112,16 +112,18 @@ private static void appendOneRecord(final ObjectId oldId,
 		final byte[] rec = Constants.encode(r.toString());
 		final File logdir = new File(db.getDirectory(), Constants.LOGS);
 		final File reflog = new File(logdir, refName);
-		final File refdir = reflog.getParentFile();
+		if (reflog.exists() || db.getConfig().getCore().isLogAllRefUpdates()) {
+			final File refdir = reflog.getParentFile();
 
-		if (!refdir.exists() && !refdir.mkdirs())
-			throw new IOException("Cannot create directory " + refdir);
+			if (!refdir.exists() && !refdir.mkdirs())
+				throw new IOException("Cannot create directory " + refdir);
 
-		final FileOutputStream out = new FileOutputStream(reflog, true);
-		try {
-			out.write(rec);
-		} finally {
-			out.close();
+			final FileOutputStream out = new FileOutputStream(reflog, true);
+			try {
+				out.write(rec);
+			} finally {
+				out.close();
+			}
 		}
 	}
 
-- 
1.6.4.msysgit.0
Robin Rosenberg· Sep 25, 2009, 22:45 UTC · re: Halstrick, Christian · lore

Re: [JGIT PATCH 1/2] add support for core.logAllRefUpdates configuration parameter

onsdag 23 september 2009 18:42:29 skrev "Halstrick, Christian" <christian.halstrick@sap.com>:
Show 8 quoted lines
> From: Christian Halstrick <christian.halstrick@sap.com>
> 
> JGit should understand configuration parameter logAllRefUpdates and should
> only log updates of refs when
>   either the log file for this ref is already present
>   or this configuration parameter is set to true
> Before this commit JGit was always writing logs, regardless of this
> parameter or existence of logfiles.

A few minor things: Format the comment nicely and space betwee paragraphs. Start the comment with a capital letter A cover letter for multiple patches is nice, though in this case you could actually just squash there patches into one patch.

and one major. RefUpdateTest broke.

Probably because of this.
> +		logAllRefUpdates = rc.getBoolean("core", "logAllRefUpdates", false);

According to the git-config man page logAllRefUpdates is true by default for non-bare repos and false for bare repos.

I had some trouble applying these patches as git-am did not like them. Apparently git-am doesn't like base64. Could you set your mailer to use a more plain-ish format or use git-send-email.

-- robin
Robin Rosenberg· Sep 25, 2009, 22:52 UTC · re: Robin Rosenberg · lore

Re: [JGIT PATCH 1/2] add support for core.logAllRefUpdates configuration parameter

lördag 26 september 2009 00:45:20 skrev Robin Rosenberg <robin.rosenberg@dewire.com>:
Show 11 quoted lines
> onsdag 23 september 2009 18:42:29 skrev "Halstrick, Christian" <christian.halstrick@sap.com>:
> > From: Christian Halstrick <christian.halstrick@sap.com>
> > 
> > JGit should understand configuration parameter logAllRefUpdates and should
> > only log updates of refs when
> >   either the log file for this ref is already present
> >   or this configuration parameter is set to true
> > Before this commit JGit was always writing logs, regardless of this
> > parameter or existence of logfiles.
> 
> A few minor things:
Forgot: Please:
> Format the comment nicely and space betwee paragraphs.
[...]
-- robin

← back to recent threads