Skip to content

Commit

Permalink
Merge branch 'js/mingw-fallouts'
Browse files Browse the repository at this point in the history
* js/mingw-fallouts:
  fetch-pack: Prepare for a side-band demultiplexer in a thread.
  rehabilitate some t5302 tests on 32-bit off_t machines
  Allow ETC_GITCONFIG to be a relative path.
  Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.
  Allow a relative builtin template directory.
  Close files opened by lock_file() before unlinking.
  builtin run_command: do not exit with -1.
  Move #include <sys/select.h> and <sys/ioctl.h> to git-compat-util.h.
  Use is_absolute_path() in sha1_file.c.
  Skip t3902-quoted.sh if the file system does not support funny names.
  t5302-pack-index: Skip tests of 64-bit offsets if necessary.
  t7501-commit.sh: Not all seds understand option -i
  t5300-pack-object.sh: Split the big verify-pack test into smaller parts.
  • Loading branch information
Junio C Hamano committed Nov 25, 2007
2 parents 25f3cd5 + 1f759ee commit ab002e3
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 71 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
LIBS = $(GITLIBS) $(EXTLIBS)

BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
$(COMPAT_CFLAGS)
LIB_OBJS += $(COMPAT_OBJS)

ALL_CFLAGS += $(BASIC_CFLAGS)
Expand Down Expand Up @@ -903,6 +903,9 @@ exec_cmd.o: exec_cmd.c GIT-CFLAGS
builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<

config.o: config.c GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<

http.o: http.c GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<

Expand Down
4 changes: 2 additions & 2 deletions builtin-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int get_value(const char* key_, const char* regex_)
local = repo_config = xstrdup(git_path("config"));
if (home)
global = xstrdup(mkpath("%s/.gitconfig", home));
system_wide = ETC_GITCONFIG;
system_wide = git_etc_gitconfig();
}

key = xstrdup(key_);
Expand Down Expand Up @@ -191,7 +191,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}
}
else if (!strcmp(argv[1], "--system"))
setenv(CONFIG_ENVIRONMENT, ETC_GITCONFIG, 1);
setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1);
else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
if (argc < 3)
usage(git_config_set_usage);
Expand Down
42 changes: 16 additions & 26 deletions builtin-fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,42 +462,33 @@ static int sideband_demux(int fd, void *data)
{
int *xd = data;

close(xd[1]);
return recv_sideband("fetch-pack", xd[0], fd, 2);
}

static void setup_sideband(int fd[2], int xd[2], struct async *demux)
{
if (!use_sideband) {
fd[0] = xd[0];
fd[1] = xd[1];
return;
}
/* xd[] is talking with upload-pack; subprocess reads from
* xd[0], spits out band#2 to stderr, and feeds us band#1
* through demux->out.
*/
demux->proc = sideband_demux;
demux->data = xd;
if (start_async(demux))
die("fetch-pack: unable to fork off sideband demultiplexer");
close(xd[0]);
fd[0] = demux->out;
fd[1] = xd[1];
}

static int get_pack(int xd[2], char **pack_lockfile)
{
struct async demux;
int fd[2];
const char *argv[20];
char keep_arg[256];
char hdr_arg[256];
const char **av;
int do_keep = args.keep_pack;
struct child_process cmd;

setup_sideband(fd, xd, &demux);
memset(&demux, 0, sizeof(demux));
if (use_sideband) {
/* xd[] is talking with upload-pack; subprocess reads from
* xd[0], spits out band#2 to stderr, and feeds us band#1
* through demux->out.
*/
demux.proc = sideband_demux;
demux.data = xd;
if (start_async(&demux))
die("fetch-pack: unable to fork off sideband"
" demultiplexer");
}
else
demux.out = xd[0];

memset(&cmd, 0, sizeof(cmd));
cmd.argv = argv;
Expand All @@ -506,7 +497,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
if (!args.keep_pack && unpack_limit) {
struct pack_header header;

if (read_pack_header(fd[0], &header))
if (read_pack_header(demux.out, &header))
die("protocol error: bad pack header");
snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
ntohl(header.hdr_version), ntohl(header.hdr_entries));
Expand Down Expand Up @@ -542,11 +533,10 @@ static int get_pack(int xd[2], char **pack_lockfile)
*av++ = hdr_arg;
*av++ = NULL;

cmd.in = fd[0];
cmd.in = demux.out;
cmd.git_cmd = 1;
if (start_command(&cmd))
die("fetch-pack: unable to fork off %s", argv[0]);
close(fd[1]);
if (do_keep && pack_lockfile)
*pack_lockfile = index_pack_lockfile(cmd.out);

Expand Down
16 changes: 13 additions & 3 deletions builtin-init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "builtin.h"
#include "exec_cmd.h"

#ifndef DEFAULT_GIT_TEMPLATE_DIR
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
Expand Down Expand Up @@ -131,10 +132,19 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
int template_len;
DIR *dir;

if (!template_dir) {
if (!template_dir)
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
if (!template_dir)
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
if (!template_dir) {
/*
* if the hard-coded template is relative, it is
* interpreted relative to the exec_dir
*/
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
if (!is_absolute_path(template_dir)) {
const char *exec_path = git_exec_path();
template_dir = prefix_path(exec_path, strlen(exec_path),
template_dir);
}
}
strcpy(template_path, template_dir);
template_len = strlen(template_path);
Expand Down
2 changes: 2 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ extern int refresh_index(struct index_state *, unsigned int flags, const char **

struct lock_file {
struct lock_file *next;
int fd;
pid_t owner;
char on_list;
char filename[PATH_MAX];
Expand Down Expand Up @@ -556,6 +557,7 @@ extern int git_config_bool(const char *, const char *);
extern int git_config_set(const char *, const char *);
extern int git_config_set_multivar(const char *, const char *, const char *, int);
extern int git_config_rename_section(const char *, const char *);
extern const char *git_etc_gitconfig(void);
extern int check_repository_format_version(const char *var, const char *value);

#define MAX_GITNAME (1000)
Expand Down
20 changes: 18 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/
#include "cache.h"
#include "exec_cmd.h"

#define MAXNAME (256)

Expand Down Expand Up @@ -459,6 +460,21 @@ int git_config_from_file(config_fn_t fn, const char *filename)
return ret;
}

const char *git_etc_gitconfig(void)
{
static const char *system_wide;
if (!system_wide) {
system_wide = ETC_GITCONFIG;
if (!is_absolute_path(system_wide)) {
/* interpret path relative to exec-dir */
const char *exec_path = git_exec_path();
system_wide = prefix_path(exec_path, strlen(exec_path),
system_wide);
}
}
return system_wide;
}

int git_config(config_fn_t fn)
{
int ret = 0;
Expand All @@ -471,8 +487,8 @@ int git_config(config_fn_t fn)
* config file otherwise. */
filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) {
if (!access(ETC_GITCONFIG, R_OK))
ret += git_config_from_file(fn, ETC_GITCONFIG);
if (!access(git_etc_gitconfig(), R_OK))
ret += git_config_from_file(fn, git_etc_gitconfig());
home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!filename)
Expand Down
2 changes: 2 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
#include <fnmatch.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <assert.h>
#include <regex.h>
#include <netinet/in.h>
Expand Down
2 changes: 1 addition & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)

status = p->fn(argc, argv, prefix);
if (status)
return status;
return status & 0xff;

/* Somebody closed stdout? */
if (fstat(fileno(stdout), &st))
Expand Down
1 change: 0 additions & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "builtin.h"
#include "exec_cmd.h"
#include "common-cmds.h"
#include <sys/ioctl.h>

/* most GUI terminals set COLUMNS (although some don't export it) */
static int term_columns(void)
Expand Down
17 changes: 10 additions & 7 deletions lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ static void remove_lock_file(void)

while (lock_file_list) {
if (lock_file_list->owner == me &&
lock_file_list->filename[0])
lock_file_list->filename[0]) {
close(lock_file_list->fd);
unlink(lock_file_list->filename);
}
lock_file_list = lock_file_list->next;
}
}
Expand Down Expand Up @@ -120,8 +122,6 @@ static char *resolve_symlink(char *p, size_t s)

static int lock_file(struct lock_file *lk, const char *path)
{
int fd;

if (strlen(path) >= sizeof(lk->filename)) return -1;
strcpy(lk->filename, path);
/*
Expand All @@ -130,8 +130,8 @@ static int lock_file(struct lock_file *lk, const char *path)
*/
resolve_symlink(lk->filename, sizeof(lk->filename)-5);
strcat(lk->filename, ".lock");
fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
if (0 <= fd) {
lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
if (0 <= lk->fd) {
if (!lock_file_list) {
signal(SIGINT, remove_lock_file_on_signal);
atexit(remove_lock_file);
Expand All @@ -148,7 +148,7 @@ static int lock_file(struct lock_file *lk, const char *path)
}
else
lk->filename[0] = 0;
return fd;
return lk->fd;
}

int hold_lock_file_for_update(struct lock_file *lk, const char *path, int die_on_error)
Expand All @@ -163,6 +163,7 @@ int commit_lock_file(struct lock_file *lk)
{
char result_file[PATH_MAX];
int i;
close(lk->fd);
strcpy(result_file, lk->filename);
i = strlen(result_file) - 5; /* .lock */
result_file[i] = 0;
Expand Down Expand Up @@ -194,7 +195,9 @@ int commit_locked_index(struct lock_file *lk)

void rollback_lock_file(struct lock_file *lk)
{
if (lk->filename[0])
if (lk->filename[0]) {
close(lk->fd);
unlink(lk->filename);
}
lk->filename[0] = 0;
}
2 changes: 0 additions & 2 deletions pager.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "cache.h"

#include <sys/select.h>

/*
* This is split up from the rest of git so that we might do
* something different on Windows, for example.
Expand Down
8 changes: 4 additions & 4 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int safe_create_leading_directories(char *path)
char *pos = path;
struct stat st;

if (*pos == '/')
if (is_absolute_path(path))
pos++;

while (pos) {
Expand Down Expand Up @@ -253,7 +253,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
int entlen = pfxlen + 43;
int base_len = -1;

if (*entry != '/' && relative_base) {
if (!is_absolute_path(entry) && relative_base) {
/* Relative alt-odb */
if (base_len < 0)
base_len = strlen(relative_base) + 1;
Expand All @@ -262,7 +262,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
}
ent = xmalloc(sizeof(*ent) + entlen);

if (*entry != '/' && relative_base) {
if (!is_absolute_path(entry) && relative_base) {
memcpy(ent->base, relative_base, base_len - 1);
ent->base[base_len - 1] = '/';
memcpy(ent->base + base_len, entry, len);
Expand Down Expand Up @@ -333,7 +333,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
while (cp < ep && *cp != sep)
cp++;
if (last != cp) {
if ((*last != '/') && depth) {
if (!is_absolute_path(last) && depth) {
error("%s: ignoring relative alternate object store %s",
relative_base, last);
} else {
Expand Down
7 changes: 7 additions & 0 deletions t/t3902-quoted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ LF='
'
DQ='"'

echo foo > "Name and an${HT}HT"
test -f "Name and an${HT}HT" || {
# since FAT/NTFS does not allow tabs in filenames, skip this test
say 'Your filesystem does not allow tabs in filenames, test skipped.'
test_done
}

for_each_name () {
for name in \
Name "Name and a${LF}LF" "Name and an${HT}HT" "Name${DQ}" \
Expand Down
Loading

0 comments on commit ab002e3

Please sign in to comment.