* [PATCH 06/15] Test for WIN32 instead of __MINGW32_
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>
From: Frank Li <lznuaa@gmail.com>
The code which is conditional on MinGW32 is actually conditional on Windows.
Use the WIN32 symbol, which is defined by the MINGW32 and MSVC environments,
but not by Cygwin.
Define SNPRINTF_SIZE_CORR=1 for MSVC too, as its vsnprintf function does
not add NUL at the end of the buffer if the result fits the buffer size
exactly.
Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
compat/snprintf.c | 10 ++++++----
help.c | 2 +-
| 4 ++--
run-command.c | 8 ++++----
run-command.h | 2 +-
setup.c | 2 +-
6 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/compat/snprintf.c b/compat/snprintf.c
index 4d07087..e1e0e75 100644
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
@@ -2,12 +2,14 @@
/*
* The size parameter specifies the available space, i.e. includes
- * the trailing NUL byte; but Windows's vsnprintf expects the
- * number of characters to write, and does not necessarily write the
- * trailing NUL.
+ * the trailing NUL byte; but Windows's vsnprintf uses the entire
+ * buffer and avoids the trailing NUL, should the buffer be exactly
+ * big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will
+ * therefore remove 1 byte from the reported buffer size, so we
+ * always have room for a trailing NUL byte.
*/
#ifndef SNPRINTF_SIZE_CORR
-#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
+#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
#define SNPRINTF_SIZE_CORR 1
#else
#define SNPRINTF_SIZE_CORR 0
diff --git a/help.c b/help.c
index fd51b8e..e8db31f 100644
--- a/help.c
+++ b/help.c
@@ -126,7 +126,7 @@ static int is_executable(const char *name)
!S_ISREG(st.st_mode))
return 0;
-#ifdef __MINGW32__
+#ifdef WIN32
{ /* cannot trust the executable bit, peek into the file instead */
char buf[3] = { 0 };
int n;
--git a/pager.c b/pager.c
index f416d38..86facec 100644
--- a/pager.c
+++ b/pager.c
@@ -9,7 +9,7 @@
static int spawned_pager;
-#ifndef __MINGW32__
+#ifndef WIN32
static void pager_preexec(void)
{
/*
@@ -72,7 +72,7 @@ void setup_pager(void)
static const char *env[] = { "LESS=FRSX", NULL };
pager_process.env = env;
}
-#ifndef __MINGW32__
+#ifndef WIN32
pager_process.preexec_cb = pager_preexec;
#endif
if (start_command(&pager_process))
diff --git a/run-command.c b/run-command.c
index bb76750..cf2d8f7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -75,7 +75,7 @@ fail_pipe:
trace_argv_printf(cmd->argv, "trace: run_command:");
-#ifndef __MINGW32__
+#ifndef WIN32
fflush(NULL);
cmd->pid = fork();
if (!cmd->pid) {
@@ -315,7 +315,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
return run_command(&cmd);
}
-#ifdef __MINGW32__
+#ifdef WIN32
static unsigned __stdcall run_thread(void *data)
{
struct async *async = data;
@@ -331,7 +331,7 @@ int start_async(struct async *async)
return error("cannot create pipe: %s", strerror(errno));
async->out = pipe_out[0];
-#ifndef __MINGW32__
+#ifndef WIN32
/* Flush stdio before fork() to avoid cloning buffers */
fflush(NULL);
@@ -360,7 +360,7 @@ int start_async(struct async *async)
int finish_async(struct async *async)
{
-#ifndef __MINGW32__
+#ifndef WIN32
int ret = wait_or_whine(async->pid, "child process", 0);
#else
DWORD ret = 0;
diff --git a/run-command.h b/run-command.h
index 0c00b25..fb34209 100644
--- a/run-command.h
+++ b/run-command.h
@@ -70,7 +70,7 @@ struct async {
int (*proc)(int fd, void *data);
void *data;
int out; /* caller reads from here and closes it */
-#ifndef __MINGW32__
+#ifndef WIN32
pid_t pid;
#else
HANDLE tid;
diff --git a/setup.c b/setup.c
index e3781b6..029371e 100644
--- a/setup.c
+++ b/setup.c
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
{
static char path[PATH_MAX];
-#ifndef __MINGW32__
+#ifndef WIN32
if (!pfx || !*pfx || is_absolute_path(arg))
return arg;
memcpy(path, pfx, pfx_len);
--
1.6.2.1.418.g33d56.dirty
^ permalink raw reply related
* [PATCH v4 00/15] Build Git with MSVC
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen
=== V4 2009.09.16 ===
1) Removed the _fmode extern, and if(std*) statements, as pointed out
by Alexey Borzenkov.
2) Renumbered the points in the compat/vcbuild/README (affects 2
patches), as pointed out by Thiago Farina.
3) Added flag to lib command to invoke the Link Time Code Generation
to avoid warnings about restarting the libifier with this option.
4) Added a patch to the end of the series, which tags the GIT_VERSION
with ".MSVC", to ease debugging/problem solving on Windows, when we
start getting reports from both MSysGit and MSVCGit people.
NOTE: If people are OK with this patch, it should probably be
squashed into patch 12. If not, just skip it.
The overall difference between v4 and v3 of this series is rather small
but since it touches several patches due to context (thus conflicts
appear), I push out a new version of the whole serie.
v3 to v4 diff:
diff --git a/Makefile b/Makefile
index 761cef1..2c20922 100644
--- a/Makefile
+++ b/Makefile
@@ -878,6 +878,7 @@ ifneq (,$(findstring CYGWIN,$(uname_S)))
UNRELIABLE_FSTAT = UnfortunatelyYes
endif
ifdef MSVC
+ GIT_VERSION := $(GIT_VERSION).MSVC
pathsep = ;
NO_PREAD = YesPlease
NO_OPENSSL = YesPlease
@@ -923,6 +924,7 @@ ifdef MSVC
ifndef DEBUG
BASIC_CFLAGS += -GL -Os -MT
BASIC_LDFLAGS += -LTCG
+ AR += -LTCG
else
BASIC_CFLAGS += -Zi -MTd
endif
diff --git a/compat/mingw.h b/compat/mingw.h
index 544b576..5b5258b 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -229,20 +229,17 @@ void free_environ(char **env);
/*
* A replacement of main() that ensures that argv[0] has a path
+ * and that default fmode and std(in|out|err) are in binary mode
*/
-extern int _fmode;
#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(); \
int main(int argc, const char **argv) \
{ \
_fmode = _O_BINARY; \
- if (stdin) \
- _setmode(_fileno(stdin), _O_BINARY); \
- if (stdout) \
- _setmode(_fileno(stdout), _O_BINARY); \
- if (stderr) \
- _setmode(_fileno(stderr), _O_BINARY); \
+ _setmode(_fileno(stdin), _O_BINARY); \
+ _setmode(_fileno(stdout), _O_BINARY); \
+ _setmode(_fileno(stderr), _O_BINARY); \
argv[0] = xstrdup(_pgmptr); \
return mingw_main(argc, argv); \
} \
diff --git a/compat/vcbuild/README b/compat/vcbuild/README
index e64f7e5..df8a657 100644
--- a/compat/vcbuild/README
+++ b/compat/vcbuild/README
@@ -29,11 +29,11 @@ The Steps of Build Git with VS2008
executables, since Git might need to run scripts which are part of
the git operations.
-4. Inside Git's directory run the command:
+3. Inside Git's directory run the command:
make common-cmds.h
to generate the common-cmds.h file needed to compile git.
-5. Then either build Git with the GNU Make Makefile in the Git projects
+4. Then either build Git with the GNU Make Makefile in the Git projects
root
make MSVC=1
or generate Visual Studio solution/projects (.sln/.vcproj) with the
--
EOD
=== V3 2009.09.15 ===
1) Reworded patch 01: s/Microsoft Visual C++/MSVC/
2) Nuked patch 02
3) Merged patch 03 into path 08
4) Rewrote patch 06 to set _fmode instead for both MinGW and MSVC
5) Fix patch 07 to use __stdcall for thread functions instead of WINAPI
6) Rewrote patch 14 to rather use a define to _chsize
7) Fix patch 15 to use "-o $@" instead of "-o git.o"
Think that's it..
=== V2 2009.09.14 ===
Here's a second roll of the series for supporting compilation of Git
using Visual C++ (MSVC). (Sorry for the long delay on a followup, time
is in short supply these days)
There's no guarantee that the compiled result will work as well as the
current MinGW compile, or at all. However, I think it's important to
get the Git repo to a compilable state with MSVC as quickly as
possible, to further enable contributions from the Windows developers
which we are sorely lacking at the moment.
I hope that a repo which compiles successfully with the tools they are
accustomed to (also a very good debugger) will entice them to send more
patches.
In addition to this series, I have also setup a repo with binaries of
the required libs to compile Git with MSVC. Only 32bit versions for now.
So, the developer can choose to either use that, or Frank's source code
repo to build Git with MSVC. You'll find the binary repo here:
http://repo.or.cz/w/msvcgit.git
Note that the binaries will still require the msysgit environment for
execution, due to the non-binary components of Git. (Scripts, gitk,
git-gui, etc). You'll find that repo here:
http://repo.or.cz/w/msysgit.git
1) Rebased ontop on current git.git 'next'.
2) Fixed code and commit msgs based on the previous feedback.
Let me know if I forgot anything!
3) Added a proper Makefile patch for MSVC support.
You now compile with 'make MSVC=1'.
4) Added perl scripts (contrib) which uses GNU Make output to generate
MSVC IDE (.sln & .vcproj) projects and QMake projects, and picking
up the project settings from the Makefile, so it's all in one place.
5) Added necessary patches to make things compile ontop of current
'next'.
=== V1 2009.08.21 ===
So, Frank Li started this series, and I took it upon my self to help
out a bit; cleaning, reorganizing, rebasing the series. Hopefully
we're now a bit closer to including the series into mainline..
Here's a summary of what has happend:
1) This series is rebased ontop of git.git 'next', which needed an
extra patch to avoid a non-constant array creation, which
mscv doesn't like.
2) I've polished (tied to anyways) the commit messages a bit.
3) I've applied much of the feedback provided to the first round of
the patches.
4) I've split, merged and reordered some of the patches, so things
that belong together are in the same commits, and in a order of
'importance'
5) I've removed the
#define func _func
stuff, as it's not needed and Microsoft cannot really kill the
compatibility functions anyways. So, adding the define
_CRT_NONSTDC_NO_DEPRECATE
will kill the warnings seen without the defines above.
6) ..probably much more as well, but I forget..
Note: I did not sign off on the last two commits, which involve the
adding of the vcproj files, since I don't agree on adding them as is.
We need a Makefile way of compiling primarily, and second, a script
to generate the vcproj, as already discussed. But the commits are
included for completeness, at to let others compile and play with it.
I've kept the original author as is, and just signed the patches..
Thanks for watching, now bring on the comments!
Frank Li (6):
Avoid declaration after statement
Change regerror() declaration from K&R style to ANSI C (C89)
Fix __stdcall placement and function prototype
Test for WIN32 instead of __MINGW32_
Add MinGW header files to build git with MSVC
Add platform files for MSVC porting
Marius Storm-Olsen (9):
Add define guards to compat/win32.h
Set _O_BINARY as default fmode for both MinGW and MSVC
Add empty header files for MSVC port
Make usage of windows.h lean and mean
Define strncasecmp and ftruncate for MSVC
Add MSVC to Makefile
Add README for MSVC build
Add scripts to generate projects for other buildsystems (MSVC vcproj,
QMake)
Tag GIT_VERSION when Git is built with MSVC
.gitignore | 11 +
Makefile | 56 +++-
compat/mingw.c | 20 +-
compat/mingw.h | 7 +
compat/msvc.c | 35 ++
compat/msvc.h | 50 +++
compat/regex/regex.c | 7 +-
compat/snprintf.c | 10 +-
compat/vcbuild/README | 50 +++
compat/vcbuild/include/alloca.h | 1 +
compat/vcbuild/include/arpa/inet.h | 1 +
compat/vcbuild/include/dirent.h | 128 ++++++
compat/vcbuild/include/grp.h | 1 +
compat/vcbuild/include/inttypes.h | 1 +
compat/vcbuild/include/netdb.h | 1 +
compat/vcbuild/include/netinet/in.h | 1 +
compat/vcbuild/include/netinet/tcp.h | 1 +
compat/vcbuild/include/pwd.h | 1 +
compat/vcbuild/include/sys/ioctl.h | 1 +
compat/vcbuild/include/sys/param.h | 1 +
compat/vcbuild/include/sys/poll.h | 1 +
compat/vcbuild/include/sys/select.h | 1 +
compat/vcbuild/include/sys/socket.h | 1 +
compat/vcbuild/include/sys/time.h | 1 +
compat/vcbuild/include/sys/utime.h | 34 ++
compat/vcbuild/include/sys/wait.h | 1 +
compat/vcbuild/include/unistd.h | 92 ++++
compat/vcbuild/include/utime.h | 1 +
compat/vcbuild/scripts/clink.pl | 48 +++
compat/vcbuild/scripts/lib.pl | 26 ++
compat/win32.h | 7 +
compat/winansi.c | 1 -
contrib/buildsystems/Generators.pm | 42 ++
contrib/buildsystems/Generators/QMake.pm | 189 +++++++++
contrib/buildsystems/Generators/Vcproj.pm | 639 +++++++++++++++++++++++++++++
contrib/buildsystems/engine.pl | 353 ++++++++++++++++
contrib/buildsystems/generate | 29 ++
contrib/buildsystems/parse.pl | 228 ++++++++++
git-compat-util.h | 9 +
help.c | 5 +-
| 4 +-
run-command.c | 12 +-
run-command.h | 2 +-
setup.c | 2 +-
thread-utils.c | 5 +-
45 files changed, 2084 insertions(+), 33 deletions(-)
create mode 100644 compat/msvc.c
create mode 100644 compat/msvc.h
create mode 100644 compat/vcbuild/README
create mode 100644 compat/vcbuild/include/alloca.h
create mode 100644 compat/vcbuild/include/arpa/inet.h
create mode 100644 compat/vcbuild/include/dirent.h
create mode 100644 compat/vcbuild/include/grp.h
create mode 100644 compat/vcbuild/include/inttypes.h
create mode 100644 compat/vcbuild/include/netdb.h
create mode 100644 compat/vcbuild/include/netinet/in.h
create mode 100644 compat/vcbuild/include/netinet/tcp.h
create mode 100644 compat/vcbuild/include/pwd.h
create mode 100644 compat/vcbuild/include/sys/ioctl.h
create mode 100644 compat/vcbuild/include/sys/param.h
create mode 100644 compat/vcbuild/include/sys/poll.h
create mode 100644 compat/vcbuild/include/sys/select.h
create mode 100644 compat/vcbuild/include/sys/socket.h
create mode 100644 compat/vcbuild/include/sys/time.h
create mode 100644 compat/vcbuild/include/sys/utime.h
create mode 100644 compat/vcbuild/include/sys/wait.h
create mode 100644 compat/vcbuild/include/unistd.h
create mode 100644 compat/vcbuild/include/utime.h
create mode 100644 compat/vcbuild/scripts/clink.pl
create mode 100644 compat/vcbuild/scripts/lib.pl
create mode 100644 contrib/buildsystems/Generators.pm
create mode 100644 contrib/buildsystems/Generators/QMake.pm
create mode 100644 contrib/buildsystems/Generators/Vcproj.pm
create mode 100644 contrib/buildsystems/engine.pl
create mode 100644 contrib/buildsystems/generate
create mode 100644 contrib/buildsystems/parse.pl
^ permalink raw reply related
* [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen, Marius Storm-Olsen
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>
From: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
MinGW set the _CRT_fmode to set both the default fmode and
_O_BINARY on stdin/stdout/stderr. Rather use the main()
define in mingw.h to set this for both MinGW and MSVC.
This will ensure that a MinGW and MSVC build will handle
input and output identically.
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
compat/mingw.c | 2 --
compat/mingw.h | 5 +++++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 5478b74..5a8fae8 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -3,8 +3,6 @@
#include <conio.h>
#include "../strbuf.h"
-unsigned int _CRT_fmode = _O_BINARY;
-
static int err_win_to_posix(DWORD winerr)
{
int error = ENOSYS;
diff --git a/compat/mingw.h b/compat/mingw.h
index c43917c..bcd23b0 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -227,12 +227,17 @@ void free_environ(char **env);
/*
* A replacement of main() that ensures that argv[0] has a path
+ * and that default fmode and std(in|out|err) are in binary mode
*/
#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(); \
int main(int argc, const char **argv) \
{ \
+ _fmode = _O_BINARY; \
+ _setmode(_fileno(stdin), _O_BINARY); \
+ _setmode(_fileno(stdout), _O_BINARY); \
+ _setmode(_fileno(stderr), _O_BINARY); \
argv[0] = xstrdup(_pgmptr); \
return mingw_main(argc, argv); \
} \
--
1.6.2.1.418.g33d56.dirty
^ permalink raw reply related
* [PATCH 02/15] Add define guards to compat/win32.h
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
compat/win32.h | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/compat/win32.h b/compat/win32.h
index c26384e..e8c178d 100644
--- a/compat/win32.h
+++ b/compat/win32.h
@@ -1,3 +1,6 @@
+#ifndef WIN32_H
+#define WIN32_H
+
/* common Win32 functions for MinGW and Cygwin */
#include <windows.h>
@@ -32,3 +35,5 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd
return ENOENT;
}
}
+
+#endif
--
1.6.2.1.418.g33d56.dirty
^ permalink raw reply related
* [PATCH 03/15] Change regerror() declaration from K&R style to ANSI C (C89)
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>
From: Frank Li <lznuaa@gmail.com>
The MSVC headers typedef errcode as int, and thus confused the
compiler in the K&R style definition. ANSI style deconfuses it.
Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
compat/regex/regex.c | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index 5ea0075..67d5c37 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -4852,11 +4852,8 @@ regexec (preg, string, nmatch, pmatch, eflags)
from either regcomp or regexec. We don't use PREG here. */
size_t
-regerror (errcode, preg, errbuf, errbuf_size)
- int errcode;
- const regex_t *preg;
- char *errbuf;
- size_t errbuf_size;
+regerror(int errcode, const regex_t *preg,
+ char *errbuf, size_t errbuf_size)
{
const char *msg;
size_t msg_size;
--
1.6.2.1.418.g33d56.dirty
^ permalink raw reply related
* [PATCH 01/15] Avoid declaration after statement
From: Marius Storm-Olsen @ 2009-09-16 8:20 UTC (permalink / raw)
To: git
Cc: Johannes.Schindelin, msysgit, gitster, j6t, lznuaa, raa.lkml,
snaury, Marius Storm-Olsen
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>
From: Frank Li <lznuaa@gmail.com>
MSVC does not understand this C99 style
Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
compat/mingw.c | 14 ++++++++++----
help.c | 3 ++-
run-command.c | 2 ++
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 36ef8d3..5478b74 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -123,13 +123,17 @@ int mingw_open (const char *filename, int oflags, ...)
{
va_list args;
unsigned mode;
+ int fd;
+
va_start(args, oflags);
mode = va_arg(args, int);
va_end(args);
if (!strcmp(filename, "/dev/null"))
filename = "nul";
- int fd = open(filename, oflags, mode);
+
+ fd = open(filename, oflags, mode);
+
if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
DWORD attrs = GetFileAttributes(filename);
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
@@ -580,10 +584,11 @@ static char **get_path_split(void)
static void free_path_split(char **path)
{
+ char **p = path;
+
if (!path)
return;
- char **p = path;
while (*p)
free(*p++);
free(path);
@@ -1120,9 +1125,9 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out)
#undef signal
sig_handler_t mingw_signal(int sig, sig_handler_t handler)
{
+ sig_handler_t old = timer_fn;
if (sig != SIGALRM)
return signal(sig, handler);
- sig_handler_t old = timer_fn;
timer_fn = handler;
return old;
}
@@ -1209,8 +1214,9 @@ struct dirent *mingw_readdir(DIR *dir)
if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)
{
+ DWORD lasterr;
handle = FindFirstFileA(dir->dd_name, &buf);
- DWORD lasterr = GetLastError();
+ lasterr = GetLastError();
dir->dd_handle = (long)handle;
if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
errno = err_win_to_posix(lasterr);
diff --git a/help.c b/help.c
index 294337e..fd51b8e 100644
--- a/help.c
+++ b/help.c
@@ -127,7 +127,7 @@ static int is_executable(const char *name)
return 0;
#ifdef __MINGW32__
- /* cannot trust the executable bit, peek into the file instead */
+{ /* cannot trust the executable bit, peek into the file instead */
char buf[3] = { 0 };
int n;
int fd = open(name, O_RDONLY);
@@ -140,6 +140,7 @@ static int is_executable(const char *name)
st.st_mode |= S_IXUSR;
close(fd);
}
+}
#endif
return st.st_mode & S_IXUSR;
}
diff --git a/run-command.c b/run-command.c
index ac314a5..02aaedf 100644
--- a/run-command.c
+++ b/run-command.c
@@ -134,6 +134,7 @@ fail_pipe:
error("cannot fork() for %s: %s", cmd->argv[0],
strerror(failed_errno = errno));
#else
+{
int s0 = -1, s1 = -1, s2 = -1; /* backups of stdin, stdout, stderr */
const char **sargv = cmd->argv;
char **env = environ;
@@ -197,6 +198,7 @@ fail_pipe:
dup2(s1, 1), close(s1);
if (s2 >= 0)
dup2(s2, 2), close(s2);
+}
#endif
if (cmd->pid < 0) {
--
1.6.2.1.418.g33d56.dirty
^ permalink raw reply related
* Re: self contained executable
From: Alex Riesen @ 2009-09-16 8:13 UTC (permalink / raw)
To: Joel Saltzman; +Cc: git
In-Reply-To: <ED42F58A-A814-467B-A37D-B485B2E267ED@gmail.com>
On Wed, Sep 16, 2009 at 09:45, Joel Saltzman <saltzmanjoelh@gmail.com> wrote:
> is it possible to compile git with all its dependencies so I can run it on a
> server that does not have root access?
This is kind of default configuration (the install prefix is $HOME/,
and everthing gets
installed into ~/bin, ~/share, etc). But if you don't have some of the
libraries (libcurl
for http, eventually openssl and iconv) you can always provide them locally and
set the appropriate compile and linking flags in config.mak (but see
the Makefile
for the variables to set).
^ permalink raw reply
* [RFC/PATCH 1/2] ref-dict: Add a set of functions for working with a ref dictionary
From: Julian Phillips @ 2009-09-16 7:53 UTC (permalink / raw)
To: git
In-Reply-To: <20090916074737.58044.42776.julian@quantumfyre.co.uk>
These are a set of helper functions that use the generic hash table
functions to provide a quick and easy mapping from ref name to sha1.
Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
---
Makefile | 1 +
ref-dict.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ref-dict.h | 13 ++++++++++
3 files changed, 90 insertions(+), 0 deletions(-)
create mode 100644 ref-dict.c
create mode 100644 ref-dict.h
diff --git a/Makefile b/Makefile
index d4958b8..815e4c9 100644
--- a/Makefile
+++ b/Makefile
@@ -531,6 +531,7 @@ LIB_OBJS += reachable.o
LIB_OBJS += read-cache.o
LIB_OBJS += reflog-walk.o
LIB_OBJS += refs.o
+LIB_OBJS += ref-dict.o
LIB_OBJS += remote.o
LIB_OBJS += replace_object.o
LIB_OBJS += rerere.o
diff --git a/ref-dict.c b/ref-dict.c
new file mode 100644
index 0000000..b9cab4b
--- /dev/null
+++ b/ref-dict.c
@@ -0,0 +1,76 @@
+/*
+ * ref-dict.c
+ *
+ * A Hash-based dictionary for storing name-sha1 data for refs.
+ *
+ * Copyright (C) 2009 Julian Phillips
+ */
+
+#include "cache.h"
+#include "hash.h"
+#include "remote.h"
+#include "ref-dict.h"
+
+/* hash_name based on the function of the same name in name-hash.c */
+static unsigned int hash_name(const char *name)
+{
+ unsigned int hash = 0x123;
+ int namelen = strlen(name);
+
+ do {
+ unsigned char c = *name++;
+ hash = hash*101 + c;
+ } while (--namelen);
+ return hash;
+}
+
+/*
+ * A convienience function for creating a ref_dict from a ref_list.
+ */
+void ref_dict_create(struct hash_table *dict, const struct ref *ref_list)
+{
+ struct ref *ref;
+
+ init_hash(dict);
+
+ for (ref = (struct ref *)ref_list; ref; ref = ref->next) {
+ ref_dict_add(dict, ref->name, ref->old_sha1);
+ }
+}
+
+/*
+ * Add an entry to the ref_dict, recording that name maps to sha1.
+ */
+void ref_dict_add(struct hash_table *dict, const char *name,
+ const unsigned char *sha1)
+{
+ struct ref **ref;
+ struct ref *new_ref = alloc_ref(name);
+
+ hashcpy(new_ref->old_sha1, sha1);
+
+ ref = (struct ref **)insert_hash(hash_name(name), new_ref, dict);
+ if (ref) {
+ new_ref->next = *ref;
+ *ref = new_ref;
+ }
+}
+
+/*
+ * Find the sha1 for the given name. Returns 1 if found and copies the sha1
+ * into the space pointed to by sha1, returns 0 otherwise and sha1 is untouched.
+ */
+int ref_dict_get(const struct hash_table *dict, const char *name,
+ unsigned char *sha1)
+{
+ struct ref *ref = lookup_hash(hash_name(name), dict);
+
+ for (; ref; ref = ref->next) {
+ if (!strcmp(name, ref->name)) {
+ hashcpy(sha1, ref->old_sha1);
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/ref-dict.h b/ref-dict.h
new file mode 100644
index 0000000..ca1e9a7
--- /dev/null
+++ b/ref-dict.h
@@ -0,0 +1,13 @@
+#ifndef REF_DICT_H
+#define REF_DICT_H
+
+#include "cache.h"
+#include "hash.h"
+
+void ref_dict_create(struct hash_table *dict, const struct ref *ref_list);
+void ref_dict_add(struct hash_table *dict, const char *name,
+ const unsigned char *sha1);
+int ref_dict_get(const struct hash_table *dict, const char *name,
+ unsigned char *sha1);
+
+#endif /* REF_DICT_H */
--
1.6.4.2
^ permalink raw reply related
* [RFC/PATCH 0/2] Speed up fetch with large number of tags
From: Julian Phillips @ 2009-09-16 7:53 UTC (permalink / raw)
To: git
I have a repository at $dayjob where fetch was taking ~30s to tell me
that there were no updates.
It turns out that I appear to have added a nasty linear search of all
remote refs for every commit (i.e. tag^{}) tag ref way back in the
original C implementation of fetch. This doesn't scale well to large
numbers of refs, so this replaces it with a hash table based lookup
instead, which brings the time down to a few seconds even for very large
ref counts.
I haven't tested it with non-native transports, but there is no reason
to believe that the code should be transport specific.
Julian Phillips (2):
ref-dict: Add a set of functions for working with a ref dictionary
fetch: Speed up fetch by using ref dictionary
Makefile | 1 +
builtin-fetch.c | 19 ++++++-------
ref-dict.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
ref-dict.h | 13 +++++++++
4 files changed, 99 insertions(+), 10 deletions(-)
create mode 100644 ref-dict.c
create mode 100644 ref-dict.h
^ permalink raw reply
* [RFC/PATCH 2/2] fetch: Speed up fetch by using ref dictionary
From: Julian Phillips @ 2009-09-16 7:53 UTC (permalink / raw)
To: git
In-Reply-To: <20090916074737.58044.42776.julian@quantumfyre.co.uk>
When trying to get a list of remote tags to see if we need to fetch
any we were doing a linear search for the matching tag ref for the
tag^{} commit entries. This proves to be incredibly slow for large
numbers of tags.
For a repository with 50000 tags (and just a single commit on a single
branch), a fetch that does nothing goes from ~ 1m50s to ~4.5s.
Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
---
builtin-fetch.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index cb48c57..16cfee6 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -11,6 +11,7 @@
#include "run-command.h"
#include "parse-options.h"
#include "sigchain.h"
+#include "ref-dict.h"
static const char * const builtin_fetch_usage[] = {
"git fetch [options] [<repository> <refspec>...]",
@@ -513,12 +514,16 @@ static void find_non_local_tags(struct transport *transport,
char *ref_name;
int ref_name_len;
const unsigned char *ref_sha1;
- const struct ref *tag_ref;
+ unsigned char tag_sha1[40];
struct ref *rm = NULL;
const struct ref *ref;
+ struct hash_table dict;
+ const struct ref *remote_refs = transport_get_remote_refs(transport);
+
+ ref_dict_create(&dict, remote_refs);
for_each_ref(add_existing, &existing_refs);
- for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
+ for (ref = remote_refs; ref; ref = ref->next) {
if (prefixcmp(ref->name, "refs/tags"))
continue;
@@ -528,14 +533,8 @@ static void find_non_local_tags(struct transport *transport,
if (!strcmp(ref_name + ref_name_len - 3, "^{}")) {
ref_name[ref_name_len - 3] = 0;
- tag_ref = transport_get_remote_refs(transport);
- while (tag_ref) {
- if (!strcmp(tag_ref->name, ref_name)) {
- ref_sha1 = tag_ref->old_sha1;
- break;
- }
- tag_ref = tag_ref->next;
- }
+ if (ref_dict_get(&dict, ref_name, tag_sha1))
+ ref_sha1 = tag_sha1;
}
if (!string_list_has_string(&existing_refs, ref_name) &&
--
1.6.4.2
^ permalink raw reply related
* self contained executable
From: Joel Saltzman @ 2009-09-16 7:45 UTC (permalink / raw)
To: git
is it possible to compile git with all its dependencies so I can run
it on a server that does not have root access?
^ permalink raw reply
* git workflow for fully distributed mini-teams
From: Rustom Mody @ 2009-09-16 7:35 UTC (permalink / raw)
To: Git Mailing List
I am trying to formulate (and understand) what it means to have a
fully-distributed mini team workflow with git.
By fully distributed I mean theres no central repo -- not for pushing
or even pulling; all communication is by email.
By mini-team I mean: Not more than 5 programmers.
Heres a typical scenario.
There are 3 programmers A B and C who communicate by email who have
started off from the same code base.
A's branches: dev, master, B, C
B's branches: dev, master, A, C
C's branches: dev, master, A, B
A's best practices (and invariants) are:
I (ie A) develop on dev (or other topic branches).
I only merge onto master; never commit.
I never work on nor merge onto B and C.
When B sends me patches I apply them to the B branch likewise for C.
Thereafter I merge that branch onto dev or master.
There are no tracking branches because there are no remotes -- no
central repo. [not clear about this]
B and C have corresponding practices/behavior.
So the questions...
Is there a better way of doing things?
Can some of these practices/invariants be enforced by scripts/options etc?
What about checkpointing and restoring from botches?
^ permalink raw reply
* Re: Gource - new GL Visualisation for git repositories
From: Mike Hommey @ 2009-09-16 6:40 UTC (permalink / raw)
To: Sam Vilain; +Cc: Git Mailing List
In-Reply-To: <4AB0858E.6040805@vilain.net>
On Wed, Sep 16, 2009 at 06:28:30PM +1200, Sam Vilain wrote:
> A little fun candy to be had here:
>
> http://www.youtube.com/watch?v=GTMC3g2Xy8c
> (HQ version coming, once processing completes...)
>
> Gource is a visualizer written in C++ which shows you the development of
> the source code over time graphically. It's pretty neat. Home page at
> http://code.google.com/p/gource/
Code swarm (http://vis.cs.ucdavis.edu/~ogawa/codeswarm/) gives nice
results, too.
Mike
^ permalink raw reply
* Gource - new GL Visualisation for git repositories
From: Sam Vilain @ 2009-09-16 6:28 UTC (permalink / raw)
To: Git Mailing List
A little fun candy to be had here:
http://www.youtube.com/watch?v=GTMC3g2Xy8c
(HQ version coming, once processing completes...)
Gource is a visualizer written in C++ which shows you the development of
the source code over time graphically. It's pretty neat. Home page at
http://code.google.com/p/gource/
Enjoy,
Sam
^ permalink raw reply
* Re: [PATCH 13/14] Add README for MSVC build
From: Marius Storm-Olsen @ 2009-09-16 5:26 UTC (permalink / raw)
To: Thiago Farina; +Cc: Johannes.Schindelin, msysgit, git, lznuaa, raa.lkml, snaury
In-Reply-To: <a4c8a6d00909151822p6f9d8dffr9391d7e58077de2@mail.gmail.com>
Thiago Farina said the following on 16.09.2009 03:22:
> On Tue, Sep 15, 2009 at 10:44 AM, Marius Storm-Olsen <mstormo@gmail.com> wrote:
>> Based on original README patch from Frank Li
>>
>> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
>> ---
>> compat/vcbuild/README | 39 +++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 39 insertions(+), 0 deletions(-)
>> create mode 100644 compat/vcbuild/README
>>
>> diff --git a/compat/vcbuild/README b/compat/vcbuild/README
>> new file mode 100644
>> index 0000000..5d7a07a
>> --- /dev/null
>> +++ b/compat/vcbuild/README
>> @@ -0,0 +1,39 @@
>> +The Steps of Build Git with VS2008
>> +
>> +1. You need the build environment, which contains the Git dependencies
>> + to be able to compile, link and run Git with MSVC.
>> +
>> + You can either use the binary repository:
>> +
>> + WWW: http://repo.or.cz/w/msvcgit.git
>> + Git: git clone git://repo.or.cz/msvcgit.git
>> + Zip: http://repo.or.cz/w/msvcgit.git?a=snapshot;h=master;sf=zip
>> +
>> + and call the setup_32bit_env.cmd batch script before compiling Git,
>> + (see repo/package README for details), or the source repository:
>> +
>> + WWW: http://repo.or.cz/w/gitbuild.git
>> + Git: git clone git://repo.or.cz/gitbuild.git
>> + Zip: (None, as it's a project with submodules)
>> +
>> + and build the support libs as instructed in that repo/package.
>> +
>> +2. Ensure you have the msysgit environment in your path, so you have
>> + GNU Make, bash and perl available.
>> +
>> + WWW: http://repo.or.cz/w/msysgit.git
>> + Git: git clone git://repo.or.cz/msysgit.git
>> + Zip: http://repo.or.cz/w/msysgit.git?a=snapshot;h=master;sf=zip
>> +
>> + This environment is also needed when you use the resulting
>> + executables, since Git might need to run scripts which are part of
>> + the git operations.
>> +
>> +4. Inside Git's directory run the command:
> Shouldn't be 3.?
>> + make common-cmds.h
>> + to generate the common-cmds.h file needed to compile git.
>> +
>> +5. Then build Git with the GNU Make Makefile in the Git projects root
> 4.?
Heh, you're right.. I've been modifying this file too much lately :-)
--
.marius
^ permalink raw reply
* [PATCH v2 3/4] reset: add option "--merge-safe" to "git reset"
From: Christian Couder @ 2009-09-16 4:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski, Linus Torvalds, Paolo Bonzini
In-Reply-To: <20090916035131.3737.33020.chriscool@tuxfamily.org>
From: Stephan Beyer <s-beyer@gmx.net>
This option is nearly like "--merge" except that it is
safer. The table below show the differences between these
options.
working index HEAD target working index HEAD
B B A A --m-s B A A
--merge A A A
B B A C --m-s (disallowed)
--merge C C C
In this table, A, B and C are some different states of
a file. For example the first 2 lines of the table mean
that if a file is in state B in the working tree and
the index, and in a different state A in HEAD and in
the target, then "git reset --merge-safe target" will
put the file in state B in the working tree and in
state A in the index and HEAD.
So as can be seen in the table, "--merge" discards changes
in the index, while "--merge-safe" does not.
A following patch will add some test cases for
"--merge-safe", where the differences between "--merge"
and "--merge-safe" can also be seen.
The "--merge-safe" option is implemented by doing a 2 way
merge between HEAD and the reset target, and if this
succeeds by doing a mixed reset to the target.
The code comes from the sequencer GSoC project:
git://repo.or.cz/git/sbeyer.git
(at commit 5a78908b70ceb5a4ea9fd4b82f07ceba1f019079)
But in the sequencer project the "reset" flag was set
in the "struct unpack_trees_options" passed to
"unpack_trees()". With this flag the changes in the
working tree were discarded if the file was different
between HEAD and the reset target.
Mentored-by: Daniel Barkalow <barkalow@iabervon.org>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-reset.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/builtin-reset.c b/builtin-reset.c
index ddb81f3..78d42e6 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -22,13 +22,15 @@
#include "cache-tree.h"
static const char * const git_reset_usage[] = {
- "git reset [--mixed | --soft | --hard | --merge] [-q] [<commit>]",
+ "git reset [--mixed | --soft | --hard | --merge | --merge-safe] [-q] [<commit>]",
"git reset [--mixed] <commit> [--] <paths>...",
NULL
};
-enum reset_type { MIXED, SOFT, HARD, MERGE, NONE };
-static const char *reset_type_names[] = { "mixed", "soft", "hard", "merge", NULL };
+enum reset_type { MIXED, SOFT, HARD, MERGE, MERGE_SAFE, NONE };
+static const char *reset_type_names[] = {
+ "mixed", "soft", "hard", "merge", "merge_safe", NULL
+};
static char *args_to_str(const char **argv)
{
@@ -81,6 +83,7 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
if (!quiet)
opts.verbose_update = 1;
switch (reset_type) {
+ case MERGE_SAFE:
case MERGE:
opts.update = 1;
break;
@@ -95,6 +98,16 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
read_cache_unmerged();
+ if (reset_type == MERGE_SAFE) {
+ unsigned char *head_sha1;
+ if (get_sha1("HEAD", head_sha1))
+ return error("You do not have a valid HEAD.");
+ if (parse_and_init_tree_desc(head_sha1, desc))
+ return error("Failed to find tree of HEAD.");
+ nr++;
+ opts.fn = twoway_merge;
+ }
+
if (parse_and_init_tree_desc(sha1, desc + nr - 1))
return error("Failed to find tree of %s.", sha1_to_hex(sha1));
if (unpack_trees(nr, desc, &opts))
@@ -238,6 +251,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
"reset HEAD, index and working tree", HARD),
OPT_SET_INT(0, "merge", &reset_type,
"reset HEAD, index and working tree", MERGE),
+ OPT_SET_INT(0, "merge-safe", &reset_type,
+ "reset HEAD, index and working tree",
+ MERGE_SAFE),
OPT_BOOLEAN('q', NULL, &quiet,
"disable showing new HEAD in hard reset and progress message"),
OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
@@ -324,9 +340,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (reset_type == SOFT) {
if (is_merge() || read_cache() < 0 || unmerged_cache())
die("Cannot do a soft reset in the middle of a merge.");
+ } else {
+ int err = reset_index_file(sha1, reset_type, quiet);
+ if (reset_type == MERGE_SAFE)
+ err = err || reset_index_file(sha1, MIXED, quiet);
+ if (err)
+ die("Could not reset index file to revision '%s'.", rev);
}
- else if (reset_index_file(sha1, reset_type, quiet))
- die("Could not reset index file to revision '%s'.", rev);
/* Any resets update HEAD to the head being switched to,
* saving the previous head in ORIG_HEAD before. */
--
1.6.5.rc0.150.g38fe6
^ permalink raw reply related
* [PATCH v2 4/4] reset: add test cases for "--merge-safe" option
From: Christian Couder @ 2009-09-16 4:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski, Linus Torvalds, Paolo Bonzini
In-Reply-To: <20090916035131.3737.33020.chriscool@tuxfamily.org>
This shows that with the "--merge-safe" option, changes that are
both in the work tree and the index are kept in the work tree after
the reset (but discarded in the index). As with the "--merge" option,
changes that are in both the work tree and the index are discarded
after the reset.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t7110-reset-merge.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index 1ec32f9..5b6db41 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -3,7 +3,7 @@
# Copyright (c) 2009 Christian Couder
#
-test_description='Tests for "git reset --merge"'
+test_description='Tests for "git reset" with --merge and --merge-safe'
. ./test-lib.sh
@@ -30,6 +30,20 @@ test_expect_success 'reset --merge is ok with changes in file it does not touch'
grep 4 file2
'
+test_expect_success 'reset --merge-safe is ok with changes in file it does not touch' '
+ git reset --hard HEAD^ &&
+ echo "line 4" >> file1 &&
+ echo "line 4" >> file2 &&
+ test_tick &&
+ git commit -m "add line 4" file1 &&
+ git reset --merge-safe HEAD^ &&
+ ! grep 4 file1 &&
+ grep 4 file2 &&
+ git reset --merge-safe HEAD@{1} &&
+ grep 4 file1 &&
+ grep 4 file2
+'
+
test_expect_success 'reset --merge discards changes added to index (1)' '
echo "line 5" >> file1 &&
git add file1 &&
@@ -55,13 +69,43 @@ test_expect_success 'reset --merge discards changes added to index (2)' '
grep 4 file1
'
+test_expect_success 'reset --merge-safe fails with changes in index in files it touches' '
+ echo "line 4" >> file2 &&
+ echo "line 5" >> file1 &&
+ git add file1 &&
+ test_must_fail git reset --merge-safe HEAD^ &&
+ git reset --hard HEAD
+'
+
+test_expect_success 'reset --merge-safe keeps changes it does not touch' '
+ echo "line 4" >> file2 &&
+ git add file2 &&
+ git reset --merge-safe HEAD^ &&
+ grep 4 file2 &&
+ git reset --merge-safe HEAD@{1} &&
+ grep 4 file2 &&
+ grep 4 file1 &&
+ git reset --hard HEAD
+'
+
test_expect_success 'reset --merge fails with changes in file it touches' '
- echo "line 6" >> file1 &&
+ echo "line 5" >> file1 &&
test_tick &&
- git commit -m "add line 6" file1 &&
+ git commit -m "add line 5" file1 &&
sed -e "s/line 1/changed line 1/" <file1 >file3 &&
mv file3 file1 &&
test_must_fail git reset --merge HEAD^ 2>err.log &&
+ grep file1 err.log | grep "not uptodate" &&
+ git reset --hard HEAD^
+'
+
+test_expect_success 'reset --merge-safe fails with changes in file it touches' '
+ echo "line 5" >> file1 &&
+ test_tick &&
+ git commit -m "add line 5" file1 &&
+ sed -e "s/line 1/changed line 1/" <file1 >file3 &&
+ mv file3 file1 &&
+ test_must_fail git reset --merge-safe HEAD^ 2>err.log &&
grep file1 err.log | grep "not uptodate"
'
--
1.6.5.rc0.150.g38fe6
^ permalink raw reply related
* [PATCH v2 2/4] reset: use "unpack_trees()" directly instead of "git read-tree"
From: Christian Couder @ 2009-09-16 4:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski, Linus Torvalds, Paolo Bonzini
In-Reply-To: <20090916035131.3737.33020.chriscool@tuxfamily.org>
From: Stephan Beyer <s-beyer@gmx.net>
This patch makes "reset_index_file()" call "unpack_trees()" directly
instead of forking and execing "git read-tree". So the code is more
efficient.
And it's also easier to see which unpack_tree() options will be used,
as we don't need to follow "git read-tree"'s command line parsing
which is quite complex.
As Daniel Barkalow found, there is a difference between this new
version and the old one. The old version gives an error for
"git reset --merge" with unmerged entries and the new version does
not. But this can be seen as a bug fix, because "--merge" was the
only "git reset" option with this behavior and this behavior was
not documented.
The code comes from the sequencer GSoC project:
git://repo.or.cz/git/sbeyer.git
(at commit 5a78908b70ceb5a4ea9fd4b82f07ceba1f019079)
Mentored-by: Daniel Barkalow <barkalow@iabervon.org>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-reset.c | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/builtin-reset.c b/builtin-reset.c
index 73e6022..ddb81f3 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -18,6 +18,8 @@
#include "tree.h"
#include "branch.h"
#include "parse-options.h"
+#include "unpack-trees.h"
+#include "cache-tree.h"
static const char * const git_reset_usage[] = {
"git reset [--mixed | --soft | --hard | --merge] [-q] [<commit>]",
@@ -52,29 +54,56 @@ static inline int is_merge(void)
return !access(git_path("MERGE_HEAD"), F_OK);
}
+static int parse_and_init_tree_desc(const unsigned char *sha1,
+ struct tree_desc *desc)
+{
+ struct tree *tree = parse_tree_indirect(sha1);
+ if (!tree)
+ return 1;
+ init_tree_desc(desc, tree->buffer, tree->size);
+ return 0;
+}
+
static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet)
{
- int i = 0;
- const char *args[6];
+ int nr = 1;
+ int newfd;
+ struct tree_desc desc[2];
+ struct unpack_trees_options opts;
+ struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
- args[i++] = "read-tree";
+ memset(&opts, 0, sizeof(opts));
+ opts.head_idx = 1;
+ opts.src_index = &the_index;
+ opts.dst_index = &the_index;
+ opts.fn = oneway_merge;
+ opts.merge = 1;
if (!quiet)
- args[i++] = "-v";
+ opts.verbose_update = 1;
switch (reset_type) {
case MERGE:
- args[i++] = "-u";
- args[i++] = "-m";
+ opts.update = 1;
break;
case HARD:
- args[i++] = "-u";
+ opts.update = 1;
/* fallthrough */
default:
- args[i++] = "--reset";
+ opts.reset = 1;
}
- args[i++] = sha1_to_hex(sha1);
- args[i] = NULL;
- return run_command_v_opt(args, RUN_GIT_CMD);
+ newfd = hold_locked_index(lock, 1);
+
+ read_cache_unmerged();
+
+ if (parse_and_init_tree_desc(sha1, desc + nr - 1))
+ return error("Failed to find tree of %s.", sha1_to_hex(sha1));
+ if (unpack_trees(nr, desc, &opts))
+ return -1;
+ if (write_cache(newfd, active_cache, active_nr) ||
+ commit_locked_index(lock))
+ return error("Could not write new index file.");
+
+ return 0;
}
static void print_new_head_line(struct commit *commit)
--
1.6.5.rc0.150.g38fe6
^ permalink raw reply related
* [PATCH v2 1/4] reset: add a few tests for "git reset --merge"
From: Christian Couder @ 2009-09-16 4:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski, Linus Torvalds, Paolo Bonzini
In-Reply-To: <20090916035131.3737.33020.chriscool@tuxfamily.org>
Commit 9e8eceab ("Add 'merge' mode to 'git reset'", 2008-12-01),
added the --merge option to git reset, but there were no test cases
for it.
This was not a big problem because "git reset" was just forking and
execing "git read-tree", but this will change in a following patch.
So let's add a few test cases to make sure that there will be no
regression.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t7110-reset-merge.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+), 0 deletions(-)
create mode 100755 t/t7110-reset-merge.sh
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
new file mode 100755
index 0000000..1ec32f9
--- /dev/null
+++ b/t/t7110-reset-merge.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Christian Couder
+#
+
+test_description='Tests for "git reset --merge"'
+
+. ./test-lib.sh
+
+test_expect_success 'creating initial files' '
+ echo "line 1" >> file1 &&
+ echo "line 2" >> file1 &&
+ echo "line 3" >> file1 &&
+ cp file1 file2 &&
+ git add file1 file2 &&
+ test_tick &&
+ git commit -m "Initial commit"
+'
+
+test_expect_success 'reset --merge is ok with changes in file it does not touch' '
+ echo "line 4" >> file1 &&
+ echo "line 4" >> file2 &&
+ test_tick &&
+ git commit -m "add line 4" file1 &&
+ git reset --merge HEAD^ &&
+ ! grep 4 file1 &&
+ grep 4 file2 &&
+ git reset --merge HEAD@{1} &&
+ grep 4 file1 &&
+ grep 4 file2
+'
+
+test_expect_success 'reset --merge discards changes added to index (1)' '
+ echo "line 5" >> file1 &&
+ git add file1 &&
+ git reset --merge HEAD^ &&
+ ! grep 4 file1 &&
+ ! grep 5 file1 &&
+ grep 4 file2 &&
+ echo "line 5" >> file2 &&
+ git add file2 &&
+ git reset --merge HEAD@{1} &&
+ ! grep 4 file2 &&
+ ! grep 5 file1 &&
+ grep 4 file1
+'
+
+test_expect_success 'reset --merge discards changes added to index (2)' '
+ echo "line 4" >> file2 &&
+ git add file2 &&
+ git reset --merge HEAD^ &&
+ ! grep 4 file2 &&
+ git reset --merge HEAD@{1} &&
+ ! grep 4 file2 &&
+ grep 4 file1
+'
+
+test_expect_success 'reset --merge fails with changes in file it touches' '
+ echo "line 6" >> file1 &&
+ test_tick &&
+ git commit -m "add line 6" file1 &&
+ sed -e "s/line 1/changed line 1/" <file1 >file3 &&
+ mv file3 file1 &&
+ test_must_fail git reset --merge HEAD^ 2>err.log &&
+ grep file1 err.log | grep "not uptodate"
+'
+
+test_done
--
1.6.5.rc0.150.g38fe6
^ permalink raw reply related
* [PATCH v2 0/4] "git reset --merge" related improvements
From: Christian Couder @ 2009-09-16 4:14 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski, Linus Torvalds, Paolo Bonzini
In this new version, the test cases that were bogus are now fixed. And
the new "git reset" option is now called "--merge-safe" (instead of
"--merge-dirty").
To make the test cases pass I had to change a little bit the way
"--merge-safe" is implemented. It now does not set the "reset" flag in the
"struct unpack_trees_options" passed to "unpack_trees()".
And commit messages have been improved, thanks to input from Daniel, Junio
and Linus. And there is no more "exec </dev/null" in the test script, thanks
to Jakub.
I prefer to keep Stephan as the author of patch 3/4 because he designed and
implemented the new feature in the first place.
I am working on the documentation for "--merge-safe" and on improving the
existing "git reset" documentation using a table at the same time. So
another patch will be added to this series later.
Christian Couder (2):
reset: add a few tests for "git reset --merge"
reset: add test cases for "--merge-safe" option
Stephan Beyer (2):
reset: use "unpack_trees()" directly instead of "git read-tree"
reset: add option "--merge-safe" to "git reset"
builtin-reset.c | 81 ++++++++++++++++++++++++++++-------
t/t7110-reset-merge.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 16 deletions(-)
create mode 100755 t/t7110-reset-merge.sh
^ permalink raw reply
* Re: [PATCH 13/14] Add README for MSVC build
From: Thiago Farina @ 2009-09-16 1:22 UTC (permalink / raw)
To: Marius Storm-Olsen
Cc: Johannes.Schindelin, msysgit, git, lznuaa, raa.lkml, snaury
In-Reply-To: <22e0abb5a1e91c3ca95f8538d8396c167bb1028d.1253021728.git.mstormo@gmail.com>
On Tue, Sep 15, 2009 at 10:44 AM, Marius Storm-Olsen <mstormo@gmail.com> wrote:
> Based on original README patch from Frank Li
>
> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
> ---
> compat/vcbuild/README | 39 +++++++++++++++++++++++++++++++++++++++
> 1 files changed, 39 insertions(+), 0 deletions(-)
> create mode 100644 compat/vcbuild/README
>
> diff --git a/compat/vcbuild/README b/compat/vcbuild/README
> new file mode 100644
> index 0000000..5d7a07a
> --- /dev/null
> +++ b/compat/vcbuild/README
> @@ -0,0 +1,39 @@
> +The Steps of Build Git with VS2008
> +
> +1. You need the build environment, which contains the Git dependencies
> + to be able to compile, link and run Git with MSVC.
> +
> + You can either use the binary repository:
> +
> + WWW: http://repo.or.cz/w/msvcgit.git
> + Git: git clone git://repo.or.cz/msvcgit.git
> + Zip: http://repo.or.cz/w/msvcgit.git?a=snapshot;h=master;sf=zip
> +
> + and call the setup_32bit_env.cmd batch script before compiling Git,
> + (see repo/package README for details), or the source repository:
> +
> + WWW: http://repo.or.cz/w/gitbuild.git
> + Git: git clone git://repo.or.cz/gitbuild.git
> + Zip: (None, as it's a project with submodules)
> +
> + and build the support libs as instructed in that repo/package.
> +
> +2. Ensure you have the msysgit environment in your path, so you have
> + GNU Make, bash and perl available.
> +
> + WWW: http://repo.or.cz/w/msysgit.git
> + Git: git clone git://repo.or.cz/msysgit.git
> + Zip: http://repo.or.cz/w/msysgit.git?a=snapshot;h=master;sf=zip
> +
> + This environment is also needed when you use the resulting
> + executables, since Git might need to run scripts which are part of
> + the git operations.
> +
> +4. Inside Git's directory run the command:
Shouldn't be 3.?
> + make common-cmds.h
> + to generate the common-cmds.h file needed to compile git.
> +
> +5. Then build Git with the GNU Make Makefile in the Git projects root
4.?
> + make MSVC=1
> +
> +Done!
> --
> 1.6.2.1.418.g33d56.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply
* [PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory.
From: mr.gaffo @ 2009-09-16 0:48 UTC (permalink / raw)
To: git; +Cc: Mike Gaffney
In-Reply-To: <1253062116-13830-4-git-send-email-mr.gaffo@gmail.com>
From: Mike Gaffney <mr.gaffo@gmail.com>
Signed-off-by: Mike Gaffney <mr.gaffo@gmail.com>
---
.../jgit/lib/InfoDirectoryDatabaseTest.java | 66 ++++++++++++++++++++
.../org/spearce/jgit/lib/ObjectDirectoryTest.java | 1 -
.../src/org/spearce/jgit/lib/InfoDatabase.java | 44 +++++++++++++
.../spearce/jgit/lib/InfoDirectoryDatabase.java | 54 ++++++++++++++++
.../src/org/spearce/jgit/lib/Repository.java | 11 +++
5 files changed, 175 insertions(+), 1 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
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
new file mode 100644
index 0000000..066473d
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+import java.io.File;
+
+import org.spearce.jgit.util.JGitTestUtil;
+
+import junit.framework.TestCase;
+
+public class InfoDirectoryDatabaseTest extends TestCase {
+
+ private File testDir;
+
+ @Override
+ protected void setUp() throws Exception {
+ testDir = JGitTestUtil.generateTempDirectoryFileObject();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (testDir.exists()){
+ JGitTestUtil.recursiveDelete(testDir, false, getClass().getName() + "." + getName(), true);
+ }
+ }
+
+ public void testCreateCreatesDirectory() throws Exception {
+ assertFalse(testDir.exists());
+ new InfoDirectoryDatabase(testDir).create();
+ assertTrue(testDir.exists());
+ }
+}
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 204fb7c..8c1d32d 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
@@ -38,7 +38,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import org.spearce.jgit.util.JGitTestUtil;
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
new file mode 100644
index 0000000..2a8d88d
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+public abstract class InfoDatabase {
+
+ public void create() {
+ }
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
new file mode 100644
index 0000000..90655e8
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+import java.io.File;
+
+public class InfoDirectoryDatabase extends InfoDatabase {
+
+ private File info;
+
+ public InfoDirectoryDatabase(final File directory) {
+ info = directory;
+ }
+
+ @Override
+ public void create() {
+ info.mkdirs();
+ }
+
+}
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 46b7804..f658b5c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -97,6 +97,8 @@
private final RefDatabase refs;
private final ObjectDirectory objectDatabase;
+
+ private final InfoDatabase infoDatabase;
private GitIndex index;
@@ -116,6 +118,7 @@ public Repository(final File d) throws IOException {
gitDir = d.getAbsoluteFile();
refs = new RefDatabase(this);
objectDatabase = new ObjectDirectory(FS.resolve(gitDir, "objects"));
+ infoDatabase = new InfoDirectoryDatabase(FS.resolve(gitDir, "info"));
final FileBasedConfig userConfig;
userConfig = SystemReader.getInstance().openUserConfig();
@@ -177,6 +180,7 @@ public void create(boolean bare) throws IOException {
gitDir.mkdirs();
refs.create();
objectDatabase.create();
+ infoDatabase.create();
new File(gitDir, "branches").mkdir();
new File(gitDir, "remotes").mkdir();
@@ -210,6 +214,13 @@ public File getObjectsDirectory() {
public ObjectDatabase getObjectDatabase() {
return objectDatabase;
}
+
+ /**
+ * @return the info database which stores this repository's info
+ */
+ public InfoDatabase getInfoDatabase() {
+ return infoDatabase;
+ }
/**
* @return the configuration of this repository
--
1.6.4.2
^ permalink raw reply related
* [PATCH JGit 3/5] Implemented directory based info cache for objects/info/packs.
From: mr.gaffo @ 2009-09-16 0:48 UTC (permalink / raw)
To: git; +Cc: Mike Gaffney
In-Reply-To: <1253062116-13830-3-git-send-email-mr.gaffo@gmail.com>
From: Mike Gaffney <mr.gaffo@gmail.com>
Details:
Add abstract method for updating the object db's info cache to directory.
Implemented passthrough on Alternate for the update of infocache.
Added utility that generates the contents of the objects/info/packs
file as a string from a list of PackFiles.
Added implementation from ObjectDirectory on down
for creating the info cache.
Added test for creating the info cache
Signed-off-by: Mike Gaffney <mr.gaffo@gmail.com>
---
.../CachedPacksInfoFileContentsGeneratorTest.java | 74 ++++++++++++++++++++
.../org/spearce/jgit/lib/ObjectDirectoryTest.java | 36 +++++++---
.../tst/org/spearce/jgit/util/JGitTestUtil.java | 26 ++++++-
.../jgit/lib/AlternateRepositoryDatabase.java | 5 ++
.../lib/CachedPacksInfoFileContentsGenerator.java | 63 +++++++++++++++++
.../src/org/spearce/jgit/lib/Constants.java | 3 +
.../src/org/spearce/jgit/lib/ObjectDatabase.java | 8 ++
.../src/org/spearce/jgit/lib/ObjectDirectory.java | 5 ++
.../lib/UpdateDirectoryBasedPacksInfoCache.java | 62 ++++++++++++++++
.../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 26 +++++++
.../org/spearce/jgit/transport/ReceivePack.java | 10 +++
11 files changed, 307 insertions(+), 11 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.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/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
new file mode 100644
index 0000000..bea0b70
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+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 CachedPacksInfoFileContentsGeneratorTest 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() + "\n\n", new CachedPacksInfoFileContentsGenerator(packs).generateContents());
+ }
+
+ 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("\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 CachedPacksInfoFileContentsGenerator(packs).generateContents());
+ }
+
+}
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 c27580f..204fb7c 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
@@ -38,8 +38,8 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
import org.spearce.jgit.util.JGitTestUtil;
@@ -54,9 +54,9 @@
@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()){
@@ -106,23 +106,41 @@ 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();
assertEquals(1, localPacks.size());
assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());
}
+
+ public void testUpdateInfoCacheCreatesPacksAndRefsFile() throws Exception {
+ createSamplePacksDir();
+
+ ObjectDirectory od = new ObjectDirectory(testDir);
+ od.create();
+ od.updateInfoCache();
+
+ String expectedContents = new CachedPacksInfoFileContentsGenerator(od.listLocalPacks()).generateContents();
+ File packsFile = new File(od.getDirectory(), Constants.CACHED_PACKS_FILE);
+
+ assertTrue(packsFile.exists());
+ assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
+ }
private void createTestDir(){
if (!testDir.mkdir()){
fail("unable to create test directory");
}
}
+
+ 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/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
index 785922a..44630fd 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,15 +37,17 @@
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;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.UUID;
import junit.framework.AssertionFailedError;
@@ -74,7 +76,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);
@@ -87,6 +90,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();
}
@@ -136,4 +154,8 @@ private static void reportDeleteFailure(final String name,
else
System.out.println(msg);
}
+
+ public static File generateTempDirectoryFileObject() {
+ return new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString());
+ }
}
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..70ce505 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() throws IOException {
+ odb.updateInfoCache();
+ }
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java
new file mode 100644
index 0000000..6046c94
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+import java.util.List;
+
+/**
+ * This file is used to generate the contents of the file system
+ * based pack file cache used by the dumb git-http client protocol.
+ * @author mike
+ */
+public class CachedPacksInfoFileContentsGenerator {
+
+ private List<PackFile> packs;
+
+ public CachedPacksInfoFileContentsGenerator(List<PackFile> packs) {
+ this.packs = packs;
+ }
+
+ public String generateContents(){
+ StringBuilder builder = new StringBuilder();
+ for (PackFile packFile : packs) {
+ builder.append("P ").append(packFile.getPackFile().getName()).append('\n');
+ }
+ builder.append('\n');
+ return builder.toString();
+ }
+
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java
index 9afea67..2d78dda 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java
@@ -224,6 +224,9 @@
/** Info refs folder */
public static final String INFO_REFS = "info/refs";
+
+ /** cached packs file */
+ public static final String CACHED_PACKS_FILE = "info/packs";
/** Packed refs file */
public static final String PACKED_REFS = "packed-refs";
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..5ded7bb 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,14 @@ 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
+ * @throws IOException
+ */
+ public abstract void updateInfoCache() throws IOException;
+
+ /**
* Does this database exist yet?
*
* @return true if this database is already created; false if the caller
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 cbe132d..f4251c1 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
@@ -514,4 +514,9 @@ boolean tryAgain(final long currLastModified) {
tryAgain1();
return new ArrayList<PackFile>(Arrays.asList(packList.get().packs));
}
+
+ @Override
+ public void updateInfoCache() throws IOException {
+ new UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.getDirectory(), Constants.CACHED_PACKS_FILE)).execute();
+ }
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java
new file mode 100644
index 0000000..327bb34
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009, Mike Gaffney.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+public class UpdateDirectoryBasedPacksInfoCache {
+
+ private List<PackFile> packsList;
+ private File infoPacksFile;
+
+ public UpdateDirectoryBasedPacksInfoCache(List<PackFile> packsList,
+ File infoPacksFile) {
+ this.packsList = packsList;
+ this.infoPacksFile = infoPacksFile;
+ }
+
+ public void execute() throws IOException {
+ String packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();
+ FileOutputStream fos = new FileOutputStream(infoPacksFile);
+ fos.write(packsContents.getBytes());
+ fos.close();
+ }
+
+}
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..b6947ce
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
@@ -0,0 +1,26 @@
+package org.spearce.jgit.lib;
+
+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 infoPacksFile;
+
+ public UpdateDirectoryInfoCache(List<PackFile> packsList,
+ File infoPacksFile) {
+ this.packsList = packsList;
+ this.infoPacksFile = infoPacksFile;
+ }
+
+ public void execute() throws IOException {
+ String packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();
+ FileOutputStream fos = new FileOutputStream(infoPacksFile);
+ fos.write(packsContents.getBytes());
+ fos.close();
+ }
+
+}
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 eb21254..5865736 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -521,6 +521,16 @@ void sendString(final String s) throws IOException {
}
postReceive.onPostReceive(this, filterCommands(Result.OK));
+ updateObjectInfoCache();
+ }
+ }
+
+ private void updateObjectInfoCache() {
+ try{
+ getRepository().getObjectDatabase().updateInfoCache();
+ }
+ catch (IOException e){
+ sendMessage("error updating server info: " + e.getMessage());
}
}
--
1.6.4.2
^ permalink raw reply related
* [PATCH JGit 5/5] added tests for the file based info cache update and made pass
From: mr.gaffo @ 2009-09-16 0:48 UTC (permalink / raw)
To: git; +Cc: mike.gaffney, Mike Gaffney
In-Reply-To: <1253062116-13830-5-git-send-email-mr.gaffo@gmail.com>
From: mike.gaffney <mike.gaffney@asolutions.com>
Signed-off-by: Mike Gaffney <mr.gaffo@gmail.com>
---
.../CachedPacksInfoFileContentsGeneratorTest.java | 8 ++--
.../jgit/lib/InfoDirectoryDatabaseTest.java | 30 ++++++++++++++++++++
.../org/spearce/jgit/lib/ObjectDirectoryTest.java | 4 +-
.../src/org/spearce/jgit/lib/InfoDatabase.java | 15 ++++++++++
.../spearce/jgit/lib/InfoDirectoryDatabase.java | 15 ++++++++++
.../org/spearce/jgit/transport/ReceivePack.java | 10 ++++++
6 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
index bea0b70..10ce9e3 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java
@@ -63,10 +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("\n");
- expected.append("P ").append(TEST_PACK.getName()).append("\n");
- expected.append("P ").append(TEST_PACK.getName()).append("\n");
- expected.append("\n");
+ 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 CachedPacksInfoFileContentsGenerator(packs).generateContents());
}
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 066473d..e31b883 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
@@ -37,6 +37,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;
@@ -63,4 +67,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.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
index 8c1d32d..a3f5278 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
@@ -40,10 +40,10 @@
import java.io.IOException;
import java.util.List;
-import org.spearce.jgit.util.JGitTestUtil;
-
import junit.framework.TestCase;
+import org.spearce.jgit.util.JGitTestUtil;
+
public class ObjectDirectoryTest extends TestCase {
private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
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 2a8d88d..96a39fc 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java
@@ -36,9 +36,24 @@
*/
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 90655e8..48f60d1 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
@@ -37,6 +37,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 {
@@ -51,4 +54,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();
+ }
+
}
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 5865736..23277c9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -522,6 +522,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] Adding update-server-info functionality try2
From: mr.gaffo @ 2009-09-16 0:48 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.
It also incorporates suggesions from RobinRosenberg.
Please be gentle.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox