diff options
author | James Moger <james.moger@gitblit.com> | 2011-07-22 17:47:53 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-07-22 17:47:53 -0400 |
commit | a2709dd91e5d6b18f573016882ccc70799573ad3 (patch) | |
tree | 6b87a08d65c462d9f51b253e7deafb95c7167bbb /src/com/gitblit/utils/FileUtils.java | |
parent | b1dba764c201f4708b82767b2d91edb6e189ce6f (diff) | |
download | gitblit-a2709dd91e5d6b18f573016882ccc70799573ad3.tar.gz gitblit-a2709dd91e5d6b18f573016882ccc70799573ad3.zip |
Centralize default branch/HEAD resolution (issue 14)
If an object id was not specified Gitblit used HEAD to perform the
operation. This breaks under some conditions like working with a
repository that does not have any commits on master but does have
commits on a vcs-import branch.
The new approach is to centralize the resolution of unspecified object
ids to a common method which resolves HEAD first but uses the most
recently modified branch if HEAD points to nothing.
This commit also includes a non-functional method for creating an empty
branch. I couldn't figure out how to make JGit create an orphaned
branch.
Diffstat (limited to 'src/com/gitblit/utils/FileUtils.java')
-rw-r--r-- | src/com/gitblit/utils/FileUtils.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java index 310e35a9..6644d83c 100644 --- a/src/com/gitblit/utils/FileUtils.java +++ b/src/com/gitblit/utils/FileUtils.java @@ -16,9 +16,12 @@ package com.gitblit.utils;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
/**
@@ -58,6 +61,25 @@ public class FileUtils { }
/**
+ * Writes the string content to the file.
+ *
+ * @param file
+ * @param content
+ */
+ public static void writeContent(File file, String content) {
+ try {
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file),
+ Charset.forName("UTF-8"));
+ BufferedWriter writer = new BufferedWriter(os);
+ writer.append(content);
+ writer.close();
+ } catch (Throwable t) {
+ System.err.println("Failed to write content of " + file.getAbsolutePath());
+ t.printStackTrace();
+ }
+ }
+
+ /**
* Recursively traverses a folder and its subfolders to calculate the total
* size in bytes.
*
|