git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/6] Port git to Plan 9
@ 2019-08-03 23:52 KADOTA, Kyohei via GitGitGadget
  2019-08-03 23:52 ` [PATCH 1/6] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: KADOTA, Kyohei via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/6] Change HOME, PATH, and .gitconfig paths to be customizable
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-03 23:52 ` [PATCH 2/6] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

In Plan 9, almost environment variables are not capitalized.

Signed-off-by: lufia <lufia@lufia.org>
---
 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(-)

diff --git a/Makefile b/Makefile
index bd246f2989..721364efba 100644
--- a/Makefile
+++ b/Makefile
@@ -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)"'
diff --git a/builtin/config.c b/builtin/config.c
index 98d65bc0ad..22c4f0ab71 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -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)
diff --git a/config.c b/config.c
index ed7f58e0fc..f67cef5cf8 100644
--- a/config.c
+++ b/config.c
@@ -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)
diff --git a/credential-cache.c b/credential-cache.c
index 1cccc3a0b9..3e2ed6c0be 100644
--- a/credential-cache.c
+++ b/credential-cache.c
@@ -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
diff --git a/credential-store.c b/credential-store.c
index ac295420dd..37256ee942 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -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)
diff --git a/exec-cmd.c b/exec-cmd.c
index 7deeab3039..c95fc8dbdd 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -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);
 }
diff --git a/git-compat-util.h b/git-compat-util.h
index 83be89de0a..f8fdd79591 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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)
diff --git a/help.c b/help.c
index 5261d83ecf..6094bfae7d 100644
--- a/help.c
+++ b/help.c
@@ -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) {
diff --git a/path.c b/path.c
index 25e97b8c3f..45bde04d37 100644
--- a/path.c
+++ b/path.c
@@ -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;
diff --git a/run-command.c b/run-command.c
index 3449db319b..85d7a8c342 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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);
 
diff --git a/sequencer.c b/sequencer.c
index 34ebf8ed94..044b0fabea 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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);
 
diff --git a/shell.c b/shell.c
index 40084a3013..fa844425b9 100644
--- a/shell.c
+++ b/shell.c
@@ -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)
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/6] Fix C syntactic errors for the Plan 9 C compiler
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
  2019-08-03 23:52 ` [PATCH 1/6] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-03 23:52 ` [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr lufia via GitGitGadget
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

Signed-off-by: lufia <lufia@lufia.org>
---
 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

diff --git a/compat/plan9/openssl/crypto.h b/compat/plan9/openssl/crypto.h
new file mode 100644
index 0000000000..9d1ef43422
--- /dev/null
+++ b/compat/plan9/openssl/crypto.h
@@ -0,0 +1,5 @@
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+
+#include_next <openssl/crypto.h>
diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
index 3ee8aae59d..7313c747a6 100644
--- a/compat/regex/regex_internal.h
+++ b/compat/regex/regex_internal.h
@@ -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
diff --git a/config.c b/config.c
index f67cef5cf8..993f9f57be 100644
--- a/config.c
+++ b/config.c
@@ -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;
 
diff --git a/git-compat-util.h b/git-compat-util.h
index f8fdd79591..1aa7877af4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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
diff --git a/parse-options.h b/parse-options.h
index a4bd40bb6a..38a33a087e 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -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
diff --git a/remove-bitfields.rc b/remove-bitfields.rc
new file mode 100644
index 0000000000..897f98da10
--- /dev/null
+++ b/remove-bitfields.rc
@@ -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
+}
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
  2019-08-03 23:52 ` [PATCH 1/6] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
  2019-08-03 23:52 ` [PATCH 2/6] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-05 22:37   ` Junio C Hamano
  2019-08-03 23:52 ` [PATCH 5/6] Add plan9/wrap.c lufia via GitGitGadget
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

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*//')
 
 if test -r $GVF
 then
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/6] Port generate-cmdline.sh to rc
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
                   ` (3 preceding siblings ...)
  2019-08-03 23:52 ` [PATCH 5/6] Add plan9/wrap.c lufia via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-03 23:52 ` [PATCH 6/6] Add mkfile to build git and subcommands for Plan 9 lufia via GitGitGadget
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

Signed-off-by: lufia <lufia@lufia.org>
---
 generate-cmdlist.rc | 102 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100755 generate-cmdlist.rc

diff --git a/generate-cmdlist.rc b/generate-cmdlist.rc
new file mode 100755
index 0000000000..18699ea9c4
--- /dev/null
+++ b/generate-cmdlist.rc
@@ -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
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 5/6] Add plan9/wrap.c
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
                   ` (2 preceding siblings ...)
  2019-08-03 23:52 ` [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr lufia via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-04  0:03   ` brian m. carlson
  2019-08-03 23:52 ` [PATCH 4/6] Port generate-cmdline.sh to rc lufia via GitGitGadget
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

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.

Signed-off-by: lufia <lufia@lufia.org>
---
 plan9/wrap.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 plan9/wrap.c

diff --git a/plan9/wrap.c b/plan9/wrap.c
new file mode 100644
index 0000000000..589d13bf5d
--- /dev/null
+++ b/plan9/wrap.c
@@ -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 */
+}
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 6/6] Add mkfile to build git and subcommands for Plan 9
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
                   ` (4 preceding siblings ...)
  2019-08-03 23:52 ` [PATCH 4/6] Port generate-cmdline.sh to rc lufia via GitGitGadget
@ 2019-08-03 23:52 ` lufia via GitGitGadget
  2019-08-04  0:38 ` [PATCH 0/6] Port git to " brian m. carlson
  2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
  7 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-03 23:52 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

Signed-off-by: lufia <lufia@lufia.org>
---
 mkfile | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 195 insertions(+)
 create mode 100644 mkfile

diff --git a/mkfile b/mkfile
new file mode 100644
index 0000000000..f0b06437ed
--- /dev/null
+++ b/mkfile
@@ -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]
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/6] Add plan9/wrap.c
  2019-08-03 23:52 ` [PATCH 5/6] Add plan9/wrap.c lufia via GitGitGadget
@ 2019-08-04  0:03   ` brian m. carlson
  2019-08-04  1:26     ` Kyohei Kadota
  0 siblings, 1 reply; 17+ messages in thread
From: brian m. carlson @ 2019-08-04  0:03 UTC (permalink / raw)
  To: lufia via GitGitGadget; +Cc: git, Junio C Hamano, lufia

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

On 2019-08-03 at 23:52:12, lufia via GitGitGadget wrote:
> From: lufia <lufia@lufia.org>
> 
> 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.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/6] Port git to Plan 9
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
                   ` (5 preceding siblings ...)
  2019-08-03 23:52 ` [PATCH 6/6] Add mkfile to build git and subcommands for Plan 9 lufia via GitGitGadget
@ 2019-08-04  0:38 ` brian m. carlson
  2019-08-04  2:22   ` Kyohei Kadota
  2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
  7 siblings, 1 reply; 17+ messages in thread
From: brian m. carlson @ 2019-08-04  0:38 UTC (permalink / raw)
  To: KADOTA, Kyohei via GitGitGadget; +Cc: git, Junio C Hamano

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

On 2019-08-03 at 23:52:08, KADOTA, Kyohei via GitGitGadget wrote:
> 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.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/6] Add plan9/wrap.c
  2019-08-04  0:03   ` brian m. carlson
@ 2019-08-04  1:26     ` Kyohei Kadota
  0 siblings, 0 replies; 17+ messages in thread
From: Kyohei Kadota @ 2019-08-04  1:26 UTC (permalink / raw)
  To: brian m. carlson, lufia via GitGitGadget, git, Junio C Hamano, lufia

2019-08-04(Sun) 9:03 brian m. carlson <sandals@crustytoothpaste.net>:
>
> On 2019-08-03 at 23:52:12, lufia via GitGitGadget wrote:
> > From: lufia <lufia@lufia.org>
> >
> > 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.
> --
> 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/6] Port git to Plan 9
  2019-08-04  0:38 ` [PATCH 0/6] Port git to " brian m. carlson
@ 2019-08-04  2:22   ` Kyohei Kadota
  2019-08-04 20:22     ` Jonathan Nieder
  0 siblings, 1 reply; 17+ messages in thread
From: Kyohei Kadota @ 2019-08-04  2:22 UTC (permalink / raw)
  To: brian m. carlson, KADOTA, Kyohei via GitGitGadget, git, Junio C Hamano

2019-08-04(Sun) 9:38 brian m. carlson <sandals@crustytoothpaste.net>:
>
> On 2019-08-03 at 23:52:08, KADOTA, Kyohei via GitGitGadget wrote:
> > 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.
> --
> 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.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/6] Port git to Plan 9
  2019-08-04  2:22   ` Kyohei Kadota
@ 2019-08-04 20:22     ` Jonathan Nieder
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Nieder @ 2019-08-04 20:22 UTC (permalink / raw)
  To: Kyohei Kadota
  Cc: brian m. carlson, KADOTA, Kyohei via GitGitGadget, git, Junio C Hamano

Hi,

Kyohei Kadota wrote:

> 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr
  2019-08-03 23:52 ` [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr lufia via GitGitGadget
@ 2019-08-05 22:37   ` Junio C Hamano
  0 siblings, 0 replies; 17+ messages in thread
From: Junio C Hamano @ 2019-08-05 22:37 UTC (permalink / raw)
  To: lufia via GitGitGadget; +Cc: git, lufia

"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.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 0/3] Port git to Plan 9
  2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
                   ` (6 preceding siblings ...)
  2019-08-04  0:38 ` [PATCH 0/6] Port git to " brian m. carlson
@ 2019-08-27 13:46 ` KADOTA, Kyohei via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 1/3] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
                     ` (2 more replies)
  7 siblings, 3 replies; 17+ messages in thread
From: KADOTA, Kyohei via GitGitGadget @ 2019-08-27 13:46 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 1/3] Change HOME, PATH, and .gitconfig paths to be customizable
  2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
@ 2019-08-27 13:46   ` lufia via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 2/3] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 3/3] Support Plan 9 dialect lufia via GitGitGadget
  2 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-27 13:46 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

In Plan 9, almost environment variables are not capitalized.

Signed-off-by: lufia <lufia@lufia.org>
---
 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(-)

diff --git a/Makefile b/Makefile
index f9255344ae..04ff7df64a 100644
--- a/Makefile
+++ b/Makefile
@@ -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)"'
diff --git a/builtin/config.c b/builtin/config.c
index 98d65bc0ad..22c4f0ab71 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -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)
diff --git a/config.c b/config.c
index 3900e4947b..14de96ee6d 100644
--- a/config.c
+++ b/config.c
@@ -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)
diff --git a/credential-cache.c b/credential-cache.c
index 1cccc3a0b9..3e2ed6c0be 100644
--- a/credential-cache.c
+++ b/credential-cache.c
@@ -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
diff --git a/credential-store.c b/credential-store.c
index ac295420dd..37256ee942 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -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)
diff --git a/exec-cmd.c b/exec-cmd.c
index 7deeab3039..c95fc8dbdd 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -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);
 }
diff --git a/git-compat-util.h b/git-compat-util.h
index 83be89de0a..f8fdd79591 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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)
diff --git a/help.c b/help.c
index 5261d83ecf..6094bfae7d 100644
--- a/help.c
+++ b/help.c
@@ -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) {
diff --git a/path.c b/path.c
index 25e97b8c3f..45bde04d37 100644
--- a/path.c
+++ b/path.c
@@ -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;
diff --git a/run-command.c b/run-command.c
index 3449db319b..85d7a8c342 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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);
 
diff --git a/sequencer.c b/sequencer.c
index 34ebf8ed94..044b0fabea 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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);
 
diff --git a/shell.c b/shell.c
index 40084a3013..fa844425b9 100644
--- a/shell.c
+++ b/shell.c
@@ -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)
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 2/3] Fix C syntactic errors for the Plan 9 C compiler
  2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 1/3] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
@ 2019-08-27 13:46   ` lufia via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 3/3] Support Plan 9 dialect lufia via GitGitGadget
  2 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-27 13:46 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

Signed-off-by: lufia <lufia@lufia.org>
---
 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

diff --git a/compat/plan9/openssl/crypto.h b/compat/plan9/openssl/crypto.h
new file mode 100644
index 0000000000..9d1ef43422
--- /dev/null
+++ b/compat/plan9/openssl/crypto.h
@@ -0,0 +1,5 @@
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+
+#include_next <openssl/crypto.h>
diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
index 3ee8aae59d..7313c747a6 100644
--- a/compat/regex/regex_internal.h
+++ b/compat/regex/regex_internal.h
@@ -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
diff --git a/config.c b/config.c
index 14de96ee6d..0024b767e5 100644
--- a/config.c
+++ b/config.c
@@ -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;
 
diff --git a/git-compat-util.h b/git-compat-util.h
index f8fdd79591..1aa7877af4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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
diff --git a/parse-options.h b/parse-options.h
index a4bd40bb6a..38a33a087e 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -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
diff --git a/remove-bitfields.sh b/remove-bitfields.sh
new file mode 100755
index 0000000000..952bd34f12
--- /dev/null
+++ b/remove-bitfields.sh
@@ -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
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 3/3] Support Plan 9 dialect
  2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 1/3] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
  2019-08-27 13:46   ` [PATCH v2 2/3] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
@ 2019-08-27 13:46   ` lufia via GitGitGadget
  2 siblings, 0 replies; 17+ messages in thread
From: lufia via GitGitGadget @ 2019-08-27 13:46 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, lufia

From: lufia <lufia@lufia.org>

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

Signed-off-by: lufia <lufia@lufia.org>
---
 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

diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 98f88a28d3..ec5635b120 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -26,7 +26,7 @@ else
 	VN="$DEF_VER"
 fi
 
-VN=$(expr "$VN" : v*'\(.*\)')
+VN=${VN#v}
 
 if test -r $GVF
 then
diff --git a/Makefile b/Makefile
index 04ff7df64a..a2729ba6d3 100644
--- a/Makefile
+++ b/Makefile
@@ -570,6 +570,7 @@ export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
 
 # Set our default programs
 CC = cc
+LD = cc
 AR = ar
 RM = rm -f
 DIFF = diff
@@ -800,6 +801,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-upload-pack
@@ -1863,6 +1868,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  =
 
@@ -2062,7 +2072,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
@@ -2122,7 +2132,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
@@ -2141,10 +2151,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 $< $@
 
 command-list.h: generate-cmdlist.sh command-list.txt
@@ -2344,6 +2355,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) \
@@ -2464,22 +2476,29 @@ 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-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)
@@ -2489,7 +2508,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)
@@ -2783,7 +2802,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
@@ -2966,6 +2985,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 \
@@ -2975,6 +2995,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)" && \
diff --git a/config.mak.uname b/config.mak.uname
index db7f06b95f..77dc661107 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -427,6 +427,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 \
@@ -510,6 +511,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
@@ -657,8 +659,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
@@ -691,6 +695,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
diff --git a/exec-wrapper.c b/exec-wrapper.c
new file mode 100644
index 0000000000..b56e871d02
--- /dev/null
+++ b/exec-wrapper.c
@@ -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 */
+}
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 71158f7d8b..e4fe3ea608 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -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
diff --git a/t/chainlint.sed b/t/chainlint.sed
index 70df40e34b..7282e7b426 100644
--- a/t/chainlint.sed
+++ b/t/chainlint.sed
@@ -117,7 +117,7 @@
 /^[ 	]*!*[ 	]*(..*)[ 	]*[0-9]*[<>|&]/boneline
 
 # multi-line "(...\n...)"
-/^[ 	]*(/bsubshell
+/^[ 	]*(/bsubsh
 
 # innocuous line -- print it and advance to next line
 b
@@ -130,11 +130,11 @@ b
 }
 b
 
-:subshell
+:subsh
 # bare "(" line? -- stash for later printing
 /^[ 	]*([	]*$/ {
 	h
-	bnextline
+	bnextln
 }
 # "(..." line -- split off and stash "(", then process "..." as its own line
 x
@@ -143,7 +143,7 @@ x
 s/(//
 bslurp
 
-:nextline
+:nextln
 N
 s/.*\n//
 
@@ -151,10 +151,10 @@ s/.*\n//
 # incomplete line "...\"
 /\\$/bicmplte
 # multi-line quoted string "...\n..."?
-/"/bdqstring
+/"/bdqstr
 # multi-line quoted string '...\n...'? (but not contraction in string "it's")
 /'/{
-	/"[^'"]*'[^'"]*"/!bsqstring
+	/"[^'"]*'[^'"]*"/!bsqstr
 }
 :folded
 # here-doc -- swallow it
@@ -163,8 +163,8 @@ s/.*\n//
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
 # legitimately lacks "&&", so "suspect" mark must be removed
-/^[ 	]*#/bnextline
-/^[ 	]*$/bnextline
+/^[ 	]*#/bnextln
+/^[ 	]*$/bnextln
 # in-line comment -- strip it (but not "#" in a string, Bash ${#...} array
 # length, or Perforce "//depot/path#42" revision in filespec)
 /[ 	]#/{
@@ -175,22 +175,22 @@ s/.*\n//
 # multi-line "case ... esac"
 /^[ 	]*case[ 	]..*[ 	]in/bcase
 # multi-line "for ... done" or "while ... done"
-/^[ 	]*for[ 	]..*[ 	]in/bcontinue
-/^[ 	]*while[ 	]/bcontinue
-/^[ 	]*do[ 	]/bcontinue
-/^[ 	]*do[ 	]*$/bcontinue
-/;[ 	]*do/bcontinue
+/^[ 	]*for[ 	]..*[ 	]in/bcnt
+/^[ 	]*while[ 	]/bcnt
+/^[ 	]*do[ 	]/bcnt
+/^[ 	]*do[ 	]*$/bcnt
+/;[ 	]*do/bcnt
 /^[ 	]*done[ 	]*&&[ 	]*$/bdone
 /^[ 	]*done[ 	]*$/bdone
 /^[ 	]*done[ 	]*[<>|]/bdone
 /^[ 	]*done[ 	]*)/bdone
-/||[ 	]*exit[ 	]/bcontinue
-/||[ 	]*exit[ 	]*$/bcontinue
+/||[ 	]*exit[ 	]/bcnt
+/||[ 	]*exit[ 	]*$/bcnt
 # multi-line "if...elsif...else...fi"
-/^[ 	]*if[ 	]/bcontinue
-/^[ 	]*then[ 	]/bcontinue
-/^[ 	]*then[ 	]*$/bcontinue
-/;[ 	]*then/bcontinue
+/^[ 	]*if[ 	]/bcnt
+/^[ 	]*then[ 	]/bcnt
+/^[ 	]*then[ 	]*$/bcnt
+/;[ 	]*then/bcnt
 /^[ 	]*elif[ 	]/belse
 /^[ 	]*elif[ 	]*$/belse
 /^[ 	]*else[ 	]/belse
@@ -234,10 +234,10 @@ s/.*\n//
 	}
 }
 # line ends with pipe "...|" -- valid; not missing "&&"
-/|[ 	]*$/bcontinue
+/|[ 	]*$/bcnt
 # missing end-of-line "&&" -- mark suspect
 /&&[ 	]*$/!s/^/?!AMP?!/
-:continue
+:cnt
 # retrieve and print previous line
 x
 n
@@ -250,7 +250,7 @@ s/\\\n//
 bslurp
 
 # check for multi-line double-quoted string "...\n..." -- fold to one line
-:dqstring
+:dqstr
 # remove all quote pairs
 s/"\([^"]*\)"/@!\1@!/g
 # done if no dangling quote
@@ -258,13 +258,13 @@ s/"\([^"]*\)"/@!\1@!/g
 # otherwise, slurp next line and try again
 N
 s/\n//
-bdqstring
+bdqstr
 :dqdone
 s/@!/"/g
 bfolded
 
 # check for multi-line single-quoted string '...\n...' -- fold to one line
-:sqstring
+:sqstr
 # remove all quote pairs
 s/'\([^']*\)'/@!\1@!/g
 # done if no dangling quote
@@ -272,7 +272,7 @@ s/'\([^']*\)'/@!\1@!/g
 # otherwise, slurp next line and try again
 N
 s/\n//
-bsqstring
+bsqstr
 :sqdone
 s/@!/'/g
 bfolded
@@ -282,11 +282,11 @@ bfolded
 :heredoc
 s/^\(.*\)<<[ 	]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
 s/[ 	]*<<//
-:heredsub
+:heresub
 N
 /^<\([^>]*\)>.*\n[ 	]*\1[ 	]*$/!{
 	s/\n.*$//
-	bheredsub
+	bheresub
 }
 s/^<[^>]*>//
 s/\n.*$//
@@ -305,7 +305,7 @@ bcase
 x
 s/?!AMP?!//
 x
-bcontinue
+bcnt
 
 # found "done" closing for-loop or while-loop, or "fi" closing if-then -- drop
 # "suspect" from final contained line since that line legitimately lacks "&&"
@@ -321,10 +321,10 @@ bchkchn
 # found nested multi-line "(...\n...)" -- pass through untouched
 :nest
 x
-:nstslurp
+:nstslrp
 n
 # closing ")" on own line -- stop nested slurp
-/^[ 	]*)/bnstclose
+/^[ 	]*)/bnstclos
 # comment -- not closing ")" if in comment
 /^[ 	]*#/bnstcnt
 # "$((...))" -- arithmetic expansion; not closing ")"
@@ -332,11 +332,11 @@ n
 # "$(...)" -- command substitution; not closing ")"
 /\$([^)][^)]*)[^)]*$/bnstcnt
 # closing "...)" -- stop nested slurp
-/)/bnstclose
+/)/bnstclos
 :nstcnt
 x
-bnstslurp
-:nstclose
+bnstslrp
+:nstclos
 s/^/>>/
 # is it "))" which closes nested and parent subshells?
 /)[ 	]*)/bslurp
diff --git a/templates/Makefile b/templates/Makefile
index d22a71a399..19216a924a 100644
--- a/templates/Makefile
+++ b/templates/Makefile
@@ -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) -)
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-08-27 13:46 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-03 23:52 [PATCH 0/6] Port git to Plan 9 KADOTA, Kyohei via GitGitGadget
2019-08-03 23:52 ` [PATCH 1/6] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
2019-08-03 23:52 ` [PATCH 2/6] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
2019-08-03 23:52 ` [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr lufia via GitGitGadget
2019-08-05 22:37   ` Junio C Hamano
2019-08-03 23:52 ` [PATCH 5/6] Add plan9/wrap.c lufia via GitGitGadget
2019-08-04  0:03   ` brian m. carlson
2019-08-04  1:26     ` Kyohei Kadota
2019-08-03 23:52 ` [PATCH 4/6] Port generate-cmdline.sh to rc lufia via GitGitGadget
2019-08-03 23:52 ` [PATCH 6/6] Add mkfile to build git and subcommands for Plan 9 lufia via GitGitGadget
2019-08-04  0:38 ` [PATCH 0/6] Port git to " brian m. carlson
2019-08-04  2:22   ` Kyohei Kadota
2019-08-04 20:22     ` Jonathan Nieder
2019-08-27 13:46 ` [PATCH v2 0/3] " KADOTA, Kyohei via GitGitGadget
2019-08-27 13:46   ` [PATCH v2 1/3] Change HOME, PATH, and .gitconfig paths to be customizable lufia via GitGitGadget
2019-08-27 13:46   ` [PATCH v2 2/3] Fix C syntactic errors for the Plan 9 C compiler lufia via GitGitGadget
2019-08-27 13:46   ` [PATCH v2 3/3] Support Plan 9 dialect lufia via GitGitGadget

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git