From 5a5999a393d75b5e9b0e9a4fc659ddabea7c31db Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 10:47:26 -0400 Subject: [PATCH 1/6] psuh: add a built-in by popular demand Doing a codelab Signed-off-by: Daniel Ploch --- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/psuh.c | 11 +++++++++++ git.c | 1 + 5 files changed, 15 insertions(+) create mode 100644 builtin/psuh.c diff --git a/.gitignore b/.gitignore index 8caf3700c2305d..d48ef7b8b46e42 100644 --- a/.gitignore +++ b/.gitignore @@ -118,6 +118,7 @@ /git-patch-id /git-prune /git-prune-packed +/git-psuh /git-pull /git-push /git-quiltimport diff --git a/Makefile b/Makefile index 91f65d7dc57961..83f6a3dd79a392 100644 --- a/Makefile +++ b/Makefile @@ -1276,6 +1276,7 @@ BUILTIN_OBJS += builtin/pack-refs.o BUILTIN_OBJS += builtin/patch-id.o BUILTIN_OBJS += builtin/prune-packed.o BUILTIN_OBJS += builtin/prune.o +BUILTIN_OBJS += builtin/psuh.o BUILTIN_OBJS += builtin/pull.o BUILTIN_OBJS += builtin/push.o BUILTIN_OBJS += builtin/range-diff.o diff --git a/builtin.h b/builtin.h index 14fa0171607b17..a8059f6da575f3 100644 --- a/builtin.h +++ b/builtin.h @@ -207,6 +207,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix); int cmd_patch_id(int argc, const char **argv, const char *prefix); int cmd_prune(int argc, const char **argv, const char *prefix); int cmd_prune_packed(int argc, const char **argv, const char *prefix); +int cmd_psuh(int argc, const char **argv, const char *prefix); int cmd_pull(int argc, const char **argv, const char *prefix); int cmd_push(int argc, const char **argv, const char *prefix); int cmd_range_diff(int argc, const char **argv, const char *prefix); diff --git a/builtin/psuh.c b/builtin/psuh.c new file mode 100644 index 00000000000000..dfe55ab2652231 --- /dev/null +++ b/builtin/psuh.c @@ -0,0 +1,11 @@ +#include "builtin.h" +#include "gettext.h" + +int cmd_psuh(int argc, const char **argv, const char *prefix) +{ + (void)argc; + (void)argv; + (void)prefix; + printf(_("Pony saying hello goes here.\n")); + return 0; +} \ No newline at end of file diff --git a/git.c b/git.c index 9a618a2740f195..ceace549979152 100644 --- a/git.c +++ b/git.c @@ -596,6 +596,7 @@ static struct cmd_struct commands[] = { { "pickaxe", cmd_blame, RUN_SETUP }, { "prune", cmd_prune, RUN_SETUP }, { "prune-packed", cmd_prune_packed, RUN_SETUP }, + { "psuh", cmd_psuh, RUN_SETUP }, { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE }, { "push", cmd_push, RUN_SETUP }, { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER }, From 84362406b79febb97eed7038d280ec67c43bd354 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 10:59:10 -0400 Subject: [PATCH 2/6] psuh: show parameters & config opts Signed-off-by: Daniel Ploch --- builtin/psuh.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index dfe55ab2652231..a66a893d0af4be 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,11 +1,26 @@ #include "builtin.h" +#include "config.h" #include "gettext.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { - (void)argc; - (void)argv; - (void)prefix; + printf(Q_("Your args (there is %d):\n", + "Your args (there are %d):\n", + argc), + argc); + for (int i = 0; i < argc; i++) + printf("%d: %s\n", i, argv[i]); + + printf(_("Your current working directory:\n%s%s\n"), + prefix ? "/" : "", prefix ? prefix : ""); + + const char *cfg_name; + git_config(git_default_config, NULL); + if (git_config_get_string_tmp("user.name", &cfg_name) > 0) + printf(_("No name found in config\n")); + else + printf(_("Your name: %s\n"), cfg_name); + printf(_("Pony saying hello goes here.\n")); return 0; } \ No newline at end of file From eb0d336ce59858cac8a07ac67bded51e7ac1daaa Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 11:00:21 -0400 Subject: [PATCH 3/6] psuh: fix declaration Signed-off-by: Daniel Ploch --- builtin/psuh.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index a66a893d0af4be..59a772ca85c5f0 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -2,6 +2,8 @@ #include "config.h" #include "gettext.h" +const char *cfg_name; + int cmd_psuh(int argc, const char **argv, const char *prefix) { printf(Q_("Your args (there is %d):\n", @@ -14,7 +16,6 @@ int cmd_psuh(int argc, const char **argv, const char *prefix) printf(_("Your current working directory:\n%s%s\n"), prefix ? "/" : "", prefix ? prefix : ""); - const char *cfg_name; git_config(git_default_config, NULL); if (git_config_get_string_tmp("user.name", &cfg_name) > 0) printf(_("No name found in config\n")); From b355673c6e0af02254b59ec917235a0f9b1e29a3 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 11:14:43 -0400 Subject: [PATCH 4/6] psuh: print the current branch Signed-off-by: Daniel Ploch --- builtin/psuh.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index 59a772ca85c5f0..6c985a6d1ee5fc 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,11 +1,13 @@ #include "builtin.h" #include "config.h" #include "gettext.h" - -const char *cfg_name; +#include "wt-status.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { + const char *cfg_name; + struct wt_status status; + printf(Q_("Your args (there is %d):\n", "Your args (there are %d):\n", argc), @@ -16,12 +18,15 @@ int cmd_psuh(int argc, const char **argv, const char *prefix) printf(_("Your current working directory:\n%s%s\n"), prefix ? "/" : "", prefix ? prefix : ""); - git_config(git_default_config, NULL); + wt_status_prepare(the_repository, &status); + git_config(git_default_config, &status); if (git_config_get_string_tmp("user.name", &cfg_name) > 0) printf(_("No name found in config\n")); else printf(_("Your name: %s\n"), cfg_name); + printf(_("Your current branch: %s\n"), status.branch); + printf(_("Pony saying hello goes here.\n")); return 0; } \ No newline at end of file From 6d4be35e9deb63d397a5e12c74c9cb7b48be5419 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 11:25:32 -0400 Subject: [PATCH 5/6] psuh: add help Signed-off-by: Daniel Ploch --- builtin/psuh.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/psuh.c b/builtin/psuh.c index 6c985a6d1ee5fc..1ea713835eae00 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,12 +1,17 @@ #include "builtin.h" +#include "commit.h" #include "config.h" #include "gettext.h" +#include "pretty.h" +#include "strbuf.h" #include "wt-status.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { const char *cfg_name; struct wt_status status; + struct commit *c = NULL; + struct strbuf commitline = STRBUF_INIT; printf(Q_("Your args (there is %d):\n", "Your args (there are %d):\n", @@ -27,6 +32,12 @@ int cmd_psuh(int argc, const char **argv, const char *prefix) printf(_("Your current branch: %s\n"), status.branch); + c = lookup_commit_reference_by_name("origin/master"); + if (c != NULL) { + pp_commit_easy(CMIT_FMT_ONELINE, c, &commitline); + printf(_("Current commit: %s\n"), commitline.buf); + } + printf(_("Pony saying hello goes here.\n")); return 0; } \ No newline at end of file From 0fc2aef550ea5ef421cac13bb5fccf779b95efa0 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Tue, 10 Sep 2024 11:30:02 -0400 Subject: [PATCH 6/6] psuh: add usage string Signed-off-by: Daniel Ploch --- builtin/psuh.c | 9 +++++++++ command-list.txt | 1 + 2 files changed, 10 insertions(+) diff --git a/builtin/psuh.c b/builtin/psuh.c index 1ea713835eae00..f1c6f03b04ba29 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -2,16 +2,25 @@ #include "commit.h" #include "config.h" #include "gettext.h" +#include "parse-options.h" #include "pretty.h" #include "strbuf.h" #include "wt-status.h" +static const char * const psuh_usage[] = { + N_("git psuh [...]"), + NULL, +}; + int cmd_psuh(int argc, const char **argv, const char *prefix) { const char *cfg_name; struct wt_status status; struct commit *c = NULL; struct strbuf commitline = STRBUF_INIT; + struct option options[] = { OPT_END() }; + + argc = parse_options(argc, argv, prefix, options, psuh_usage, 0); printf(Q_("Your args (there is %d):\n", "Your args (there are %d):\n", diff --git a/command-list.txt b/command-list.txt index e0bb87b3b5c278..16ca2f4ef25045 100644 --- a/command-list.txt +++ b/command-list.txt @@ -149,6 +149,7 @@ git-pack-refs ancillarymanipulators git-patch-id purehelpers git-prune ancillarymanipulators complete git-prune-packed plumbingmanipulators +git-psuh mainporcelain info git-pull mainporcelain remote git-push mainporcelain remote git-quiltimport foreignscminterface