git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] show-branch: fix segfault when showbranch.default exists
@ 2009-06-09  6:26 Junio C Hamano
  2009-06-09  7:17 ` Stephen Boyd
  0 siblings, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2009-06-09  6:26 UTC (permalink / raw)
  To: git; +Cc: Stephen Boyd, Pierre Habouzit

When running "git show-branch" without any parameter in a repository that
has showbranch.default defined, we used to rely on the fact that our
handcrafted option parsing loop never looked at av[0].

The array of default strings had the first real command line argument in
default_arg[0], but the option parser wanted to look at the array starting
at av[1], so we assigned the address of -1th element to av to force the
loop start working from default_arg[0].

This no longer worked since 5734365 (show-branch: migrate to parse-options
API, 2009-05-21), as parse_options_start() saved the incoming &av[0] in
its ctx->out and later in parse_options_end() it did memmove to ctx->out
(with ctx->cpidx == 0), overwriting the memory before default_arg[] array.

I am not sure if this is a bug in parse_options(), or a bug in the caller,
and tonight I do not have enough concentration to figure out which.  In
any case, this patch works the issue around.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-show-branch.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 01bea3b..baec9ed 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -565,7 +565,15 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "showbranch.default")) {
 		if (!value)
 			return config_error_nonbool(var);
-		if (default_alloc <= default_num + 1) {
+		/*
+		 * default_arg is now passed to parse_options(), so we need to
+		 * mimick the real argv a bit better.
+		 */
+		if (!default_num) {
+			default_alloc = 20;
+			default_arg = xcalloc(default_alloc, sizeof(*default_arg));
+			default_arg[default_num++] = "show-branch";
+		} else if (default_alloc <= default_num + 1) {
 			default_alloc = default_alloc * 3 / 2 + 20;
 			default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
 		}
@@ -692,8 +700,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 
 	/* If nothing is specified, try the default first */
 	if (ac == 1 && default_num) {
-		ac = default_num + 1;
-		av = default_arg - 1; /* ick; we would not address av[0] */
+		ac = default_num;
+		av = default_arg;
 	}
 
 	ac = parse_options(ac, av, prefix, builtin_show_branch_options,

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* Branch Management
@ 2021-08-10 22:24 mail.chris.az
  2021-08-11  6:31 ` Bagas Sanjaya
  0 siblings, 1 reply; 14+ messages in thread
From: mail.chris.az @ 2021-08-10 22:24 UTC (permalink / raw)
  To: git

I have a private git repository (private.git) on a private server
(PRIVATEREPO.COM).  That repo is updated via development on my local system.
All works great in that area.  I have 2 branches, "master" and "version".

I want to update my production system via git from the private git
repository via command line.  The production system not only contains the
files from the repo, but also additional files and directories.  I need
those files to be left alone.

I was able to successful clone just the "master" branch using:

# git clone -b master git_user@PRIVATEREPO.COM:private.git production.git

I am now ready to move the new "version" branch.  
1.  How can I do that?

The "version" branch contains some new files that are not in the "master"
branch.

Now suppose that I move to the "version" branch, but determine that I need
to go back to the "master" branch.

2.  How do I go back to the "master" branch and remove any of the new files
that were uploaded from the "version" branch?  I don't want any remnants
that the "version" branch was even there.

Hopefully someone can head me in the right direction.

Thanks!


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

end of thread, other threads:[~2021-08-11  6:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-09  6:26 [PATCH] show-branch: fix segfault when showbranch.default exists Junio C Hamano
2009-06-09  7:17 ` Stephen Boyd
2009-06-09  8:06   ` Pierre Habouzit
2009-06-09 16:28     ` Junio C Hamano
2009-06-09 17:23       ` Pierre Habouzit
2009-06-09 17:35         ` branch management Harry Duin
2009-06-09 19:50           ` Alex Riesen
2009-06-10 14:02             ` Harry Duin
2009-06-10 14:43               ` Jakub Narebski
2009-06-10 15:28                 ` Nicolas Pitre
2009-06-10 17:37                   ` Linus Torvalds
2009-06-10 19:14               ` Daniel Barkalow
  -- strict thread matches above, loose matches on Subject: below --
2021-08-10 22:24 Branch Management mail.chris.az
2021-08-11  6:31 ` Bagas Sanjaya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).