git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] Expand ~ and ~user in core.excludesfile, commit.template

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 29, 2008, 16:08 UTC
Message-ID
<7vsksn4xdo.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<quack.20080829T0229.lthhc94rwyr_-_@roar.cs.berkeley.edu>
Karl Chen <quarl@cs.berkeley.edu> writes:
Show 7 quoted lines
> These config variables are parsed to substitute ~ and ~user with getpw
> entries.
>
> user_path() refactored into new function expand_user_path(), to allow
> dynamically allocating the return buffer.
>
> Signed-off-by: Karl Chen <quarl@quarl.org>
Thanks.
> ... Anyway, I accept the color you picked for this
> bikeshed.

I do not think Documentation/CodingStyle is bikesheding but just behaving like Romans do while in Rome, so that the end result will blend in better.

Show 6 quoted lines
>     Hannes> You really should use the strbuf API here. Look for
>     Hannes> strbuf_detach() in the existing code.
>
> Unfortunately expand_user_path() needs to support both a fixed
> buffer and mallocing return.  I don't think the strbuf API can do
> that easily?

I do not see any strong reason why the single caller of user_path() has to keep using the static allocation. Would it help to reduce the complexity of your expand_user_path() implementation, if we fixed the caller along the lines of this patch (untested, but just to illustrate the point)?

 path.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git i/path.c w/path.c
index 76e8872..c5b253c 100644
--- i/path.c
+++ w/path.c
@@ -221,19 +221,22 @@ char *enter_repo(char *path, int strict)
 		if (PATH_MAX <= len)
 			return NULL;
 		if (path[0] == '~') {
-			if (!user_path(used_path, path, PATH_MAX))
+			char *newpath = expand_user_path(path);
+			if (!newpath || (PATH_MAX <= strlen(newpath))) {
+				if (path != newpath)
+					free(newpath);
 				return NULL;
+			}
 			strcpy(validated_path, path);
-			path = used_path;
-		}
-		else if (PATH_MAX - 10 < len)
-			return NULL;
-		else {
+			path = newpath;
+		} else {
 			path = strcpy(used_path, path);
 			strcpy(validated_path, path);
 		}
 		len = strlen(path);
 		for (i = 0; suffix[i]; i++) {
+			if (PATH_MAX <= strlen(suffix[i] + len))
+				continue;
 			strcpy(path + len, suffix[i]);
 			if (!access(path, F_OK)) {
 				strcat(validated_path, suffix[i]);
Previous: Karl ChenNext: Karl Chen
Message 37 of 45 in “Support "core.excludesfile = ~/.gitignore"”
  1. Support "core.excludesfile = ~/.gitignore"Karl Chen, Aug 22, 2008
  2. Eric RaibleAug 22, 2008
  3. Bert WesargAug 22, 2008
  4. Junio C HamanoAug 22, 2008
  5. Karl ChenAug 24, 2008
  6. Junio C HamanoAug 24, 2008
  7. Jeff KingAug 24, 2008
  8. Junio C HamanoAug 24, 2008
  9. Jeff KingAug 24, 2008
  10. Junio C HamanoAug 24, 2008
  11. limiting relationship of git dir and worktree (was Re: [PATCH] Support "core.excludesfile = ~/.gitignore")Jeff King, Aug 24, 2008
  12. Dropping core.worktree and GIT_WORK_TREE support (was Re: limiting relationship of git dir and worktree)Junio C Hamano, Aug 25, 2008
  13. Miklos VajnaAug 25, 2008
  14. Junio C HamanoAug 25, 2008
  15. Miklos VajnaAug 25, 2008
  16. Nguyen Thai Ngoc DuyAug 25, 2008
  17. git diff/diff-index/diff-files: call setup_work_tree()Miklos Vajna, Aug 25, 2008
  18. Nguyen Thai Ngoc DuyAug 25, 2008
  19. Miklos VajnaAug 25, 2008
  20. git diff/diff-index/diff-files: call setup_work_tree()Miklos Vajna, Aug 25, 2008
  21. Nguyen Thai Ngoc DuyAug 25, 2008
  22. Junio C HamanoAug 26, 2008
  23. diff*: fix worktree setupNguyễn Thái Ngọc Duy, Aug 28, 2008
  24. Junio C HamanoAug 25, 2008
  25. Miklos VajnaAug 25, 2008
  26. Michael J GruberAug 26, 2008
  27. Jeff KingAug 27, 2008
  28. Support "core.excludesfile = ~/.gitignore"Karl Chen, Aug 25, 2008
  29. Johannes SixtAug 26, 2008
  30. Jeff KingAug 27, 2008
  31. Karl ChenAug 27, 2008
  32. Junio C HamanoAug 27, 2008
  33. Expand ~ and ~user in core.excludesfile, commit.templateKarl Chen, Aug 28, 2008
  34. Jeff KingAug 29, 2008
  35. Junio C HamanoAug 29, 2008
  36. Expand ~ and ~user in core.excludesfile, commit.templateKarl Chen, Aug 29, 2008
  37. Junio C HamanoAug 29, 2008
  38. Karl ChenAug 29, 2008
  39. Junio C HamanoAug 29, 2008
  40. Karl ChenAug 29, 2008
  41. Junio C HamanoAug 30, 2008
  42. Jeff KingAug 30, 2008
  43. Johannes SixtAug 29, 2008
  44. Karl ChenAug 27, 2008
  45. Junio C HamanoAug 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.