Skip to content

Port git to Plan 9 #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GIT-VERSION-GEN
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ else
VN="$DEF_VER"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

"lufia via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: lufia <lufia@lufia.org>
>
> Plan 9 don't have expr(1).
>
> Signed-off-by: lufia <lufia@lufia.org>
> ---
>  GIT-VERSION-GEN | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
> index a0766f64ed..754d4486f5 100755
> --- a/GIT-VERSION-GEN
> +++ b/GIT-VERSION-GEN
> @@ -26,7 +26,7 @@ else
>  	VN="$DEF_VER"
>  fi
>  
> -VN=$(expr "$VN" : v*'\(.*\)')
> +VN=$(echo "$VN" | sed 's/^v*//')

The expr utility is often a shell built-in, but sed is almost never
(as it is a lot more heavy-weight command).  It may not be a bad
idea to get rid of expr with a simple shell parameter expansion,
e.g.

	VN=${VN#v}

instead.

The original explicitly is prepared to see no 'v' at the beginning
(in which case it just passes VN intact), or more than one 'v's (in
which case all leading 'v's are stripped), while the shell parameter
expansion strips zero or one 'v' at the beginning.  So there is a
slight "regression" there, but I do not think it matters (certainly,
it was *NOT* my intention while writing the original to strip two or
more 'v's).  181129d2 ("For release tarballs, include the proper
version", 2006-01-09) snuck in the "all leading 'v's are stripped"
without sufficient explanation, but I do not think it was an attempt
to allow two or more 'v's.

fi

VN=$(expr "$VN" : v*'\(.*\)')
VN=${VN#v}

if test -r $GVF
then
Expand Down
81 changes: 68 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,21 @@ perllibdir = $(sharedir)/perl5
localedir = $(sharedir)/locale
template_dir = share/git-core/templates
htmldir = $(prefix)/share/doc/git-doc
ETC_GITCONFIG = $(sysconfdir)/gitconfig
ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
ifndef ETC_GITCONFIG
ETC_GITCONFIG = $(sysconfdir)/gitconfig
endif
ifndef ETC_GITATTRIBUTES
ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
endif
ifndef USER_GITCONFIG
USER_GITCONFIG = ~/.gitconfig
endif
ifndef USER_GITCREDENTIALS
USER_GITCREDENTIALS = ~/.git-credentials
endif
ifndef USER_GITCREDENTIAL_CACHE
USER_GITCREDENTIAL_CACHE = ~/.git-credential-cache
endif
lib = lib
# DESTDIR =
pathsep = :
Expand All @@ -543,6 +556,7 @@ export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir

# Set our default programs
CC = cc
LD = cc
AR = ar
RM = rm -f
DIFF = diff
Expand Down Expand Up @@ -779,6 +793,10 @@ ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
# what 'all' will build but not install in gitexecdir
OTHER_PROGRAMS = git$X

# what 'all' will build but not install in neither bindir and gitexecdir,
COMPAT_PROGRAM_OBJS =
COMPAT_PROGRAMS =

# what test wrappers are needed and 'install' will install, in bindir
BINDIR_PROGRAMS_NEED_X += git
BINDIR_PROGRAMS_NEED_X += git-receive-pack
Expand Down Expand Up @@ -1869,6 +1887,11 @@ ifndef PAGER_ENV
PAGER_ENV = LESS=FRX LV=-c
endif

ifdef USE_EXEC_WRAPPER
COMPAT_PROGRAM_OBJS += exec-wrapper.o
COMPAT_PROGRAMS += exec-wrapper$X
endif

QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =

Expand Down Expand Up @@ -1930,6 +1953,9 @@ endif

ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
USER_GITCONFIG_SQ = $(subst ','\'',$(USER_GITCONFIG))
USER_GITCREDENTIALS_SQ = $(subst ','\'',$(USER_GITCREDENTIALS))
USER_GITCREDENTIAL_CACHE_SQ = $(subst ','\'',$(USER_GITCREDENTIAL_CACHE))

DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
bindir_SQ = $(subst ','\'',$(bindir))
Expand Down Expand Up @@ -2066,7 +2092,7 @@ profile-fast: profile-clean
$(MAKE) PROFILE=USE all


all:: $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
all:: $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) $(COMPAT_PROGRAMS) GIT-BUILD-OPTIONS
ifneq (,$X)
$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
endif
Expand Down Expand Up @@ -2126,7 +2152,7 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = \
'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'

git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) \
$(filter %.o,$^) $(LIBS)

help.sp help.s help.o: command-list.h
Expand All @@ -2145,10 +2171,11 @@ version.sp version.s version.o: EXTRA_CPPFLAGS = \
GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
git rev-parse -q --verify HEAD 2>/dev/null)"'

$(BUILT_INS): git$X
$(BUILT_INS): git$X $(COMPAT_PROGRAMS)
$(QUIET_BUILT_IN)$(RM) $@ && \
ln $< $@ 2>/dev/null || \
ln -s $< $@ 2>/dev/null || \
cp exec-wrapper$X $@ 2>/dev/null || \
cp $< $@

config-list.h: generate-configlist.sh
Expand Down Expand Up @@ -2354,6 +2381,7 @@ VCSSVN_OBJS += vcs-svn/svndump.o

TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
$(COMPAT_PROGRAM_OBJS) \
$(XDIFF_OBJS) \
$(VCSSVN_OBJS) \
$(FUZZ_OBJS) \
Expand Down Expand Up @@ -2426,12 +2454,30 @@ builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \

config.sp config.s config.o: GIT-PREFIX
config.sp config.s config.o: EXTRA_CPPFLAGS = \
-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' \
-DUSER_GITCONFIG='"$(USER_GITCONFIG_SQ)"'

builtin/config.sp builtin/config.s builtin/config.o: GIT-PREFIX
builtin/config.sp builtin/config.s builtin/config.o: EXTRA_CPPFLAGS = \
-DUSER_GITCONFIG='"$(USER_GITCONFIG_SQ)"'

sequencer.sp sequencer.s sequencer.o: GIT-PREFIX
sequencer.sp sequencer.s sequencer.o: EXTRA_CPPFLAGS = \
-DUSER_GITCONFIG='"$(USER_GITCONFIG_SQ)"'

attr.sp attr.s attr.o: GIT-PREFIX
attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
-DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'

credential-cache.sp credential-cache.s credential-cache.o: GIT-PREFIX
credential-cache.sp credential-cache.s credential-cache.o: EXTRA_CPPFLAGS = \
-DUSER_GITCONFIG='"$(USER_GITCONFIG_SQ)"' \
-DUSER_GITCREDENTIAL_CACHE='"$(USER_GITCREDENTIAL_CACHE_SQ)"'

credential-store.sp credential-store.s credential-store.o: GIT-PREFIX
credential-store.sp credential-store.s credential-store.o: EXTRA_CPPFLAGS = \
-DUSER_GITCREDENTIALS='"$(USER_GITCREDENTIALS_SQ)"'

gettext.sp gettext.s gettext.o: GIT-PREFIX
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
Expand All @@ -2456,26 +2502,33 @@ compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
compat/nedmalloc/nedmalloc.sp: SP_EXTRA_FLAGS += -Wno-non-pointer-null
endif

exec-wrapper.sp exec-wrapper.s exec-wrapper.o: EXTRA_CPPFLAGS = \
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
'-DBINDIR="$(bindir_relative_SQ)"'

exec-wrapper$X: exec-wrapper.o GIT-LDFLAGS
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^)

git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)

git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIBS)

git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(IMAP_SEND_LDFLAGS) $(LIBS)

git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(LIBS)
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)

git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
$(VCSSVN_LIB)

$(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
Expand All @@ -2485,7 +2538,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
cp $< $@

$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)

$(LIB_FILE): $(LIB_OBJS)
Expand Down Expand Up @@ -2780,7 +2833,7 @@ t/helper/test-svn-fe$X: $(VCSSVN_LIB)
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))

t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
$(QUIET_LINK)$(LD) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)

check-sha1:: t/helper/test-tool$X
t/helper/test-sha1.sh
Expand Down Expand Up @@ -2963,6 +3016,7 @@ endif
{ test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
cp "exec-wrapper$X" "$$execdir/$$p" 2>/dev/null || \
cp "$$bindir/git$X" "$$bindir/$$p" || exit; } \
done && \
for p in $(BUILT_INS); do \
Expand All @@ -2972,6 +3026,7 @@ endif
{ test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
cp "exec-wrapper$X" "$$execdir/$$p" 2>/dev/null || \
cp "$$execdir/git$X" "$$execdir/$$p" || exit; } \
done && \
remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
Expand Down
2 changes: 1 addition & 1 deletion builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}

if (use_global_config) {
char *user_config = expand_user_path("~/.gitconfig", 0);
char *user_config = expand_user_path(USER_GITCONFIG, 0);
char *xdg_config = xdg_config_home("config");

if (!user_config)
Expand Down
5 changes: 5 additions & 0 deletions compat/plan9/openssl/crypto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef __attribute__
#define __attribute__(x)
#endif

#include_next <openssl/crypto.h>
3 changes: 3 additions & 0 deletions compat/regex/regex_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <stdio.h>
#include <string.h>

#ifdef NEEDS_SYS_PARAM_H
#include <sys/param.h>
#endif
#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
# include <langinfo.h>
#endif
Expand Down
5 changes: 3 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ static int do_git_config_sequence(const struct config_options *opts,
{
int ret = 0;
char *xdg_config = xdg_config_home("config");
char *user_config = expand_user_path("~/.gitconfig", 0);
char *user_config = expand_user_path(USER_GITCONFIG, 0);
char *repo_config;
enum config_scope prev_parsing_scope = current_parsing_scope;

Expand Down Expand Up @@ -2457,7 +2457,8 @@ static int store_aux_event(enum config_event_t type,
return error(_("invalid section name '%s'"), cf->var.buf);

if (cf->subsection_case_sensitive)
cmpfn = strncasecmp;
/* Plan 9's strncasecmp is typed (char*, char*, int) */
cmpfn = (int (*)(const char*, const char*, size_t))strncasecmp;
else
cmpfn = strncmp;

Expand Down
99 changes: 99 additions & 0 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ ifeq ($(uname_S),Windows)

CC = compat/vcbuild/scripts/clink.pl
AR = compat/vcbuild/scripts/lib.pl
LD = $(CC)
CFLAGS =
BASIC_CFLAGS = -nologo -I. -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
Expand Down Expand Up @@ -518,6 +519,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
# INLINE='' would just replace one set of warnings with another and
# still not compile in c89 mode, due to non-const array initializations.
CC = cc -c99
LD = $(CC)
# Build down-rev compatible objects that don't use our new getopt_long.
ifeq ($(uname_R).$(uname_V),J06.21)
CC += -WRVU=J06.20
Expand Down Expand Up @@ -665,8 +667,10 @@ else
BASIC_LDFLAGS += -Wl,--large-address-aware
endif
CC = gcc
LD = $(CC)
COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \
-fstack-protector-strong
BASIC_LDFLAGS += -fstack-protector-strong
EXTLIBS += -lntdll
INSTALL = /bin/install
NO_R_TO_GCC_LINKER = YesPlease
Expand Down Expand Up @@ -699,6 +703,101 @@ ifeq ($(uname_S),QNX)
NO_STRCASESTR = YesPlease
NO_STRLCPY = YesPlease
endif
ifeq ($(uname_S),Plan9)
CC = pcc
CFLAGS = -FVB+
ARFLAGS = uv
# pcc don't use mismatched objfiles
ifeq ($(objtype),386)
LD = 8l
endif
ifeq ($(objtype),amd64)
LD = 6l
endif
ifeq ($(objtype),arm)
LD = 5l
endif
ifeq ($(objtype),mips)
LD = vl
endif
ifeq ($(objtype),mips64)
LD = 4l
endif
ifeq ($(objtype),power)
LD = ql
endif
ifeq ($(objtype),sparc)
LD = kl
endif
ifeq ($(objtype),spim)
LD = 0l
endif
ifeq ($(objtype),spim64)
LD = xl
endif
BASIC_CFLAGS += -Icompat/plan9
BASIC_CFLAGS += -D__PLAN9__
BASIC_CFLAGS += -D_POSIX_SOURCE
BASIC_CFLAGS += -D_BSD_EXTENSION
BASIC_CFLAGS += -D_SUSV2_SOURCE
BASIC_CFLAGS += -D_PLAN9_SOURCE
BASIC_CFLAGS += -D_RESEARCH_SOURCE
BASIC_CFLAGS += -D_REENTRANT_SOURCE
BASIC_CFLAGS += -DHAVE_SOCK_OPTS
BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in6
BASIC_CFLAGS += -DHOME_ENVIRONMENT=\"home\"
BASIC_CFLAGS += -DPATH_ENVIRONMENT=\"path\"
BASIC_CFLAGS += -D_PATH_SEP=1
BASIC_CFLAGS += -D_PATH_DEFPATH=\"/bin\\x01.\\x01/bin/ape\"
COMPAT_CFLAGS += -DHAVE_STDINT_H
COMPAT_CFLAGS += -DHAVE_LOCALE_H
LDFLAGS = -L/$(objtype)/lib/ape

NEEDS_CRYPTO_WITH_SSL = YesPlease
NEEDS_SYS_PARAM_H = YesPlease
NO_NSEC = YesPlease
NO_SYMLINK_HEAD = YesPlease
NO_GECOS_IN_PWENT = YesPlease
NO_GETTEXT = YesPlease
NO_SETENV = YesPlease
NO_STRCASESTR = YesPlease
NO_STRLCPY = YesPlease
NO_STRTOUMAX = YesPlease
NO_REGEX = YesPlease
NO_MKDTEMP = YesPlease
NO_UNSETENV = YesPlease
NO_INITGROUPS = YesPlease
NO_MMAP = YesPlease
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
NO_STRUCT_ITIMERVAL = YesPlease
NO_SETITIMER = YesPlease
NO_ICONV = YesPlease
NO_SYMLINK_HEAD = YesPlease
OPENSSL_SHA1 = YesPlease
OPENSSL_SHA256 = YesPlease
NO_MEMMEM = YesPlease
HAVE_CLOCK_GETTIME = YesPlease

NO_SVN_TESTS = YesPlease
NO_PERL = YesPlease
NO_PYTHON = YesPlease
NO_TCLTK = YesPlease
NO_INSTALL_HARDLINKS = YesPlease

ETC_GITCONFIG = /sys/lib/git/config
ETC_GITATTRIBUTES = /sys/lib/git/attributes
USER_GITCONFIG = ~/lib/git/config
USER_GITCREDENTIALS = ~/lib/git/credentials
USER_GITCREDENTIAL_CACHE = ~/lib/git/credential-cache

DEFAULT_PAGER = /bin/p
PAGER_ENV = terminal=
SHELL_PATH = /bin/ape/sh
DEFAULT_EDITOR = /bin/ed

CURL_LDFLAGS = -lcurl -lssl -lcrypto
USE_EXEC_WRAPPER = YesPlease
endif

vcxproj:
# Require clean work tree
Expand Down
2 changes: 1 addition & 1 deletion credential-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static char *get_socket_path(void)
{
struct stat sb;
char *old_dir, *socket;
old_dir = expand_user_path("~/.git-credential-cache", 0);
old_dir = expand_user_path(USER_GITCREDENTIAL_CACHE, 0);
if (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))
socket = xstrfmt("%s/socket", old_dir);
else
Expand Down
Loading