All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Ramkumar Ramachandra <artagnon@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH 0/3] avoiding unintended consequences of git_path() usage
Date: Fri, 18 Nov 2011 10:33:49 +0700	[thread overview]
Message-ID: <20111118033349.GA20827@tre> (raw)
In-Reply-To: <20111116075955.GB13706@elie.hsd1.il.comcast.net>

On Wed, Nov 16, 2011 at 01:59:55AM -0600, Jonathan Nieder wrote:
> Ramkumar Ramachandra wrote:
> > Junio C Hamano wrote:
> 
> >> Or perhaps http://thread.gmane.org/gmane.comp.version-control.git/184963/focus=185436
> >
> > I noticed that sha1_to_hex() also operates like this.  The
> > resolve_ref() function is really important, but using the same
> > technique for these tiny functions is probably an overkill
> 
> I don't follow.  Do you mean that not being confusing is overkill,
> because the function is small that no one will bother to look up the
> right semantics?  Wait, that sentence didn't come out the way I
> wanted. ;-)
> 
> Jokes aside, here's a rough series to do the git_path ->
> git_path_unsafe renaming.  While writing it, I noticed a couple of
> bugs, hence the two patches before the last one.  Patch 2 is the more
> interesting one.

Or perhaps we can use per-file buffer rings instead of a global one.
This means git_path() can only interfere another one in the same file,
making the interaction simpler and hopefully simple enough for reviewers
to catch 90% bugs, therefore safe enough to avoid the _unsafe suffix.

Adding static variable declaration in cache.h is ugly, but that could be
moved to a separate header file.

diff --git a/cache.h b/cache.h
index 2e6ad36..437bc3a 100644
--- a/cache.h
+++ b/cache.h
@@ -660,9 +660,13 @@ extern char *git_snpath(char *buf, size_t n, const char *fmt, ...)
 extern char *git_pathdup(const char *fmt, ...)
 	__attribute__((format (printf, 1, 2)));
 
+#define git_path(...) git_path_1(pathname_array[3 & ++pathname_index], __VA_ARGS__)
+static char pathname_array[4][PATH_MAX];
+static int pathname_index;
+
 /* Return a statically allocated filename matching the sha1 signature */
 extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+extern char *git_path_1(char *pathname, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 extern char *git_path_submodule(const char *path, const char *fmt, ...)
 	__attribute__((format (printf, 2, 3)));
 
diff --git a/path.c b/path.c
index b6f71d1..3c95db1 100644
--- a/path.c
+++ b/path.c
@@ -101,10 +101,9 @@ char *mkpath(const char *fmt, ...)
 	return cleanup_path(pathname);
 }
 
-char *git_path(const char *fmt, ...)
+char *git_path_1(char *pathname, const char *fmt, ...)
 {
 	const char *git_dir = get_git_dir();
-	char *pathname = get_pathname();
 	va_list args;
 	unsigned len;
 

  parent reply	other threads:[~2011-11-18  3:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-05 16:29 [PATCH 0/5] Sequencer: working around historical mistakes Ramkumar Ramachandra
2011-11-05 16:29 ` [PATCH 1/5] sequencer: factor code out of revert builtin Ramkumar Ramachandra
2011-11-06  0:12   ` Jonathan Nieder
2011-11-13 10:40     ` Ramkumar Ramachandra
2011-11-13 23:10       ` Junio C Hamano
2011-11-15  9:00         ` Ramkumar Ramachandra
2011-11-15  9:18           ` Miles Bader
2011-11-15  9:47             ` Jonathan Nieder
2011-11-05 16:29 ` [PATCH 2/5] sequencer: remove CHERRY_PICK_HEAD with sequencer state Ramkumar Ramachandra
2011-11-06  0:15   ` Jonathan Nieder
2011-11-05 16:29 ` [PATCH 3/5] sequencer: sequencer state is useless without todo Ramkumar Ramachandra
2011-11-06  0:26   ` Jonathan Nieder
2011-11-13 10:44     ` Ramkumar Ramachandra
2011-11-13 20:50       ` Junio C Hamano
2011-11-15  9:13         ` Ramkumar Ramachandra
2011-11-15  9:52           ` Jonathan Nieder
2011-11-15 16:27             ` Junio C Hamano
2011-11-16  6:17               ` Ramkumar Ramachandra
2011-11-16  7:38                 ` Junio C Hamano
2011-11-16  7:59                 ` [PATCH 0/3] avoiding unintended consequences of git_path() usage Jonathan Nieder
2011-11-16  8:03                   ` [PATCH 1/3] do not let git_path clobber errno when reporting errors Jonathan Nieder
2011-11-16  8:04                   ` [PATCH 2/3] Bigfile: dynamically allocate buffer for marks file name Jonathan Nieder
2011-11-16  8:07                   ` [PATCH 3/3] rename git_path() to git_path_unsafe() Jonathan Nieder
2011-11-17  1:20                     ` Junio C Hamano
2011-11-17  7:03                       ` Jonathan Nieder
2011-11-16  8:37                   ` [PATCH 0/3] avoiding unintended consequences of git_path() usage Nguyen Thai Ngoc Duy
2011-11-16  8:42                     ` Nguyen Thai Ngoc Duy
2011-11-16  8:59                     ` Jonathan Nieder
2011-11-16  9:31                       ` Nguyen Thai Ngoc Duy
2011-11-19 19:25                         ` Ramsay Jones
2011-11-16 21:50                       ` [PATCH/RFC] introduce strbuf_addpath() Jonathan Nieder
2011-11-18  1:42                         ` Nguyen Thai Ngoc Duy
2011-11-16 22:04                     ` [PATCH 0/3] avoiding unintended consequences of git_path() usage Junio C Hamano
2011-11-16  8:51                   ` Ramkumar Ramachandra
2011-11-16 13:33                   ` Nguyen Thai Ngoc Duy
2011-11-16 13:44                     ` Michael Haggerty
2011-11-18  3:33                   ` Nguyen Thai Ngoc Duy [this message]
2011-11-05 16:29 ` [PATCH 4/5] sequencer: handle single commit pick separately Ramkumar Ramachandra
2011-11-06  0:35   ` Jonathan Nieder
2011-11-05 16:29 ` [PATCH 5/5] sequencer: revert d3f4628e Ramkumar Ramachandra
2011-11-06  0:42   ` Jonathan Nieder
2011-11-06 19:10     ` Junio C Hamano
2011-11-07  6:06       ` Ramkumar Ramachandra
2011-11-12 16:13     ` Ramkumar Ramachandra
2011-11-12 22:40       ` Jonathan Nieder
2011-11-05 23:43 ` [PATCH 0/5] Sequencer: working around historical mistakes Jonathan Nieder
2011-11-13 10:42   ` Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111118033349.GA20827@tre \
    --to=pclouds@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.