Skip to contentSkip to conversation

Port git to Plan 9

PATCH Superseded KADOTA, Kyohei via GitGitGadget 5 participants 17 messages Aug 3, 2019 – Aug 27, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Port git to Plan 9

I ported git, and git subcommands only written in C to Plan 9. This pull request contains patches for existing codes, and new files to build git in Plan 9.

All build options such as NO_PERL are not supported yet, and also some git subcommands written not in C is not available yet. But git can synchronize to remote repository with git pull and git push via HTTPS.

This pull request don't contain a part of Git toolchain for example git-credential-store, etc. So I'm going to port other parts of Git toolchain too in the future.

Whole installing process is published at
https://medium.com/@lufia/14fee2ad7493

lufia (6):
Change HOME, PATH, and .gitconfig paths to be customizable Fix C syntactic errors for the Plan 9 C compiler
GIT-VERSION-GEN: Use sed instead of expr
Port generate-cmdline.sh to rc
Add plan9/wrap.c
Add mkfile to build git and subcommands for Plan 9

 GIT-VERSION-GEN               |   2 +-
 Makefile                      |  26 ++++-
 builtin/config.c              |   2 +-
 compat/plan9/openssl/crypto.h |   5 +
 compat/regex/regex_internal.h |   3 +
 config.c                      |   5 +-
 credential-cache.c            |   2 +-
 credential-store.c            |   2 +-
 exec-cmd.c                    |   4 +-
 generate-cmdlist.rc           | 102 ++++++++++++++++++
 git-compat-util.h             |  17 ++-
 help.c                        |   2 +-
 mkfile                        | 195 ++++++++++++++++++++++++++++++++++
 parse-options.h               |  18 ++--
 path.c                        |   6 +-
 plan9/wrap.c                  |  16 +++
 remove-bitfields.rc           |  14 +++
 run-command.c                 |   4 +-
 sequencer.c                   |   2 +-
 shell.c                       |   2 +-
 20 files changed, 402 insertions(+), 27 deletions(-)
 create mode 100644 compat/plan9/openssl/crypto.h
 create mode 100755 generate-cmdlist.rc
 create mode 100644 mkfile
 create mode 100644 plan9/wrap.c
 create mode 100644 remove-bitfields.rc

base-commit: f36d08d72e7f68f880f8c1d7646cb3809c820485
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-305%2Flufia%2Fplan9-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-305/lufia/plan9-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/305

Signature · 1 line
gitgitgadget
#1 lore raw

PATCH 1/6 Change HOME, PATH, and .gitconfig paths to be customizable

From: lufia <[email protected]>

In Plan 9, almost environment variables are not capitalized.

---
 Makefile           | 26 +++++++++++++++++++++++++-
 builtin/config.c   |  2 +-
 config.c           |  2 +-
 credential-cache.c |  2 +-
 credential-store.c |  2 +-
 exec-cmd.c         |  4 ++--
 git-compat-util.h  |  8 ++++++++
 help.c             |  2 +-
 path.c             |  6 +++---
 run-command.c      |  4 ++--
 sequencer.c        |  2 +-
 shell.c            |  2 +-
 12 files changed, 47 insertions(+), 15 deletions(-)
Makefile +25 -1
index bd246f2989..721364efba 100644
@@ -541,6 +541,9 @@ template_dir = share/git-core/templates
 htmldir = $(prefix)/share/doc/git-doc
 ETC_GITCONFIG = $(sysconfdir)/gitconfig
 ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
+USER_GITCONFIG = ~/.gitconfig
+USER_GITCREDENTIALS = ~/.git-credentials
+USER_GITCREDENTIAL_CACHE = ~/.git-credential-cache
 lib = lib
 # DESTDIR =
 pathsep = :
@@ -1910,6 +1913,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))
@@ -2400,12 +2406,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)"'
builtin/config.c +1 -1
index 98d65bc0ad..22c4f0ab71 100644
@@ -625,7 +625,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)
config.c +1 -1
index ed7f58e0fc..f67cef5cf8 100644
@@ -1699,7 +1699,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;
 
 	if (opts->commondir)
credential-cache.c +1 -1
index 1cccc3a0b9..3e2ed6c0be 100644
@@ -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
credential-store.c +1 -1
index ac295420dd..37256ee942 100644
@@ -168,7 +168,7 @@ int cmd_main(int argc, const char **argv)
 	if (file) {
 		string_list_append(&fns, file);
 	} else {
-		if ((file = expand_user_path("~/.git-credentials", 0)))
+		if ((file = expand_user_path(USER_GITCREDENTIALS, 0)))
 			string_list_append_nodup(&fns, file);
 		file = xdg_config_home("credentials");
 		if (file)
exec-cmd.c +2 -2
index 7deeab3039..c95fc8dbdd 100644
@@ -304,7 +304,7 @@ static void add_path(struct strbuf *out, const char *path)
 void setup_path(void)
 {
 	const char *exec_path = git_exec_path();
-	const char *old_path = getenv("PATH");
+	const char *old_path = getenv(PATH_ENVIRONMENT);
 	struct strbuf new_path = STRBUF_INIT;
 
 	git_set_exec_path(exec_path);
@@ -315,7 +315,7 @@ void setup_path(void)
 	else
 		strbuf_addstr(&new_path, _PATH_DEFPATH);
 
-	setenv("PATH", new_path.buf, 1);
+	setenv(PATH_ENVIRONMENT, new_path.buf, 1);
 
 	strbuf_release(&new_path);
 }
git-compat-util.h +8 -0
index 83be89de0a..f8fdd79591 100644
@@ -1238,6 +1238,14 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
 # define SHELL_PATH "/bin/sh"
 #endif
 
+#ifndef HOME_ENVIRONMENT
+# define HOME_ENVIRONMENT "HOME"
+#endif
+
+#ifndef PATH_ENVIRONMENT
+# define PATH_ENVIRONMENT "PATH"
+#endif
+
 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 #define flockfile(fh)
 #define funlockfile(fh)
help.c +1 -1
index 5261d83ecf..6094bfae7d 100644
@@ -260,7 +260,7 @@ void load_command_list(const char *prefix,
 		struct cmdnames *main_cmds,
 		struct cmdnames *other_cmds)
 {
-	const char *env_path = getenv("PATH");
+	const char *env_path = getenv(PATH_ENVIRONMENT);
 	const char *exec_path = git_exec_path();
 
 	if (exec_path) {
path.c +3 -3
index 25e97b8c3f..45bde04d37 100644
@@ -719,7 +719,7 @@ char *expand_user_path(const char *path, int real_home)
 		const char *username = path + 1;
 		size_t username_len = first_slash - username;
 		if (username_len == 0) {
-			const char *home = getenv("HOME");
+			const char *home = getenv(HOME_ENVIRONMENT);
 			if (!home)
 				goto return_null;
 			if (real_home)
@@ -1426,7 +1426,7 @@ char *xdg_config_home(const char *filename)
 	if (config_home && *config_home)
 		return mkpathdup("%s/git/%s", config_home, filename);
 
-	home = getenv("HOME");
+	home = getenv(HOME_ENVIRONMENT);
 	if (home)
 		return mkpathdup("%s/.config/git/%s", home, filename);
 	return NULL;
@@ -1441,7 +1441,7 @@ char *xdg_cache_home(const char *filename)
 	if (cache_home && *cache_home)
 		return mkpathdup("%s/git/%s", cache_home, filename);
 
-	home = getenv("HOME");
+	home = getenv(HOME_ENVIRONMENT);
 	if (home)
 		return mkpathdup("%s/.cache/git/%s", home, filename);
 	return NULL;
run-command.c +2 -2
index 3449db319b..85d7a8c342 100644
@@ -180,14 +180,14 @@ int is_executable(const char *name)
  */
 static char *locate_in_PATH(const char *file)
 {
-	const char *p = getenv("PATH");
+	const char *p = getenv(PATH_ENVIRONMENT);
 	struct strbuf buf = STRBUF_INIT;
 
 	if (!p || !*p)
 		return NULL;
 
 	while (1) {
-		const char *end = strchrnul(p, ':');
+		const char *end = strchrnul(p, PATH_SEP);
 
 		strbuf_reset(&buf);
 
sequencer.c +1 -1
index 34ebf8ed94..044b0fabea 100644
@@ -1246,7 +1246,7 @@ N_("Your name and email address were configured automatically based\n"
 
 static const char *implicit_ident_advice(void)
 {
-	char *user_config = expand_user_path("~/.gitconfig", 0);
+	char *user_config = expand_user_path(USER_GITCONFIG, 0);
 	char *xdg_config = xdg_config_home("config");
 	int config_exists = file_exists(user_config) || file_exists(xdg_config);
 
shell.c +1 -1
index 40084a3013..fa844425b9 100644
@@ -39,7 +39,7 @@ static char *make_cmd(const char *prog)
 
 static void cd_to_homedir(void)
 {
-	const char *home = getenv("HOME");
+	const char *home = getenv(HOME_ENVIRONMENT);
 	if (!home)
 		die("could not determine user's home directory; HOME is unset");
 	if (chdir(home) == -1)
Signature · 1 line
gitgitgadget
#2 lore raw

PATCH 2/6 Fix C syntactic errors for the Plan 9 C compiler

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

---
 compat/plan9/openssl/crypto.h |  5 +++++
 compat/regex/regex_internal.h |  3 +++
 config.c                      |  3 ++-
 git-compat-util.h             |  9 ++++++++-
 parse-options.h               | 18 +++++++++---------
 remove-bitfields.rc           | 14 ++++++++++++++
 6 files changed, 41 insertions(+), 11 deletions(-)
 create mode 100644 compat/plan9/openssl/crypto.h
 create mode 100644 remove-bitfields.rc
compat/plan9/openssl/crypto.h new file +5 -0
new file mode 100644
index 0000000000..9d1ef43422
@@ -0,0 +1,5 @@
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+
+#include_next <openssl/crypto.h>
compat/regex/regex_internal.h +3 -0
index 3ee8aae59d..7313c747a6 100644
@@ -26,6 +26,9 @@
 #include <stdlib.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
config.c +2 -1
index f67cef5cf8..993f9f57be 100644
@@ -2461,7 +2461,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;
 
git-compat-util.h +8 -1
index f8fdd79591..1aa7877af4 100644
@@ -164,7 +164,11 @@
 #define GIT_WINDOWS_NATIVE
 #endif
 
+#include <sys/types.h>
 #include <unistd.h>
+#ifdef __PLAN9__
+#include <libv.h>
+#endif
 #include <stdio.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -180,7 +184,6 @@
 #ifdef NEEDS_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#include <sys/types.h>
 #include <dirent.h>
 #include <sys/time.h>
 #include <time.h>
@@ -282,6 +285,10 @@ char *gitbasename(char *);
 char *gitdirname(char *);
 #endif
 
+#ifdef __PLAN9__
+#include <machine/endian.h>
+#endif
+
 #ifndef NO_ICONV
 #include <iconv.h>
 #endif
parse-options.h +9 -9
index a4bd40bb6a..38a33a087e 100644
@@ -46,6 +46,15 @@ enum parse_opt_option_flags {
 	PARSE_OPT_COMP_ARG = 1024
 };
 
+enum parse_opt_result {
+	PARSE_OPT_COMPLETE = -3,
+	PARSE_OPT_HELP = -2,
+	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
+	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
+	PARSE_OPT_NON_OPTION,
+	PARSE_OPT_UNKNOWN
+};
+
 struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
@@ -241,15 +250,6 @@ const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
-enum parse_opt_result {
-	PARSE_OPT_COMPLETE = -3,
-	PARSE_OPT_HELP = -2,
-	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
-	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
-	PARSE_OPT_NON_OPTION,
-	PARSE_OPT_UNKNOWN
-};
-
 /*
  * It's okay for the caller to consume argv/argc in the usual way.
  * Other fields of that structure are private to parse-options and should not
remove-bitfields.rc new file +14 -0
new file mode 100644
index 0000000000..897f98da10
@@ -0,0 +1,14 @@
+#!/bin/rc
+# Plan 9 C compiler rejects initialization a structure including bit field.
+# usage: remove-bitfields.rc [dir ...]
+
+fn sigexit sighup sigint sigquit sigterm {
+	rm -f /tmp/remove-bitfields.$pid
+	exit
+}
+
+files=`{du -a $* | awk '/\.[ch]$/ { print $2 }'}
+for(i in $files){
+	sed '/(^[ 	]*\*|\?)/!s/([a-z]+[a-z0-9]*) *: *[0-9]+([,;])/\1\2/g' $i >/tmp/remove-bitfields.$pid
+	cp /tmp/remove-bitfields.$pid $i
+}
Signature · 1 line
gitgitgadget
#3 lore raw

PATCH 3/6 GIT-VERSION-GEN: Use sed instead of expr

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

Plan 9 don't have expr(1).

---
 GIT-VERSION-GEN | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
GIT-VERSION-GEN +1 -1
index a0766f64ed..754d4486f5 100755
@@ -26,7 +26,7 @@ else
 	VN="$DEF_VER"
 fi
 
-VN=$(expr "$VN" : v*'\(.*\)')
+VN=$(echo "$VN" | sed 's/^v*//')
 
 if test -r $GVF
 then
Signature · 1 line
gitgitgadget
#4 lore raw

Re: [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr

Quoted 14 lines · lufia via GitGitGadget

From: lufia <[email protected]>

Plan 9 don't have expr(1).

---
 GIT-VERSION-GEN | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
GIT-VERSION-GEN +0 -0
index a0766f64ed..754d4486f5 100755

GIT-VERSION-GEN else · line 29

Quoted 5 lines
GIT-VERSION-GEN +1 -1
@@ -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.

#5 lore raw

PATCH 4/6 Port generate-cmdline.sh to rc

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

---
 generate-cmdlist.rc | 102 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100755 generate-cmdlist.rc
generate-cmdlist.rc new file +102 -0
new file mode 100755
index 0000000000..18699ea9c4
@@ -0,0 +1,102 @@
+#!/bin/rc
+
+rfork e
+
+fn die {
+	echo $* >[1=2]
+	exit die
+}
+
+fn command_list {
+	grep -v '^#' $1
+}
+
+fn get_categories {
+	tr ' ' '\x0a'|
+	grep -v '^$' |
+	sort |
+	uniq
+}
+
+fn category_list {
+	command_list $1 |
+	awk '{ print substr($0, 40) }' |
+	get_categories
+}
+
+fn get_synopsis {
+	sed -n '
+		/^NAME/,/'$1'/h
+		${
+			x
+			s/.*'$1' - (.*)/N_\("\1"\)/
+			p
+		}' Documentation/$1.txt
+}
+
+fn define_categories {
+	echo
+	echo '/* Command categories */'
+	bit=0
+	category_list $1 |
+	while(cat=`{read}){
+		echo '#define CAT_'$"cat' (1UL << '$bit')'
+		bit=`{hoc -e $bit' + 1'}
+	}
+	test $bit -gt 32 && die 'Urgh.. too many categories?'
+}
+
+fn define_category_names {
+	echo
+	echo '/* Category names */'
+	echo 'static const char *category_names[] = {'
+	bit=0
+	category_list $1 |
+	while(cat=`{read}){
+		echo '	"'$"cat'", /* (1UL << '$bit') */'
+		bit=`{hoc -e $bit' + 1'}
+	}
+	echo '	NULL,'
+	echo '};'
+}
+
+fn print_command_list {
+	echo 'static struct cmdname_help command_list[] = {'
+
+	command_list $1 |
+	while(a=`{read}){
+		s=`{get_synopsis $a(1)}
+		q=`{seq 2 $#a}
+		echo -n '	{ "'^$a(1)^'", '$"s', 0'
+		for(cat in `{echo $a($q) | get_categories})
+			echo -n ' | CAT_'^$cat
+		echo ' },'
+	}
+	echo '};'
+}
+
+fn print_config_list {
+	echo 'static const char *config_name_list[] = {'
+	grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
+	sed '/deprecated/d; s/::$//; s/,  */\n/g' |
+	sort |
+	while(line=`{read})
+		echo '	"'$"line'",'
+	echo '	NULL'
+	echo '};'
+}
+
+echo '/* Automatically generated by generate-cmdlist.sh */
+struct cmdname_help {
+	const char *name;
+	const char *help;
+	uint32_t category;
+};
+'
+define_categories $1
+echo
+define_category_names $1
+echo
+print_command_list $1
+echo
+print_config_list
Signature · 1 line
gitgitgadget
#6 lore raw

PATCH 5/6 Add plan9/wrap.c

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

Plan 9 has bind(1) instead of ln(1), but bind isn't persisted to the disk. However it isn't efficient to copy git to git- subcommands such as git-add. Therefore Plan 9 needs wrap.c to switch behavior by executable name.

---
 plan9/wrap.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 plan9/wrap.c
plan9/wrap.c new file +16 -0
new file mode 100644
index 0000000000..589d13bf5d
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#define _POSIX_SOURCE
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+	USED(argc);
+	if(execv("/bin/git", argv) < 0){
+		fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
+		return 1;
+	}
+	return 0; /* can't happen */
+}
Signature · 1 line
gitgitgadget
#7 lore raw

Re: [PATCH 5/6] Add plan9/wrap.c

Quoted 5 lines · lufia via GitGitGadget

From: lufia <[email protected]>

Plan 9 has bind(1) instead of ln(1), but bind isn't persisted to the disk. However it isn't efficient to copy git to git- subcommands such as git-add. Therefore Plan 9 needs wrap.c to switch behavior by executable name.

Does Plan 9 have symbolic links? The INSTALL_SYMLINKS option uses symlinks instead, which should avoid the need for hard links.

Signature · 2 lines
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
#8 lore raw

Re: [PATCH 5/6] Add plan9/wrap.c

2019-08-04(Sun) 9:03 brian m. carlson <[email protected]>:

Quoted 8 lines · lufia via GitGitGadget
Quoted 5 lines

From: lufia <[email protected]>

Plan 9 has bind(1) instead of ln(1), but bind isn't persisted to the disk. However it isn't efficient to copy git to git- subcommands such as git-add. Therefore Plan 9 needs wrap.c to switch behavior by executable name.

Quoted 5 lines

Does Plan 9 have symbolic links? The INSTALL_SYMLINKS option uses symlinks instead, which should avoid the need for hard links. --
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

No, Plan 9 don't have a feature to create symbolic link. I think Plan 9 will not be going to have hard- and symbolic- links.
http://doc.cat-v.org/plan_9/4th_edition/papers/lexnames

#9 lore raw

PATCH 6/6 Add mkfile to build git and subcommands for Plan 9

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

---
 mkfile | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 195 insertions(+)
 create mode 100644 mkfile
mkfile new file +195 -0
new file mode 100644
index 0000000000..f0b06437ed
@@ -0,0 +1,195 @@
+</sys/src/ape/config
+
+CFILES=`{sed -n '/^BUILTIN_OBJS *\+= *(.*)\.o$/s//\1.c/p' Makefile}
+OFILES=\
+	${CFILES:%.c=%.$O}\
+	common-main.$O\
+
+X_CFILES=`{sed -n '/^BUILT_INS *\+= *git-(.*)\$X$/s//\1/p' Makefile}
+
+#APP_CFILES=`{sed -n '/^PROGRAM_OBJS *\+= *(.*)\.o$/s//\1.c/p' Makefile}
+APP_CFILES=\
+	credential-store.c\
+	http-fetch.c\
+	http-push.c\
+
+TARG=\
+	git\
+	${CFILES:builtin/%.c=git-%}\
+	${X_CFILES:%=git-%}\
+	${APP_CFILES:%.c=git-%}\
+	git-remote-http\
+	git-remote-https\
+	git-remote-ftp\
+	git-remote-ftps\
+
+# NO_UNIXSOCK
+#	git-credential-cache\
+#	git-credential-cache--daemon\
+
+#GIT_HOST_CPU=i386|i686|x86_64
+
+ROOT=`{pwd}
+<GIT-VERSION-FILE
+COMMIT_HASH=`{git rev-parse -q --verify HEAD}
+
+# -w flag isn't intentionally set because it is noisy.
+# -T flag isn't intentionally set.
+CFLAGS=-FVB+ -c\
+	-I$ROOT\
+	-I$ROOT/compat/plan9\
+	-I$ROOT/compat/regex\
+	-D__PLAN9__\
+	-D_POSIX_SOURCE\
+	-D_BSD_EXTENSION\
+	-D_SUSV2_SOURCE\
+	-D_PLAN9_SOURCE\
+	-D_RESEARCH_SOURCE\
+	-D_REENTRANT_SOURCE\
+	-DHAVE_SOCK_OPTS\
+	-DNO_NSEC\
+	-DNO_SYMLINK_HEAD\
+	-DNO_GECOS_IN_PWENT\
+	-DNO_GETTEXT\
+	-DNO_STRCASESTR\
+	-DNO_STRLCPY\
+	-DNO_STRTOUMAX\
+	-DNO_MBSUPPORT\
+	-DNO_MKDTEMP\
+	-DNO_UNSETENV\
+	-DNEEDS_SYS_PARAM_H\
+	-DNO_INITGROUPS\
+	-DNO_MMAP\
+	-DNO_ST_BLOCKS_IN_STRUCT_STAT\
+	-DNO_STRUCT_ITIMERVAL\
+	-DNO_SETITIMER\
+	-Dsockaddr_storage=sockaddr_in6\
+	-DNO_UNIX_SOCKETS\
+	-DNO_ICONV\
+	-DSHA1_OPENSSL\
+	-DSHA256_OPENSSL\
+	-DNO_MEMMEM\
+	-DHAVE_STDBOOL_H\
+	-DHAVE_STDINT_H\
+	-DHAVE_LOCALE_H\
+	-DHAVE_CLOCK_GETTIME\
+	-DGIT_VERSION="$GIT_VERSION"\
+	-DGIT_BUILT_FROM_COMMIT="$COMMIT_HASH"\
+	-DGIT_USER_AGENT="git/$GIT_VERSION"\
+	-DETC_GITCONFIG="/sys/lib/git/config"\
+	-DETC_GITATTRIBUTES="/sys/lib/git/attributes"\
+	-DUSER_GITCONFIG="~/lib/git/config"\
+	-DUSER_GITCREDENTIALS="~/lib/git/credentials"\
+	-DUSER_GITCREDENTIAL_CACHE="~/lib/git/credential-cache"\
+	-DDEFAULT_GIT_TEMPLATE_DIR="/sys/lib/git/templates"\
+	-DGIT_HOST_CPU="i386"\
+	-DGIT_EXEC_PATH="/bin/git-core"\
+	-DGIT_MAN_PATH="/sys/man"\
+	-DGIT_INFO_PATH=""\
+	-DGIT_HTML_PATH=""\
+	-DFALLBACK_RUNTIME_PREFIX="/bin/git-core"\
+	-DDEFAULT_PAGER="/bin/p"\
+	-DPAGER_ENV="terminal="\
+	-DHOME_ENVIRONMENT="home"\
+	-DPATH_ENVIRONMENT="path"\
+	-D_PATH_SEP=1\
+	-D_PATH_DEFPATH="/bin"\
+	-DSHELL_PATH="/bin/rc"\
+
+LIB_CFILES=`{sed -n '/^LIB_OBJS *\+= *(.*)\.o$/s//\1.c/p' Makefile}
+LIB_OFILES=\
+	${LIB_CFILES:%.c=%.$O}\
+	compat/qsort_s.$O\
+	compat/strcasestr.$O\
+	compat/strlcpy.$O\
+	compat/strtoumax.$O\
+	compat/strtoimax.$O\
+	compat/setenv.$O\
+	compat/mkdtemp.$O\
+	compat/unsetenv.$O\
+	compat/mmap.$O\
+	compat/memmem.$O\
+	compat/regex/regex.$O\
+
+XDIFF_CFILES=`{sed -n '/^XDIFF_OBJS *\+= *(.*)\.o$/s//\1.c/p' Makefile}
+XDIFF_OFILES=${XDIFF_CFILES:%.c=%.$O}
+
+HFILES=\
+	`{ls *.h}\
+	`{ls */*.h}\
+	`{ls */*/*.h}\
+	`{ls */*/*/*.h}\
+	command-list.h\
+
+BIN=/$objtype/bin/git-core
+OBJBIN=/$objtype/bin
+
+LIB=\
+	libgit.a$O\
+	xdiff/lib.a$O\
+	/$objtype/lib/ape/libcurl.a\
+	/$objtype/lib/ape/libssl.a\
+	/$objtype/lib/ape/libcrypto.a\
+	/$objtype/lib/ape/libexpat.a\
+	/$objtype/lib/ape/libz.a\
+
+CLEANFILES=command-list.h
+
+</sys/src/cmd/mkmany
+
+LIBGIT=libgit.a$O
+LIBGITOBJ=${LIB_OFILES:%=$LIBGIT(%)}
+LIBXDIFF=xdiff/lib.a$O
+LIBXDIFFOBJ=${XDIFF_OFILES:%=$LIBXDIFF(%)}
+
+command-list.h:D:	command-list.txt
+	rc ./generate-cmdlist.rc $prereq >$target
+
+${CFILES:builtin/%.c=$O.git-%} ${X_CFILES:%=$O.git-%}:D:	plan9/wrap.c
+	for(i in $target)
+		$CC -FTVw -o $i $prereq
+
+$O.git-credential-store:	credential-store.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+$O.git-http-fetch:	http-fetch.$O http.$O http-walker.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+$O.git-http-push:	http-push.$O http.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+git-http-%.$O:	http-%.c
+	$CC $CFLAGS -o $target $prereq
+
+$O.git-remote-http:	remote-curl.$O http.$O http-walker.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+$O.git-remote-https:	remote-curl.$O http.$O http-walker.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+$O.git-remote-ftp:	remote-curl.$O http.$O http-walker.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+$O.git-remote-ftps:	remote-curl.$O http.$O http-walker.$O common-main.$O $LIB
+	$LD $LDFLAGS -o $target $prereq
+
+# git should be copied into both $BIN and $OBJBIN
+git.install:V:	$O.git
+	cp $O.git $OBJBIN/git
+
+$LIBGIT:	$LIBGITOBJ
+	ar vu $target $newmember
+
+$LIBXDIFF:	$LIBXDIFFOBJ
+	ar vu $target $newmember
+
+%.$O:	%.c
+	$CC $CFLAGS -o $target $stem.c
+
+$LIBGIT(%.$O):N:	%.$O
+
+$LIBXDIFF(%.$O):N:	%.$O
+
+clean:V:
+	rm -f *.[$OS] [$OS].out y.tab.? lex.yy.c y.debug y.output $CLEANFILES
+	rm -f */*.[$OS] */*/*.[$OS]
Signature · 1 line
gitgitgadget
#10 lore raw
In reply to KADOTA, Kyohei via GitGitGadget
Quoted 11 lines · Kyohei via GitGitGadget

I ported git, and git subcommands only written in C to Plan 9. This pull request contains patches for existing codes, and new files to build git in Plan 9.

All build options such as NO_PERL are not supported yet, and also some git subcommands written not in C is not available yet. But git can synchronize to remote repository with git pull and git push via HTTPS.

This pull request don't contain a part of Git toolchain for example git-credential-store, etc. So I'm going to port other parts of Git toolchain too in the future.

This series seems to build a whole new build system that uses Plan 9 tools. Typically the way ports to non-POSIX platforms (such as Windows) have been handled is that the Unix tools, including GNU make, have been ported to those platforms, and the POSIX (or POSIX-ish) environment used there.

I'm concerned that by introducing a whole bunch of new, Plan 9-specific build code, we're going to have it fall behind with features or bug fixes, because none of the main developers test on Plan 9, and most contributors will not have the Plan 9 skills or systems to maintain the code.

In addition, the editor used by git commit and other commands invokes "sh", but you've set this to "rc". That's completely different from the way that all other environments work, and it means that Git on Plan 9 operates in a totally different, incompatible way there. We also use a POSIX shell for the testsuite, and we rely on it quite heavily. rc is not going to cut it there.

Plan 9 has a POSIX environment, and I think it might be a better idea to require that as a condition for building and running Git. It will likely be a lot easier, at least.

Signature · 2 lines
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
#11 lore raw

2019-08-04(Sun) 9:38 brian m. carlson <[email protected]>:

Quoted 33 lines · Kyohei via GitGitGadget
Quoted 11 lines

I ported git, and git subcommands only written in C to Plan 9. This pull request contains patches for existing codes, and new files to build git in Plan 9.

All build options such as NO_PERL are not supported yet, and also some git subcommands written not in C is not available yet. But git can synchronize to remote repository with git pull and git push via HTTPS.

This pull request don't contain a part of Git toolchain for example git-credential-store, etc. So I'm going to port other parts of Git toolchain too in the future.

This series seems to build a whole new build system that uses Plan 9 tools. Typically the way ports to non-POSIX platforms (such as Windows) have been handled is that the Unix tools, including GNU make, have been ported to those platforms, and the POSIX (or POSIX-ish) environment used there.

I'm concerned that by introducing a whole bunch of new, Plan 9-specific build code, we're going to have it fall behind with features or bug fixes, because none of the main developers test on Plan 9, and most contributors will not have the Plan 9 skills or systems to maintain the code.

In addition, the editor used by git commit and other commands invokes "sh", but you've set this to "rc". That's completely different from the way that all other environments work, and it means that Git on Plan 9 operates in a totally different, incompatible way there. We also use a POSIX shell for the testsuite, and we rely on it quite heavily. rc is not going to cut it there.

Quoted 6 lines

Plan 9 has a POSIX environment, and I think it might be a better idea to require that as a condition for building and running Git. It will likely be a lot easier, at least.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

I think it is possible to replace rc with ape/sh, ape/sh is POSIX shell in Plan 9.

However Plan 9 don't have recent versions of Unix tools, such as gcc, g++, autotools, gmake or perl,
so it is VERY hard to use Makefile instead of mkfile.

#12 lore raw

Hi,

Quoted 6 lines · Kyohei Kadota

I think it is possible to replace rc with ape/sh, ape/sh is POSIX shell in Plan 9.

However Plan 9 don't have recent versions of Unix tools, such as gcc, g++, autotools, gmake or perl,
so it is VERY hard to use Makefile instead of mkfile.

The default Git build doesn't use autotools. See INSTALL for more details.

What version of gmake is available for Plan 9? I wouldn't expect Git's build system to be super demanding as far as recent "make" features go.

So I wonder whether it would make sense to do something like the following:

- add entries to config.mak.uname to set the compiler e.g. to 6c when appropriate

- make appropriate compatibility fixes in git-compat-util.h

- add any necessary helpers to the compat/ directory

- use gmake to build

Would that work?

Thanks,
Jonathan

#13 lore raw

v2 cover Port git to Plan 9

In reply to KADOTA, Kyohei via GitGitGadget

Changes from v1
===============

* Use gmake
* Use sh
* Remove dependencies to Plan 9 tools; rc and mk

What I did
==========

I ported git, and git subcommands with gmake to Plan 9. This pull request contains patches for existing codes, and new files to build git in Plan 9.

I added three new options into Makefile.

* USER_GITCONFIG - default ~/.gitconfig
* USER_GITCREDENTIALS - default ~/.git-credentials
* USER_GITCREDENTIAL_CACHE - default ~/.git-credential-cache
* USE_EXEC_WRAPPER - default empty

In Plan 9, user configuration files are stored at $home/lib, instead of dotfiles.
http://xahlee.info/UnixResource_dir/writ/unix_origin_of_dot_filename.html

And Plan 9 haven't hard link and symbolic link. Thus I added exec-wrapper to want to shrink disk usage.
http://doc.cat-v.org/plan_9/4th_edition/papers/lexnames

Installation
============

# ANSI/POSIX commands are installed at /bin only in current namespace. % bind -a /bin/ape /bin

# Plan 9 C compiler can't initialize struct fields that is bit field so remove bit fields from all C files. % ./remove-bitfields.sh

# build Git toolchain with /n/sources/contrib/andrey/make-3.81.tgz
% gmake 'prefix=' 'gitexecdir=bin/git-core' 'sysconfdir=sys/lib/git' 'template_dir=sys/lib/git/templates' install

lufia (3):
Change HOME, PATH, and .gitconfig paths to be customizable Fix C syntactic errors for the Plan 9 C compiler Support Plan 9 dialect

 GIT-VERSION-GEN               |  2 +-
 Makefile                      | 81 +++++++++++++++++++++++-----
 builtin/config.c              |  2 +-
 compat/plan9/openssl/crypto.h |  5 ++
 compat/regex/regex_internal.h |  3 ++
 config.c                      |  5 +-
 config.mak.uname              | 99 +++++++++++++++++++++++++++++++++++
 credential-cache.c            |  2 +-
 credential-store.c            |  2 +-
 exec-cmd.c                    |  4 +-
 exec-wrapper.c                | 16 ++++++
 generate-cmdlist.sh           | 24 ++++++---
 git-compat-util.h             | 17 +++++-
 help.c                        |  2 +-
 parse-options.h               | 18 +++----
 path.c                        |  6 +--
 remove-bitfields.sh           | 17 ++++++
 run-command.c                 |  4 +-
 sequencer.c                   |  2 +-
 shell.c                       |  2 +-
 t/chainlint.sed               | 66 +++++++++++------------
 templates/Makefile            | 12 ++++-
 22 files changed, 311 insertions(+), 80 deletions(-)
 create mode 100644 compat/plan9/openssl/crypto.h
 create mode 100644 exec-wrapper.c
 create mode 100755 remove-bitfields.sh

base-commit: 745f6812895b31c02b29bdfe4ae8e5498f776c26
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-305%2Flufia%2Fplan9-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-305/lufia/plan9-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/305

Range-diff vs v1:

1: fa539c75b2 ! 1: 63e7e7794e Change HOME, PATH, and .gitconfig paths to be customizable

     @@ -10,12 +10,26 @@
       --- a/Makefile
       +++ b/Makefile
      @@
     + localedir = $(sharedir)/locale
     + template_dir = share/git-core/templates
       htmldir = $(prefix)/share/doc/git-doc
     - ETC_GITCONFIG = $(sysconfdir)/gitconfig
     - ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
     -+USER_GITCONFIG = ~/.gitconfig
     -+USER_GITCREDENTIALS = ~/.git-credentials
     -+USER_GITCREDENTIAL_CACHE = ~/.git-credential-cache
     +-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 = :
 2:  301a796de9 ! 2:  7abbd36e1d Fix C syntactic errors for the Plan 9 C compiler
     @@ -114,22 +114,25 @@
        * It's okay for the caller to consume argv/argc in the usual way.
        * Other fields of that structure are private to parse-options and should not
      
     - diff --git a/remove-bitfields.rc b/remove-bitfields.rc
     - new file mode 100644
     + diff --git a/remove-bitfields.sh b/remove-bitfields.sh
     + new file mode 100755
       --- /dev/null
     - +++ b/remove-bitfields.rc
     + +++ b/remove-bitfields.sh
      @@
     -+#!/bin/rc
     ++#!/bin/ape/sh
      +# Plan 9 C compiler rejects initialization a structure including bit field.
     -+# usage: remove-bitfields.rc [dir ...]
     ++# usage: remove-bitfields.sh [dir ...]
     ++
     ++if ! echo abc | sed 's/(ab)c/\1/' >/dev/null 2>&1
     ++then
     ++	alias sed='sed -E'
     ++fi
      +
     -+fn sigexit sighup sigint sigquit sigterm {
     -+	rm -f /tmp/remove-bitfields.$pid
     -+	exit
     -+}
     ++trap 'rm -f /tmp/remove-bitfields.$pid; exit 1' 1 2 3 15 EXIT
      +
     -+files=`{du -a $* | awk '/\.[ch]$/ { print $2 }'}
     -+for(i in $files){
     ++files=$(du -a $* | awk '/\.[ch]$/ { print $2 }')
     ++for i in $files
     ++do
      +	sed '/(^[ 	]*\*|\?)/!s/([a-z]+[a-z0-9]*) *: *[0-9]+([,;])/\1\2/g' $i >/tmp/remove-bitfields.$pid
      +	cp /tmp/remove-bitfields.$pid $i
     -+}
     ++done
 3:  df67a7e1d3 < -:  ---------- GIT-VERSION-GEN: Use sed instead of expr
 4:  d25bcb43e1 < -:  ---------- Port generate-cmdline.sh to rc
 5:  d00bbdce0d < -:  ---------- Add plan9/wrap.c
 6:  0494971306 < -:  ---------- Add mkfile to build git and subcommands for Plan 9
 -:  ---------- > 3:  7505e85fc5 Support Plan 9 dialect
Signature · 1 line
gitgitgadget
#14 lore raw

PATCH v2 1/3 Change HOME, PATH, and .gitconfig paths to be customizable

From: lufia <[email protected]>

In Plan 9, almost environment variables are not capitalized.

---
 Makefile           | 40 +++++++++++++++++++++++++++++++++++++---
 builtin/config.c   |  2 +-
 config.c           |  2 +-
 credential-cache.c |  2 +-
 credential-store.c |  2 +-
 exec-cmd.c         |  4 ++--
 git-compat-util.h  |  8 ++++++++
 help.c             |  2 +-
 path.c             |  6 +++---
 run-command.c      |  4 ++--
 sequencer.c        |  2 +-
 shell.c            |  2 +-
 12 files changed, 59 insertions(+), 17 deletions(-)
Makefile +37 -3
index f9255344ae..04ff7df64a 100644
@@ -539,8 +539,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 = :
@@ -1910,6 +1923,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))
@@ -2400,12 +2416,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)"'
builtin/config.c +1 -1
index 98d65bc0ad..22c4f0ab71 100644
@@ -625,7 +625,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)
config.c +1 -1
index 3900e4947b..14de96ee6d 100644
@@ -1700,7 +1700,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;
 
 	if (opts->commondir)
credential-cache.c +1 -1
index 1cccc3a0b9..3e2ed6c0be 100644
@@ -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
credential-store.c +1 -1
index ac295420dd..37256ee942 100644
@@ -168,7 +168,7 @@ int cmd_main(int argc, const char **argv)
 	if (file) {
 		string_list_append(&fns, file);
 	} else {
-		if ((file = expand_user_path("~/.git-credentials", 0)))
+		if ((file = expand_user_path(USER_GITCREDENTIALS, 0)))
 			string_list_append_nodup(&fns, file);
 		file = xdg_config_home("credentials");
 		if (file)
exec-cmd.c +2 -2
index 7deeab3039..c95fc8dbdd 100644
@@ -304,7 +304,7 @@ static void add_path(struct strbuf *out, const char *path)
 void setup_path(void)
 {
 	const char *exec_path = git_exec_path();
-	const char *old_path = getenv("PATH");
+	const char *old_path = getenv(PATH_ENVIRONMENT);
 	struct strbuf new_path = STRBUF_INIT;
 
 	git_set_exec_path(exec_path);
@@ -315,7 +315,7 @@ void setup_path(void)
 	else
 		strbuf_addstr(&new_path, _PATH_DEFPATH);
 
-	setenv("PATH", new_path.buf, 1);
+	setenv(PATH_ENVIRONMENT, new_path.buf, 1);
 
 	strbuf_release(&new_path);
 }
git-compat-util.h +8 -0
index 83be89de0a..f8fdd79591 100644
@@ -1238,6 +1238,14 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
 # define SHELL_PATH "/bin/sh"
 #endif
 
+#ifndef HOME_ENVIRONMENT
+# define HOME_ENVIRONMENT "HOME"
+#endif
+
+#ifndef PATH_ENVIRONMENT
+# define PATH_ENVIRONMENT "PATH"
+#endif
+
 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 #define flockfile(fh)
 #define funlockfile(fh)
help.c +1 -1
index 5261d83ecf..6094bfae7d 100644
@@ -260,7 +260,7 @@ void load_command_list(const char *prefix,
 		struct cmdnames *main_cmds,
 		struct cmdnames *other_cmds)
 {
-	const char *env_path = getenv("PATH");
+	const char *env_path = getenv(PATH_ENVIRONMENT);
 	const char *exec_path = git_exec_path();
 
 	if (exec_path) {
path.c +3 -3
index 25e97b8c3f..45bde04d37 100644
@@ -719,7 +719,7 @@ char *expand_user_path(const char *path, int real_home)
 		const char *username = path + 1;
 		size_t username_len = first_slash - username;
 		if (username_len == 0) {
-			const char *home = getenv("HOME");
+			const char *home = getenv(HOME_ENVIRONMENT);
 			if (!home)
 				goto return_null;
 			if (real_home)
@@ -1426,7 +1426,7 @@ char *xdg_config_home(const char *filename)
 	if (config_home && *config_home)
 		return mkpathdup("%s/git/%s", config_home, filename);
 
-	home = getenv("HOME");
+	home = getenv(HOME_ENVIRONMENT);
 	if (home)
 		return mkpathdup("%s/.config/git/%s", home, filename);
 	return NULL;
@@ -1441,7 +1441,7 @@ char *xdg_cache_home(const char *filename)
 	if (cache_home && *cache_home)
 		return mkpathdup("%s/git/%s", cache_home, filename);
 
-	home = getenv("HOME");
+	home = getenv(HOME_ENVIRONMENT);
 	if (home)
 		return mkpathdup("%s/.cache/git/%s", home, filename);
 	return NULL;
run-command.c +2 -2
index 3449db319b..85d7a8c342 100644
@@ -180,14 +180,14 @@ int is_executable(const char *name)
  */
 static char *locate_in_PATH(const char *file)
 {
-	const char *p = getenv("PATH");
+	const char *p = getenv(PATH_ENVIRONMENT);
 	struct strbuf buf = STRBUF_INIT;
 
 	if (!p || !*p)
 		return NULL;
 
 	while (1) {
-		const char *end = strchrnul(p, ':');
+		const char *end = strchrnul(p, PATH_SEP);
 
 		strbuf_reset(&buf);
 
sequencer.c +1 -1
index 34ebf8ed94..044b0fabea 100644
@@ -1246,7 +1246,7 @@ N_("Your name and email address were configured automatically based\n"
 
 static const char *implicit_ident_advice(void)
 {
-	char *user_config = expand_user_path("~/.gitconfig", 0);
+	char *user_config = expand_user_path(USER_GITCONFIG, 0);
 	char *xdg_config = xdg_config_home("config");
 	int config_exists = file_exists(user_config) || file_exists(xdg_config);
 
shell.c +1 -1
index 40084a3013..fa844425b9 100644
@@ -39,7 +39,7 @@ static char *make_cmd(const char *prog)
 
 static void cd_to_homedir(void)
 {
-	const char *home = getenv("HOME");
+	const char *home = getenv(HOME_ENVIRONMENT);
 	if (!home)
 		die("could not determine user's home directory; HOME is unset");
 	if (chdir(home) == -1)
Signature · 1 line
gitgitgadget
#15 lore raw

PATCH v2 2/3 Fix C syntactic errors for the Plan 9 C compiler

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

---
 compat/plan9/openssl/crypto.h |  5 +++++
 compat/regex/regex_internal.h |  3 +++
 config.c                      |  3 ++-
 git-compat-util.h             |  9 ++++++++-
 parse-options.h               | 18 +++++++++---------
 remove-bitfields.sh           | 17 +++++++++++++++++
 6 files changed, 44 insertions(+), 11 deletions(-)
 create mode 100644 compat/plan9/openssl/crypto.h
 create mode 100755 remove-bitfields.sh
compat/plan9/openssl/crypto.h new file +5 -0
new file mode 100644
index 0000000000..9d1ef43422
@@ -0,0 +1,5 @@
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+
+#include_next <openssl/crypto.h>
compat/regex/regex_internal.h +3 -0
index 3ee8aae59d..7313c747a6 100644
@@ -26,6 +26,9 @@
 #include <stdlib.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
config.c +2 -1
index 14de96ee6d..0024b767e5 100644
@@ -2462,7 +2462,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;
 
git-compat-util.h +8 -1
index f8fdd79591..1aa7877af4 100644
@@ -164,7 +164,11 @@
 #define GIT_WINDOWS_NATIVE
 #endif
 
+#include <sys/types.h>
 #include <unistd.h>
+#ifdef __PLAN9__
+#include <libv.h>
+#endif
 #include <stdio.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -180,7 +184,6 @@
 #ifdef NEEDS_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#include <sys/types.h>
 #include <dirent.h>
 #include <sys/time.h>
 #include <time.h>
@@ -282,6 +285,10 @@ char *gitbasename(char *);
 char *gitdirname(char *);
 #endif
 
+#ifdef __PLAN9__
+#include <machine/endian.h>
+#endif
+
 #ifndef NO_ICONV
 #include <iconv.h>
 #endif
parse-options.h +9 -9
index a4bd40bb6a..38a33a087e 100644
@@ -46,6 +46,15 @@ enum parse_opt_option_flags {
 	PARSE_OPT_COMP_ARG = 1024
 };
 
+enum parse_opt_result {
+	PARSE_OPT_COMPLETE = -3,
+	PARSE_OPT_HELP = -2,
+	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
+	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
+	PARSE_OPT_NON_OPTION,
+	PARSE_OPT_UNKNOWN
+};
+
 struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
@@ -241,15 +250,6 @@ const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
-enum parse_opt_result {
-	PARSE_OPT_COMPLETE = -3,
-	PARSE_OPT_HELP = -2,
-	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
-	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
-	PARSE_OPT_NON_OPTION,
-	PARSE_OPT_UNKNOWN
-};
-
 /*
  * It's okay for the caller to consume argv/argc in the usual way.
  * Other fields of that structure are private to parse-options and should not
remove-bitfields.sh new file +17 -0
new file mode 100755
index 0000000000..952bd34f12
@@ -0,0 +1,17 @@
+#!/bin/ape/sh
+# Plan 9 C compiler rejects initialization a structure including bit field.
+# usage: remove-bitfields.sh [dir ...]
+
+if ! echo abc | sed 's/(ab)c/\1/' >/dev/null 2>&1
+then
+	alias sed='sed -E'
+fi
+
+trap 'rm -f /tmp/remove-bitfields.$pid; exit 1' 1 2 3 15 EXIT
+
+files=$(du -a $* | awk '/\.[ch]$/ { print $2 }')
+for i in $files
+do
+	sed '/(^[ 	]*\*|\?)/!s/([a-z]+[a-z0-9]*) *: *[0-9]+([,;])/\1\2/g' $i >/tmp/remove-bitfields.$pid
+	cp /tmp/remove-bitfields.$pid $i
+done
Signature · 1 line
gitgitgadget
#16 lore raw

PATCH v2 3/3 Support Plan 9 dialect

In reply to KADOTA, Kyohei via GitGitGadget

From: lufia <[email protected]>

Plan 9 ANSI/POSIX environment is:
* No expr(1)
* sed(1) limits max length of label to 7 characters
* pcc ignores object files that has incorrect extension,
so should use underlying loader directly.
* No ln(1). Instead use bind(1), but bind isn't persisted to the disk. However it isn't efficient to copy git to git subcommands such as git-add. Therefore Plan 9 needs exec-wrapper to switch behavior by executable name.
* tar(1) don't have -o option

---
 GIT-VERSION-GEN     |  2 +-
 Makefile            | 41 ++++++++++++++-----
 config.mak.uname    | 99 +++++++++++++++++++++++++++++++++++++++++++++
 exec-wrapper.c      | 16 ++++++++
 generate-cmdlist.sh | 24 ++++++++---
 t/chainlint.sed     | 66 +++++++++++++++---------------
 templates/Makefile  | 12 +++++-
 7 files changed, 208 insertions(+), 52 deletions(-)
 create mode 100644 exec-wrapper.c
GIT-VERSION-GEN +1 -1
index 98f88a28d3..ec5635b120 100755
@@ -26,7 +26,7 @@ else
 	VN="$DEF_VER"
 fi
 
-VN=$(expr "$VN" : v*'\(.*\)')
+VN=${VN#v}
 
 if test -r $GVF
 then
Makefile +31 -10

127 lines not on this page · raw message

config.mak.uname +99 -0

125 lines not on this page · raw message

exec-wrapper.c new file +16 -0
new file mode 100644
index 0000000000..b56e871d02
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+	/* we should detect git-core path */
+
+	USED(argc);
+	if (execv("/bin/git", argv) < 0) {
+		fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
+		return 1;
+	}
+	return 0; /* can't happen */
+}
generate-cmdlist.sh +18 -6
index 71158f7d8b..e4fe3ea608 100755
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+if ! echo abc | sed 's/(ab)c/\1/' >/dev/null 2>&1
+then
+	alias sed='sed -E'
+fi
+
 die () {
 	echo "$@" >&2
 	exit 1
@@ -10,7 +15,7 @@ command_list () {
 }
 
 get_categories () {
-	tr ' ' '\n'|
+	tr ' ' '\012'|
 	grep -v '^$' |
 	sort |
 	uniq
@@ -18,16 +23,16 @@ get_categories () {
 
 category_list () {
 	command_list "$1" |
-	cut -c 40- |
+	awk '{ print substr($0, 40) }' |
 	get_categories
 }
 
 get_synopsis () {
 	sed -n '
-		/^NAME/,/'"$1"'/H
+		/^NAME/,/'"$1"'/h
 		${
 			x
-			s/.*'"$1"' - \(.*\)/N_("\1")/
+			s/.*'"$1"' - (.*)/N_("\1")/
 			p
 		}' "Documentation/$1.txt"
 }
@@ -60,16 +65,23 @@ define_category_names () {
 	echo "};"
 }
 
+if test -z "$(echo -n)"
+then
+	alias print='echo -n'
+else
+	alias print='printf %s'
+fi
+
 print_command_list () {
 	echo "static struct cmdname_help command_list[] = {"
 
 	command_list "$1" |
 	while read cmd rest
 	do
-		printf "	{ \"$cmd\", $(get_synopsis $cmd), 0"
+		print "	{ \"$cmd\", $(get_synopsis $cmd), 0"
 		for cat in $(echo "$rest" | get_categories)
 		do
-			printf " | CAT_$cat"
+			print " | CAT_$cat"
 		done
 		echo " },"
 	done
t/chainlint.sed +33 -33

174 lines not on this page · raw message

templates/Makefile +10 -2
index d22a71a399..19216a924a 100644
@@ -4,8 +4,16 @@ ifndef V
 	QUIET = @
 endif
 
+uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
+
 INSTALL ?= install
 TAR ?= tar
+TAR_CF = $(TAR) cf
+TAR_XF = $(TAR) xof
+ifeq ($(uname_S),Plan9)
+	TAR_CF = $(TAR) cf
+	TAR_XF = $(TAR) xf
+endif
 RM ?= rm -f
 prefix ?= $(HOME)
 template_instdir ?= $(prefix)/share/git-core/templates
@@ -62,5 +70,5 @@ clean:
 
 install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
-	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xof -)
+	(cd blt && $(TAR_CF) - .) | \
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR_XF) -)
Signature · 1 line
gitgitgadget