Git development
 help / color / mirror / Atom feed
* [PATCH] git-gui: suggest gc only when counting at least 2 objects
From: Clemens Buchacher @ 2009-09-13 16:06 UTC (permalink / raw)
  To: git; +Cc: msysgit, Junio C Hamano, Shawn O. Pearce
In-Reply-To: <20090909195158.GA12968@localhost>

On Windows, git-gui suggests running the garbage collector if it finds
1 or more files in .git/objects/42 (as opposed to 8 files on other
platforms). The probability of that happening if the repo contains
only about 100 loose objects is 32%. The probability for the same to happen
with at least 2 files is only 6%, which is bit more reasonable.

The following octave script shows the probability for m or more
objects to be in .git/objects/42 for a total of n objects.

m = [1 2 8];
n = 100:100:3000;

P = zeros(length(n), length(m));
for k = 1:length(n)
        P(k, :) = 1-binocdf(m-1, n(k), 1/255);
end
plot(n, P);

n \ m   1       2       8
100     32%     6%      0%
500     86%     58%     0%
1000    98%     90%     5%
2000    100%    100%    55%

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---

So here is the patch for my other complaint. Note that I fixed a bug in the
octave script above, in case someone wants to check the numbers.

I even tested it on a windows VM (as if it wasn't slow enough already).

Clemens

 git-gui/lib/database.tcl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-gui/lib/database.tcl b/git-gui/lib/database.tcl
index a18ac8b..44099e5 100644
--- a/git-gui/lib/database.tcl
+++ b/git-gui/lib/database.tcl
@@ -91,7 +91,7 @@ proc do_fsck_objects {} {
 proc hint_gc {} {
 	set object_limit 8
 	if {[is_Windows]} {
-		set object_limit 1
+		set object_limit 2
 	}
 
 	set objects_current [llength [glob \
-- 
1.6.5.rc0.164.g5f6b0

^ permalink raw reply related

* Re: git push --confirm ?
From: Uri Okrent @ 2009-09-13 16:59 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, Owen Taylor, git, Colin Walters
In-Reply-To: <20090913105247.GA21750@coredump.intra.peff.net>

Jeff King wrote:
[snip]
> Besides being a lot more annoying to implement, there is one big
> downside: in many cases the single TCP connection is a _feature_. If you
> are pushing via ssh and providing a password manually, it is a
> significant usability regression to have to input it twice.
> 
> Also, given that ssh is going to be by far the biggest transport for
> pushing via the git protocol, I suspect any timeouts are set for
> _before_ the authentication phase (i.e., SSH times you out if you don't
> actually log in). So in that sense it may not be worth worrying about
> how long we take during the push itself.

That doesn't seem like a huge hurdle to overcome. Most ssh clients support some
sort of ServerAliveInterval parameter for just this reason. Sending a keep alive
packet every 60 seconds or so while waiting for user confirmation doesn't seem
all that egregious.
-- 
    Uri

Please consider the environment before printing this message.
http://www.panda.org/how_you_can_help/

^ permalink raw reply

* [PATCH v2] git-push: Accept -n as a synonym for --dry-run.
From: Nelson Elhage @ 2009-09-13 16:56 UTC (permalink / raw)
  To: git; +Cc: Nelson Elhage

git-push is not currently using -n for anything else, and it seems
unlikely we will want to use it to mean anything else in the future,
so add it as an alias for convenience.

Signed-off-by: Nelson Elhage <nelhage@mit.edu>
---

 Documentation/git-push.txt |    3 ++-
 builtin-push.c             |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 58d2bd5..ba6a8a2 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects
 SYNOPSIS
 --------
 [verse]
-'git push' [--all | --mirror | --tags] [--dry-run] [--receive-pack=<git-receive-pack>]
+'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
 	   [--repo=<repository>] [-f | --force] [-v | --verbose]
 	   [<repository> <refspec>...]
 
@@ -82,6 +82,7 @@ nor in any Push line of the corresponding remotes file---see below).
 	if the configuration option `remote.<remote>.mirror` is
 	set.
 
+-n::
 --dry-run::
 	Do everything except actually send the updates.
 
diff --git a/builtin-push.c b/builtin-push.c
index 787011f..5e5f3ad 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
-	"git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
 	NULL,
 };
 
@@ -182,7 +182,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
 			    (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
 		OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
-		OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
+		OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
 		OPT_BIT( 0,  "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
 		OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
 		OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
-- 
1.6.3.1.499.ge7b8da

^ permalink raw reply related

* Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.
From: Nelson Elhage @ 2009-09-13 17:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7vd45v2za4.fsf@alter.siamese.dyndns.org>

On Sat, Sep 12, 2009 at 10:23:47PM -0700, Junio C Hamano wrote:
> Nelson Elhage <nelhage@MIT.EDU> writes:
> 
> > ... I think my
> > general argument still stands for commands where that is not the case.
> 
> Cool down.
> 
> It is a mere subset of what I already said, so you are not arguing against
> me at all.

My apologies for continuing an argument where there was none. I've
sent a patch with an improved commit message, and we can continue
discussing on that thread if necessary.

- Nelson

^ permalink raw reply

* [PATCH] reflog: Usage documentation cleanup
From: Nelson Elhage @ 2009-09-13 17:23 UTC (permalink / raw)
  To: git; +Cc: Nelson Elhage

* Make git-reflog.txt and the builtin usage text consistent.
* Make 'git reflog expire' not claim that 'show' takes the same
  arguments as 'expire'.
* Document -n as an alias for --dry-run for the expire and delete
  subcommands.
---

 Documentation/git-reflog.txt |    5 +++--
 builtin-reflog.c             |    4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

Thanks to Jeff King and Erik Faye-Lund for both pointing out that 'git
reflog expire' is probably wrong to be documenting the 'show' command
in the first place, which makes this cleanup much saner.

diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt
index 7f7a544..2c90c2c 100644
--- a/Documentation/git-reflog.txt
+++ b/Documentation/git-reflog.txt
@@ -16,10 +16,11 @@ The command takes various subcommands, and different options
 depending on the subcommand:
 
 [verse]
-'git reflog expire' [--dry-run] [--stale-fix] [--verbose]
+'git reflog expire' [-n | --dry-run] [--stale-fix] [--verbose]
 	[--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...
 +
-'git reflog delete' ref@\{specifier\}...
+'git reflog delete [--verbose] [-n | --dry-run] [--rewrite]
+	[--updateref] ref@\{specifier}\...'
 +
 'git reflog' ['show'] [log-options] [<ref>]
 
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 95198c5..4da5c6b 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -13,9 +13,9 @@
  */
 
 static const char reflog_expire_usage[] =
-"git reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
+"git reflog expire [--verbose] [-n | --dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
 static const char reflog_delete_usage[] =
-"git reflog delete [--verbose] [--dry-run] [--rewrite] [--updateref] <refs>...";
+"git reflog delete [--verbose] [-n | --dry-run] [--rewrite] [--updateref] ref@{specifier}...";
 
 static unsigned long default_reflog_expire;
 static unsigned long default_reflog_expire_unreachable;
-- 
1.6.3.1.499.ge7b8da

^ permalink raw reply related

* [PATCH 1/2] git-archive: add '-o' as a alias for '--output'
From: Dmitry Potapov @ 2009-09-13 17:36 UTC (permalink / raw)
  To: Junio C Hamano, git; +Cc: John Tapsell, Dmitry Potapov
In-Reply-To: <7v3a6r5znq.fsf@alter.siamese.dyndns.org>

The '-o' option is commonly used in many tools to specify the output file.
Typing '--output' every time is a bit too long to be a practical alternative
to redirecting output. But specifying the output name has the advantage of
making possible to guess the desired output format by filename extension.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---

PS I resend this patch because I forgot to include the git mailing list when
I sent it before. Sorry for inconvinience...

 Documentation/git-archive.txt |    3 ++-
 archive.c                     |    2 +-
 builtin-archive.c             |    2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt
index 92444dd..f7a3b95 100644
--- a/Documentation/git-archive.txt
+++ b/Documentation/git-archive.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
-	      [--output=<file>] [--worktree-attributes]
+	      [-o | --output=<file>] [--worktree-attributes]
 	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
 	      [path...]
 
@@ -48,6 +48,7 @@ OPTIONS
 --prefix=<prefix>/::
 	Prepend <prefix>/ to each filename in the archive.
 
+-o::
 --output=<file>::
 	Write the archive to <file> instead of stdout.
 
diff --git a/archive.c b/archive.c
index 0bca9ca..73b8e8a 100644
--- a/archive.c
+++ b/archive.c
@@ -283,7 +283,7 @@ static int parse_archive_args(int argc, const char **argv,
 		OPT_STRING(0, "format", &format, "fmt", "archive format"),
 		OPT_STRING(0, "prefix", &base, "prefix",
 			"prepend prefix to each pathname in the archive"),
-		OPT_STRING(0, "output", &output, "file",
+		OPT_STRING('o', "output", &output, "file",
 			"write the archive to this file"),
 		OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
 			"read .gitattributes in working directory"),
diff --git a/builtin-archive.c b/builtin-archive.c
index f9a4bea..565314b 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -71,7 +71,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 	const char *output = NULL;
 	const char *remote = NULL;
 	struct option local_opts[] = {
-		OPT_STRING(0, "output", &output, "file",
+		OPT_STRING('o', "output", &output, "file",
 			"write the archive to this file"),
 		OPT_STRING(0, "remote", &remote, "repo",
 			"retrieve the archive from remote repository <repo>"),
-- 
1.6.4

^ permalink raw reply related

* [PATCH 2/2] teach git-archive to auto detect the output format
From: Dmitry Potapov @ 2009-09-13 17:36 UTC (permalink / raw)
  To: Junio C Hamano, git; +Cc: John Tapsell, Dmitry Potapov
In-Reply-To: <1252863407-2598-1-git-send-email-dpotapov@gmail.com>

When I type something like this:
  git archive -o my-v2.0.zip v2.0
it is almost certainly that I want to create a zip archive, and not
a tar file.

This patch teaches git-archive to auto detect the output format from the
file name. Currently, only '.zip' is supported. If the auto detect failed,
the tar format is used as default. The auto detect is not used when the
output format is specified explicitly.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---

On Sat, Sep 12, 2009 at 07:47:21PM -0700, Junio C Hamano wrote:
> John Tapsell <johnflux@gmail.com> writes:
>_
> > Why not have  --format=tgz  then or something?  Or better yet, give
> > the filename on the command line and detect the format from the file
> > extension.
>_
> That is an interesting enhancement and sounds like a useful feature.

Here is my first attempt to implement that. I have not added 'tgz' yet,
but only auto detect the format from the output file name.

PS I resend this patch because I forgot to include the git mailing list when
I sent it before. Sorry for inconvinience...

 Documentation/git-archive.txt |   10 +++++++++-
 builtin-archive.c             |   25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt
index f7a3b95..c6fb21c 100644
--- a/Documentation/git-archive.txt
+++ b/Documentation/git-archive.txt
@@ -35,7 +35,9 @@ OPTIONS
 
 --format=<fmt>::
 	Format of the resulting archive: 'tar' or 'zip'.  The default
-	is 'tar'.
+	is 'tar', unless the output file is specified, and it has a known
+	extension (such as '.zip') then the default for the output format
+	will be determined by this extension.
 
 -l::
 --list::
@@ -130,6 +132,12 @@ git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs
 	Put everything in the current head's Documentation/ directory
 	into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
 
+git archive -o latest.zip HEAD::
+
+	Create a Zip archive that contains the contents of the latest
+	commit on the current branch. Note that the output format is
+	specified implicitly by the extension of the output file.
+
 
 SEE ALSO
 --------
diff --git a/builtin-archive.c b/builtin-archive.c
index 565314b..878c6b2 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -60,6 +60,17 @@ static int run_remote_archiver(int argc, const char **argv,
 	return !!rv;
 }
 
+static const char* format_from_name(const char *filename)
+{
+	const char *ext = strrchr(filename, '.');
+	if (!ext)
+		return NULL;
+	ext++;
+	if (!strcasecmp(ext, "zip"))
+		return "zip";
+	return NULL;
+}
+
 #define PARSE_OPT_KEEP_ALL ( PARSE_OPT_KEEP_DASHDASH | 	\
 			     PARSE_OPT_KEEP_ARGV0 | 	\
 			     PARSE_OPT_KEEP_UNKNOWN |	\
@@ -70,6 +81,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 	const char *exec = "git-upload-archive";
 	const char *output = NULL;
 	const char *remote = NULL;
+	const char *format = NULL;
 	struct option local_opts[] = {
 		OPT_STRING('o', "output", &output, "file",
 			"write the archive to this file"),
@@ -77,14 +89,27 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 			"retrieve the archive from remote repository <repo>"),
 		OPT_STRING(0, "exec", &exec, "cmd",
 			"path to the remote git-upload-archive command"),
+		OPT_STRING(0, "format", &format, "fmt", "archive format"),
 		OPT_END()
 	};
+	char fmt_opt[32];
 
 	argc = parse_options(argc, argv, prefix, local_opts, NULL,
 			     PARSE_OPT_KEEP_ALL);
 
 	if (output)
+	{
 		create_output_file(output);
+		if (!format)
+			format = format_from_name(output);
+	}
+
+	if (format)
+	{
+		sprintf(fmt_opt, "--format=%s", format);
+		argv[argc++] = fmt_opt;
+		argv[argc] = NULL;
+	}
 
 	if (remote)
 		return run_remote_archiver(argc, argv, remote, exec);
-- 
1.6.4

^ permalink raw reply related

* Re: [PATCH] git-gui: suggest gc only when counting at least 2 objects
From: Junio C Hamano @ 2009-09-13 17:58 UTC (permalink / raw)
  To: Clemens Buchacher; +Cc: git, msysgit, Shawn O. Pearce
In-Reply-To: <20090913160637.GA15256@localhost>

Clemens Buchacher <drizzd@aon.at> writes:

> On Windows, git-gui suggests running the garbage collector if it finds
> 1 or more files in .git/objects/42 (as opposed to 8 files on other
> platforms).

Somebody cares to explain why this threashold number has to be different
per platform in the first place?  Instead of bumping up to 2 like your
patch did, what bad things would happen if you increased it to 8 on
Windows?  Doesn't the same badness happen on non-Windows because they have
the threashold set to 8 already?

^ permalink raw reply

* Re: rename tracking and file-name swapping
From: Junio C Hamano @ 2009-09-13 18:14 UTC (permalink / raw)
  To: Yuri D'Elia; +Cc: git
In-Reply-To: <wavexx-2ECE7F.13171313092009@ger.gmane.org>

Yuri D'Elia <wavexx@users.sf.net> writes:

> Hi everyone. Does rename tracking recognize two file names being swapped?
>
> % ls -l
> total 24
> -rw-rw-r--   1 wavexx  wavexx  5952 Sep 13 13:09 file1.txt
> -rw-rw-r--   1 wavexx  wavexx  3330 Sep 13 13:09 file2.txt
> % mv file1.txt file3.txt 
> % mv file2.txt file1.txt
> % mv file3.txt file2.txt
> % git add file1.txt file2.txt 
> % git diff -M --stat --cached
>  file1.txt |  150 +++++++++++++++++++++++-------------------------------------
>  file2.txt |  150 +++++++++++++++++++++++++++++++++++++-----------------------
>  2 files changed, 150 insertions(+), 150 deletions(-)

By default, if the pathname that was present in the old version still
appears in the new version, that path is not considered as a candiate
for rename detection.  Only "X used to be there but is gone" and "Y did
not exist but appeared" are paired up and checked if they are similar.

Give the command -B option, too, to break the filepair that does not
disappear.

^ permalink raw reply

* Re: [PATCH] completion: Replace config --list with --get-regexp
From: Todd Zullinger @ 2009-09-13 18:29 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: Shawn O. Pearce, Jeff King, james bardin, git, Junio C Hamano
In-Reply-To: <36ca99e90909130351m7ad5a641t8adb3ade3d2ec5ca@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

Bert Wesarg wrote:
> I have not looked into this, but what about pushurl?

Is it reasonable to expect someone to have remote.<name>.pushurl and
not have remote.<name>.url set?  If not, then we should be fine, as
all the old code and this new code do is extract <name>.

OTOH, if there are some cases where setting pushurl and not url make
sense, extending the regex to catch pushurl as well is a simple matter
of changing 'remote\..*\.url' to 'remote\..*\.(push)?url' and, I
believe, using 'echo "${i/.*url*/}"' to strip off everything after the
remote <name>.

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fleas can be taught nearly anything that a Congressman can.
    -- Mark Twain


[-- Attachment #2: Type: application/pgp-signature, Size: 542 bytes --]

^ permalink raw reply

* Re: [PATCH 1/2] git-archive: add '-o' as a alias for '--output'
From: Junio C Hamano @ 2009-09-13 18:34 UTC (permalink / raw)
  To: Dmitry Potapov; +Cc: git, John Tapsell
In-Reply-To: <1252863407-2598-1-git-send-email-dpotapov@gmail.com>

Dmitry Potapov <dpotapov@gmail.com> writes:

> The '-o' option is commonly used in many tools to specify the output file.
> Typing '--output' every time is a bit too long to be a practical alternative
> to redirecting output. But specifying the output name has the advantage of
> making possible to guess the desired output format by filename extension.
>
> Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
> ---
> ...
> diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt
> index 92444dd..f7a3b95 100644
> --- a/Documentation/git-archive.txt
> +++ b/Documentation/git-archive.txt
> @@ -48,6 +48,7 @@ OPTIONS
>  --prefix=<prefix>/::
>  	Prepend <prefix>/ to each filename in the archive.
>  
> +-o::
>  --output=<file>::
>  	Write the archive to <file> instead of stdout.

I think this patch is very reasonable, except for this hunk, which would
want to say "-o <file>::" instead.  I'll see if there are comments from
others and if there is none, apply this patch with that minor tweak.

Thanks.

^ permalink raw reply

* Re: [PATCH] git-gui: suggest gc only when counting at least 2 objects
From: Clemens Buchacher @ 2009-09-13 18:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, msysgit, Shawn O. Pearce
In-Reply-To: <7vr5uasp4a.fsf@alter.siamese.dyndns.org>

On Sun, Sep 13, 2009 at 10:58:45AM -0700, Junio C Hamano wrote:
> Somebody cares to explain why this threashold number has to be different
> per platform in the first place? 

I really don't know. I vaguely remember someone claim that performance on
Windows suffered from many loose objects more than on other platforms. I
can't find any discussion of it though.

^ permalink raw reply

* [PATCH JGit] Adding update-server-info functionality
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git

This patch series implements update-server-info functionality
in JGit and integrates it with ReceivePack so that repositories
hosted by git-http can also be hosted by JGit.

^ permalink raw reply

* [PATCH JGit 01/19] adding tests for ObjectDirectory
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-1-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   80 ++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
new file mode 100644
index 0000000..fe019af
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
@@ -0,0 +1,80 @@
+package org.spearce.jgit.lib;
+
+import java.io.File;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+public class ObjectDirectoryTest extends TestCase {
+	
+	private File testDir;
+
+	@Override
+	protected void setUp() throws Exception {
+		testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString());
+	}
+	
+	@Override
+	protected void tearDown() throws Exception {
+		if (testDir.exists()){
+			deleteDir(testDir);
+		}
+	}
+
+	public void testCanGetDirectory() throws Exception {
+		ObjectDirectory od = new ObjectDirectory(testDir);
+		assertEquals(testDir, od.getDirectory());
+	}
+	
+	public void testExistsWithExistingDirectory() throws Exception {
+		createTestDir();
+		ObjectDirectory od = new ObjectDirectory(testDir);
+		assertTrue(od.exists());
+	}
+	
+	public void testExistsWithNonExistantDirectory() throws Exception {
+		assertFalse(new ObjectDirectory(new File("/some/nonexistant/file")).exists());
+	}
+	
+	public void testCreateMakesCorrectDirectories() throws Exception {
+		assertFalse(testDir.exists());
+		new ObjectDirectory(testDir).create();
+		assertTrue(testDir.exists());
+		
+		File infoDir = new File(testDir, "info");
+		assertTrue(infoDir.exists());
+		assertTrue(infoDir.isDirectory());
+		
+		File packDir = new File(testDir, "pack");
+		assertTrue(packDir.exists());
+		assertTrue(packDir.isDirectory());
+	}
+	
+	public void testGettingObjectFile() throws Exception {
+		ObjectDirectory od = new ObjectDirectory(testDir);
+		assertEquals(new File(testDir, "02/829ae153935095e4223f30cfc98c835de71bee"), 
+					 od.fileFor(ObjectId.fromString("02829ae153935095e4223f30cfc98c835de71bee")));
+		assertEquals(new File(testDir, "b0/52a1272310d8df34de72f60204dee7e28a43d0"), 
+				 od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0")));
+	}
+	
+	public boolean deleteDir(File dir) {
+        if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i=0; i<children.length; i++) {
+                boolean success = deleteDir(new File(dir, children[i]));
+                if (!success) {
+                    return false;
+                }
+            }
+        }
+    
+        // The directory is now empty so delete it
+        return dir.delete();
+    }
+
+	private void createTestDir(){
+		testDir.mkdir();
+	}
+	
+}
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 04/19] added utility that generates the contents of the objects/info/packs file as a string from a list of PackFiles
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-4-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/PacksFileContentsCreatorTest.java     |   37 ++++++++++++++++++++
 .../spearce/jgit/lib/PacksFileContentsCreator.java |   21 +++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
new file mode 100644
index 0000000..ef28a26
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
@@ -0,0 +1,37 @@
+package org.spearce.jgit.lib;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.spearce.jgit.util.JGitTestUtil;
+
+import junit.framework.TestCase;
+
+public class PacksFileContentsCreatorTest extends TestCase {
+	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
+	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
+	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
+
+	public void testGettingPacksContentsSinglePack() throws Exception {
+		List<PackFile> packs = new ArrayList<PackFile>();
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		
+		assertEquals("P " + TEST_PACK.getName() + '\r', new PacksFileContentsCreator(packs).toString());
+	}
+	
+	public void testGettingPacksContentsMultiplePacks() throws Exception {
+		List<PackFile> packs = new ArrayList<PackFile>();
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		
+		StringBuilder expected = new StringBuilder();
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		
+		assertEquals(expected.toString(), new PacksFileContentsCreator(packs).toString());
+	}
+	
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
new file mode 100644
index 0000000..3dd0418
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
@@ -0,0 +1,21 @@
+package org.spearce.jgit.lib;
+
+import java.util.List;
+
+public class PacksFileContentsCreator {
+
+	private List<PackFile> packs;
+
+	public PacksFileContentsCreator(List<PackFile> packs) {
+		this.packs = packs;
+	}
+	
+	public String toString(){
+		StringBuilder builder = new StringBuilder();
+		for (PackFile packFile : packs) {
+			builder.append("P ").append(packFile.getPackFile().getName()).append('\r');
+		}
+		return builder.toString();
+	}
+
+}
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 03/19] Add abstract method for updating the object db's info cache Implemented passthrough on Alternate for the update of infocache
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-3-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/AlternateRepositoryDatabase.java      |    5 +++++
 .../src/org/spearce/jgit/lib/ObjectDatabase.java   |    7 +++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
index 68ad488..5cb0579 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
@@ -130,4 +130,9 @@ protected void closeAlternates(final ObjectDatabase[] alt) {
 	public List<PackFile> listLocalPacks() {
 		return odb.listLocalPacks();
 	}
+
+	@Override
+	public void updateInfoCache() {
+		odb.updateInfoCache();
+	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
index 722c802..68ff523 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
@@ -75,6 +75,13 @@ protected ObjectDatabase() {
 	public abstract List<PackFile> listLocalPacks();
 	
 	/**
+	 * Creates the caches that are typically done by 
+	 * update-server-info, namely objects/info/packs and 
+	 * info/refs
+	 */
+	public abstract void updateInfoCache();
+	
+	/**
 	 * Does this database exist yet?
 	 *
 	 * @return true if this database is already created; false if the caller
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 06/19] added utility for reading the contents of a file as a string
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-6-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
index 04184d7..b958282 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
@@ -37,10 +37,12 @@
 
 package org.spearce.jgit.util;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -71,7 +73,8 @@ public static File getTestResourceFile(final String fileName) {
 		}
 	}
 
-	public static void copyFile(final File fromFile, final File toFile) throws IOException {
+	public static void copyFile(final File fromFile, final File toFile)
+			throws IOException {
 		InputStream in = new FileInputStream(fromFile);
 		OutputStream out = new FileOutputStream(toFile);
 
@@ -84,6 +87,21 @@ public static void copyFile(final File fromFile, final File toFile) throws IOExc
 		out.close();
 	}
 
+	public static String readFileAsString(final File file)
+			throws java.io.IOException {
+		StringBuilder fileData = new StringBuilder(1000);
+		BufferedReader reader = new BufferedReader(new FileReader(file));
+		char[] buf = new char[1024];
+		int numRead = 0;
+		while ((numRead = reader.read(buf)) != -1) {
+			String readData = String.valueOf(buf, 0, numRead);
+			fileData.append(readData);
+			buf = new char[1024];
+		}
+		reader.close();
+		return fileData.toString();
+	}
+
 	private static ClassLoader cl() {
 		return JGitTestUtil.class.getClassLoader();
 	}
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 05/19] Made tests for listLocalPacks function on ObjectDirectory and made them pass
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-5-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   24 ++++++++++++++++++++
 .../jgit/lib/UpdateDirectoryInfoCacheTest.java     |   11 +++++++++
 .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   21 ++++++++++++++++-
 .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    6 +++++
 .../spearce/jgit/lib/UpdateDirectoryInfoCache.java |   22 ++++++++++++++++++
 5 files changed, 83 insertions(+), 1 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
index fe019af..8e4d8e5 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
@@ -1,11 +1,17 @@
 package org.spearce.jgit.lib;
 
 import java.io.File;
+import java.util.List;
 import java.util.UUID;
 
+import org.spearce.jgit.util.JGitTestUtil;
+
 import junit.framework.TestCase;
 
 public class ObjectDirectoryTest extends TestCase {
+	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
+	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
+	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
 	
 	private File testDir;
 
@@ -58,6 +64,24 @@ public void testGettingObjectFile() throws Exception {
 				 od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0")));
 	}
 	
+	public void testListLocalPacksNotCreated() throws Exception {
+		assertEquals(0, new ObjectDirectory(testDir).listLocalPacks().size());
+	}
+	
+	public void testListLocalPacksWhenThereIsAPack() throws Exception {
+		createTestDir();
+		File packsDir = new File(testDir, "pack");
+		packsDir.mkdirs();
+		
+		JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));
+		JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));
+
+		ObjectDirectory od = new ObjectDirectory(testDir);
+		List<PackFile> localPacks = od.listLocalPacks();
+		assertEquals(1, localPacks.size());
+		assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());
+	}
+	
 	public boolean deleteDir(File dir) {
         if (dir.isDirectory()) {
             String[] children = dir.list();
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
new file mode 100644
index 0000000..11d183e
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
@@ -0,0 +1,11 @@
+package org.spearce.jgit.lib;
+
+import junit.framework.TestCase;
+
+public class UpdateDirectoryInfoCacheTest extends TestCase {
+	
+	public void testBase() throws Exception {
+		fail("nyi");
+	}
+
+}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
index eee0c14..04184d7 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
@@ -38,6 +38,12 @@
 package org.spearce.jgit.util;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
 
@@ -60,11 +66,24 @@ public static File getTestResourceFile(final String fileName) {
 		}
 		try {
 			return new File(url.toURI());
-		} catch(URISyntaxException e) {
+		} catch (URISyntaxException e) {
 			return new File(url.getPath());
 		}
 	}
 
+	public static void copyFile(final File fromFile, final File toFile) throws IOException {
+		InputStream in = new FileInputStream(fromFile);
+		OutputStream out = new FileOutputStream(toFile);
+
+		byte[] buf = new byte[1024];
+		int len;
+		while ((len = in.read(buf)) > 0) {
+			out.write(buf, 0, len);
+		}
+		in.close();
+		out.close();
+	}
+
 	private static ClassLoader cl() {
 		return JGitTestUtil.class.getClassLoader();
 	}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
index fe219c6..a90ae00 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
@@ -511,6 +511,12 @@ boolean tryAgain(final long currLastModified) {
 
 	@Override
 	public List<PackFile> listLocalPacks() {
+		tryAgain1();
 		return new ArrayList<PackFile>(Arrays.asList(packList.get().packs));
 	}
+
+	@Override
+	public void updateInfoCache() {
+		new UpdateDirectoryInfoCache(this.listLocalPacks(), this.infoDirectory).execute();
+	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
new file mode 100644
index 0000000..2bceb9e
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
@@ -0,0 +1,22 @@
+package org.spearce.jgit.lib;
+
+import java.io.File;
+import java.util.List;
+
+public class UpdateDirectoryInfoCache {
+
+	private List<PackFile> packsList;
+	private File infoDirectory;
+
+	public UpdateDirectoryInfoCache(List<PackFile> packsList,
+			File infoDirectory) {
+		this.packsList = packsList;
+		this.infoDirectory = infoDirectory;
+	}
+
+	public void execute() {
+//		File objectFile = objectDatabase.
+//		String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString();
+	}
+
+}
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 07/19] implemented the packs file update functionality
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-7-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/UpdateDirectoryInfoCacheTest.java     |   23 ++++++++++++++++++-
 .../spearce/jgit/lib/UpdateDirectoryInfoCache.java |   17 +++++++++-----
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
index 11d183e..25b78c5 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
@@ -1,11 +1,30 @@
 package org.spearce.jgit.lib;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.TestCase;
 
+import org.spearce.jgit.util.JGitTestUtil;
+
 public class UpdateDirectoryInfoCacheTest extends TestCase {
+	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
+	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
+	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
 	
-	public void testBase() throws Exception {
-		fail("nyi");
+	public void testCreatesTheFileAndPutsTheContentsIn() throws Exception {
+		List<PackFile> packs = new ArrayList<PackFile>();
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		
+		File packsFile = File.createTempFile(UpdateDirectoryInfoCacheTest.class.getSimpleName(), "tstdata");
+		packsFile.deleteOnExit();
+		
+		String expectedContents = new PacksFileContentsCreator(packs).toString();
+		
+		new UpdateDirectoryInfoCache(packs, packsFile).execute();
+		
+		assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
 	}
 
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
index 2bceb9e..72a315a 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
@@ -1,22 +1,27 @@
 package org.spearce.jgit.lib;
 
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.List;
 
 public class UpdateDirectoryInfoCache {
 
 	private List<PackFile> packsList;
-	private File infoDirectory;
+	private File infoPacksFile;
 
 	public UpdateDirectoryInfoCache(List<PackFile> packsList,
-			File infoDirectory) {
+									File infoPacksFile) {
 		this.packsList = packsList;
-		this.infoDirectory = infoDirectory;
+		this.infoPacksFile = infoPacksFile;
 	}
 
-	public void execute() {
-//		File objectFile = objectDatabase.
-//		String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString();
+	public void execute() throws IOException {
+		String packsContents = new PacksFileContentsCreator(packsList).toString();
+		FileOutputStream fos = new FileOutputStream(infoPacksFile);
+		fos.write(packsContents.getBytes());
+		fos.close();
 	}
 
 }
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 10/19] moved test up to a higher level to test actual functionality
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-10-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   32 ++++++++++++++++----
 .../UpdateDirectoryBasedPacksInfoCacheTest.java    |   30 ------------------
 2 files changed, 26 insertions(+), 36 deletions(-)
 delete mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
index 8e4d8e5..4ac62fa 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
@@ -1,6 +1,8 @@
 package org.spearce.jgit.lib;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
@@ -69,12 +71,7 @@ public void testListLocalPacksNotCreated() throws Exception {
 	}
 	
 	public void testListLocalPacksWhenThereIsAPack() throws Exception {
-		createTestDir();
-		File packsDir = new File(testDir, "pack");
-		packsDir.mkdirs();
-		
-		JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));
-		JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));
+		createSamplePacksDir();
 
 		ObjectDirectory od = new ObjectDirectory(testDir);
 		List<PackFile> localPacks = od.listLocalPacks();
@@ -82,6 +79,20 @@ public void testListLocalPacksWhenThereIsAPack() throws Exception {
 		assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());
 	}
 	
+	public void testUpdateInfoCacheCreatesPacksFile() throws Exception {
+		createSamplePacksDir();
+
+		ObjectDirectory od = new ObjectDirectory(testDir);
+		od.create();
+		od.updateInfoCache();
+		
+		String expectedContents = new PacksFileContentsCreator(od.listLocalPacks()).toString();
+		File packsFile = new File(od.getDirectory(), "info/packs");
+
+		assertTrue(packsFile.exists());
+		assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
+	}
+	
 	public boolean deleteDir(File dir) {
         if (dir.isDirectory()) {
             String[] children = dir.list();
@@ -100,5 +111,14 @@ public boolean deleteDir(File dir) {
 	private void createTestDir(){
 		testDir.mkdir();
 	}
+
+	private void createSamplePacksDir() throws IOException {
+		createTestDir();
+		File packsDir = new File(testDir, "pack");
+		packsDir.mkdirs();
+		
+		JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));
+		JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));
+	}
 	
 }
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java
deleted file mode 100644
index f5163e4..0000000
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.spearce.jgit.lib;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.spearce.jgit.util.JGitTestUtil;
-
-public class UpdateDirectoryBasedPacksInfoCacheTest extends TestCase {
-	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
-	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
-	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
-	
-	public void testCreatesTheFileAndPutsTheContentsIn() throws Exception {
-		List<PackFile> packs = new ArrayList<PackFile>();
-		packs.add(new PackFile(TEST_IDX, TEST_PACK));
-		
-		File packsFile = File.createTempFile(UpdateDirectoryBasedPacksInfoCacheTest.class.getSimpleName(), "tstdata");
-		packsFile.deleteOnExit();
-		
-		String expectedContents = new PacksFileContentsCreator(packs).toString();
-		
-		new UpdateDirectoryBasedPacksInfoCache(packs, packsFile).execute();
-		
-		assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
-	}
-
-}
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 08/19] changed signature to allow a IOException
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-8-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/AlternateRepositoryDatabase.java      |    2 +-
 .../src/org/spearce/jgit/lib/ObjectDatabase.java   |    3 ++-
 .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
index 5cb0579..70ce505 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java
@@ -132,7 +132,7 @@ protected void closeAlternates(final ObjectDatabase[] alt) {
 	}
 
 	@Override
-	public void updateInfoCache() {
+	public void updateInfoCache() throws IOException {
 		odb.updateInfoCache();
 	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
index 68ff523..5ded7bb 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
@@ -78,8 +78,9 @@ protected ObjectDatabase() {
 	 * Creates the caches that are typically done by 
 	 * update-server-info, namely objects/info/packs and 
 	 * info/refs
+	 * @throws IOException 
 	 */
-	public abstract void updateInfoCache();
+	public abstract void updateInfoCache() throws IOException;
 	
 	/**
 	 * Does this database exist yet?
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
index a90ae00..95618b9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
@@ -516,7 +516,7 @@ boolean tryAgain(final long currLastModified) {
 	}
 
 	@Override
-	public void updateInfoCache() {
-		new UpdateDirectoryInfoCache(this.listLocalPacks(), this.infoDirectory).execute();
+	public void updateInfoCache() throws IOException {
+		new UpdateDirectoryInfoCache(this.listLocalPacks(), new File(this.infoDirectory, "packs")).execute();
 	}
 }
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 17/19] added call to update the info refs file
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-17-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../org/spearce/jgit/transport/ReceivePack.java    |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
index baa1dec..0c818d9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -523,6 +523,16 @@ void sendString(final String s) throws IOException {
 
 			postReceive.onPostReceive(this, filterCommands(Result.OK));
 			updateObjectInfoCache();
+			updateInfoRefsCache();
+		}
+	}
+
+	private void updateInfoRefsCache() {
+		try{
+			getRepository().getInfoDatabase().updateInfoCache(getRepository().getAllRefs().values());
+		}
+		catch (IOException e){
+			sendMessage("error updating info/refs: " + e.getMessage());
 		}
 	}
 
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 14/19] pulled out some helper functions that will be useful for other tests
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-14-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   21 ++-----------------
 .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   20 ++++++++++++++++++-
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
index b27f2f8..4fecce7 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
@@ -4,7 +4,6 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.UUID;
 
 import org.spearce.jgit.util.JGitTestUtil;
 
@@ -19,13 +18,13 @@
 
 	@Override
 	protected void setUp() throws Exception {
-		testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString());
+		testDir = JGitTestUtil.generateTempDirectoryFileObject();
 	}
-	
+
 	@Override
 	protected void tearDown() throws Exception {
 		if (testDir.exists()){
-			deleteDir(testDir);
+			JGitTestUtil.deleteDir(testDir);
 		}
 	}
 
@@ -93,20 +92,6 @@ public void testUpdateInfoCacheCreatesPacksAndRefsFile() throws Exception {
 		assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
 	}
 	
-	public boolean deleteDir(File dir) {
-        if (dir.isDirectory()) {
-            String[] children = dir.list();
-            for (int i=0; i<children.length; i++) {
-                boolean success = deleteDir(new File(dir, children[i]));
-                if (!success) {
-                    return false;
-                }
-            }
-        }
-        // The directory is now empty so delete it
-        return dir.delete();
-    }
-
 	private void createTestDir(){
 		testDir.mkdir();
 	}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
index b958282..7506553 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
@@ -40,7 +40,6 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
@@ -48,6 +47,7 @@
 import java.io.OutputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.UUID;
 
 public abstract class JGitTestUtil {
 	public static final String CLASSPATH_TO_RESOURCES = "org/spearce/jgit/test/resources/";
@@ -105,4 +105,22 @@ public static String readFileAsString(final File file)
 	private static ClassLoader cl() {
 		return JGitTestUtil.class.getClassLoader();
 	}
+
+	public static boolean deleteDir(File dir) {
+	    if (dir.isDirectory()) {
+	        String[] children = dir.list();
+	        for (int i=0; i<children.length; i++) {
+	            boolean success = deleteDir(new File(dir, children[i]));
+	            if (!success) {
+	                return false;
+	            }
+	        }
+	    }
+	    // The directory is now empty so delete it
+	    return dir.delete();
+	}
+
+	public static File generateTempDirectoryFileObject() {
+		return new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString());
+	}
 }
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 19/19] changed \r to \n per compliance with real git
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-19-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/PacksFileContentsCreatorTest.java     |    9 +++++----
 .../spearce/jgit/lib/PacksFileContentsCreator.java |    3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
index 8dc9109..bf61a59 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
@@ -53,7 +53,7 @@ public void testGettingPacksContentsSinglePack() throws Exception {
 		List<PackFile> packs = new ArrayList<PackFile>();
 		packs.add(new PackFile(TEST_IDX, TEST_PACK));
 		
-		assertEquals("P " + TEST_PACK.getName() + '\r', new PacksFileContentsCreator(packs).toString());
+		assertEquals("P " + TEST_PACK.getName() + "\n\n", new PacksFileContentsCreator(packs).toString());
 	}
 	
 	public void testGettingPacksContentsMultiplePacks() throws Exception {
@@ -63,9 +63,10 @@ public void testGettingPacksContentsMultiplePacks() throws Exception {
 		packs.add(new PackFile(TEST_IDX, TEST_PACK));
 		
 		StringBuilder expected = new StringBuilder();
-		expected.append("P ").append(TEST_PACK.getName()).append("\r");
-		expected.append("P ").append(TEST_PACK.getName()).append("\r");
-		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		expected.append("P ").append(TEST_PACK.getName()).append('\n');
+		expected.append("P ").append(TEST_PACK.getName()).append('\n');
+		expected.append("P ").append(TEST_PACK.getName()).append('\n');
+		expected.append('\n');
 		
 		assertEquals(expected.toString(), new PacksFileContentsCreator(packs).toString());
 	}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
index 0efc244..e8b90a2 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
@@ -49,8 +49,9 @@ public PacksFileContentsCreator(List<PackFile> packs) {
 	public String toString(){
 		StringBuilder builder = new StringBuilder();
 		for (PackFile packFile : packs) {
-			builder.append("P ").append(packFile.getPackFile().getName()).append('\r');
+			builder.append("P ").append(packFile.getPackFile().getName()).append('\n');
 		}
+		builder.append('\n');
 		return builder.toString();
 	}
 
-- 
1.6.4.2

^ permalink raw reply related

* [PATCH JGit 16/19] added tests for the file based info cache update and made pass
From: mr.gaffo @ 2009-09-13 18:44 UTC (permalink / raw)
  To: git; +Cc: mike.gaffney
In-Reply-To: <1252867475-858-16-git-send-email-mr.gaffo@gmail.com>

From: mike.gaffney <mike.gaffney@asolutions.com>

---
 .../jgit/lib/InfoDirectoryDatabaseTest.java        |   30 ++++++++++++++++++++
 .../src/org/spearce/jgit/lib/InfoDatabase.java     |   15 ++++++++++
 .../spearce/jgit/lib/InfoDirectoryDatabase.java    |   15 ++++++++++
 3 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java
index 2b7fb5b..22972fa 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java
@@ -1,6 +1,10 @@
 package org.spearce.jgit.lib;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
 
 import org.spearce.jgit.util.JGitTestUtil;
 
@@ -27,4 +31,30 @@ public void testCreateCreatesDirectory() throws Exception {
 		new InfoDirectoryDatabase(testDir).create();
 		assertTrue(testDir.exists());
 	}
+	
+	public void testUpdateInfoCache() throws Exception {
+		Collection<Ref> refs = new ArrayList<Ref>();
+		refs.add(new Ref(Ref.Storage.LOOSE, "refs/heads/master", ObjectId.fromString("32aae7aef7a412d62192f710f2130302997ec883")));
+		refs.add(new Ref(Ref.Storage.LOOSE, "refs/heads/development", ObjectId.fromString("184063c9b594f8968d61a686b2f6052779551613")));
+
+		File expectedFile = new File(testDir, "refs");
+		assertFalse(expectedFile.exists());
+		
+		
+		final StringWriter expectedString = new StringWriter();
+		new RefWriter(refs) {
+			@Override
+			protected void writeFile(String file, byte[] content) throws IOException {
+				expectedString.write(new String(content));
+			}
+		}.writeInfoRefs();
+		
+		InfoDirectoryDatabase out = new InfoDirectoryDatabase(testDir);
+		out.create();
+		out.updateInfoCache(refs);
+		assertTrue(expectedFile.exists());
+		
+		String actual = JGitTestUtil.readFileAsString(expectedFile);
+		assertEquals(expectedString.toString(), actual);
+	}
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
index 2f1f398..26f8f22 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
@@ -1,8 +1,23 @@
 package org.spearce.jgit.lib;
 
+import java.io.IOException;
+import java.util.Collection;
+
 public abstract class InfoDatabase {
 
+	/**
+	 * Create the info database
+	 */
 	public void create() {
 	}
 
+	/**
+	 * Updates the info cache typically done by update-server-info command.
+	 * This writes THIS repository's refs out to the info/refs file.
+	 * @param collection the collections of refs to update the info cache with
+	 * @throws IOException for any type of failure on the local or remote 
+	 * 					   data store
+	 */
+	public abstract void updateInfoCache(Collection<Ref> collection) throws IOException;
+
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
index 20d8a70..f95be2f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
@@ -1,6 +1,9 @@
 package org.spearce.jgit.lib;
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Collection;
 
 public class InfoDirectoryDatabase extends InfoDatabase {
 
@@ -15,4 +18,16 @@ public void create() {
 		info.mkdirs();
 	}
 
+	@Override
+	public void updateInfoCache(Collection<Ref> refs) throws IOException {
+		new RefWriter(refs) {
+			@Override
+			protected void writeFile(String file, byte[] content) throws IOException {
+				FileOutputStream fos = new FileOutputStream(new File(info, "refs"));
+				fos.write(content);
+				fos.close();
+			}
+		}.writeInfoRefs();
+	}
+
 }
-- 
1.6.4.2

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox