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

Re: [PATCH] fetch-pack: remove --keep-auto and make it the default.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 26, 2007, 03:05 UTC
Message-ID
<7vhcue4heq.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vejpiaj2f.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
Show 23 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> On Wed, 24 Jan 2007, Junio C Hamano wrote:
>>
>>>   Ok, how about this, on top of the previous ones?
>>
>> Thanks!
>>
>>> @@ -653,6 +663,8 @@ int main(int argc, char **argv)
>>>  	struct stat st;
>>>  
>>>  	setup_git_directory();
>>> +	setup_ident();
>>> +	git_config(fetch_pack_config);
>>
>> Why do you need setup_ident()?
>
> Because presumably you would be updating the reflog that records
> who did the fetch?
>
> But then we should do the same ignore_missing_committer_name()
> we have in receive-pack to allow anonymous fetchers to fetch
> from outside world, I guess.
This turns out to be more serious than I expected.

The code that uses committer_info() in reflog can barf and die. And I do not think calling ignore_missing_committer_name() upfront like recent receive-pack did in the aplication is a reasonable workaround.

So I am thinking about doing something like the attached patch.
What the patch does.
 - git_committer_info() takes one parameter.  It used to be "if
   this is true, then die() if the name is not available due to
   bad GECOS, otherwise issue a warning once but leave the name
   empty".  The reason was because we wanted to prevent bad
   commits from being made by git-commit-tree (and its
   callers).  The value 0 is only used by "git var -l". 
   Now it takes -1, 0 or 1.  When set to -1, it does not
   complain but uses the pw->pw_name when name is not
   available.  Existing 0 and 1 values mean the same thing as
   they used to mean before.  0 means issue warnings and leave
   it empty, 1 means barf and die.
 - ignore_missing_committer_name() and its existing caller
   (receive-pack, to set the reflog) have been removed.
 - git-format-patch, to come up with the phoney message ID when
   asked to thread, now passes -1 to git_committer_info().  This
   codepath uses only the e-mail part, ignoring the name.  It
   used to barf and die.  The other call in the same program
   when asked to add signed-off-by line based on committer
   identity still passes 1 to make sure it barfs instead of
   adding a bogus s-o-b line.
 - log_ref_write in refs.c, to come up with the name to record
   who initiated the ref update in the reflog, passes -1.  It
   used to barf and die.

The last change means that git-update-ref, git-branch, and commit walker backends can now be used in a repository with reflog by somebody who does not have the user identity required to make a commit. They all used to barf and die.

I've run tests and all of them seem to pass, and also tried "git clone" as a user whose GECOS is empty -- git clone works again now (it was broken when reflog was enabled by default).

But this definitely needs extra sets of eyeballs.
---
diff --git a/builtin-log.c b/builtin-log.c
index 503cd1e..56acc13 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -352,7 +352,7 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options, co
 
 static void gen_message_id(char *dest, unsigned int length, char *base)
 {
-	const char *committer = git_committer_info(1);
+	const char *committer = git_committer_info(-1);
 	const char *email_start = strrchr(committer, '<');
 	const char *email_end = strrchr(committer, '>');
 	if(!email_start || !email_end || email_start > email_end - 1)
diff --git a/cache.h b/cache.h
index 473197d..9486132 100644
--- a/cache.h
+++ b/cache.h
@@ -320,7 +320,6 @@ void datestamp(char *buf, int bufsize);
 unsigned long approxidate(const char *);
 
 extern int setup_ident(void);
-extern void ignore_missing_committer_name(void);
 extern const char *git_author_info(int);
 extern const char *git_committer_info(int);
 
diff --git a/fetch-pack.c b/fetch-pack.c
index 4df7450..83a1d7b 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -671,8 +671,6 @@ int main(int argc, char **argv)
 
 	setup_git_directory();
 	setup_ident();
-	/* don't die if gecos is empty */
-	ignore_missing_committer_name();
 	git_config(fetch_pack_config);
 
 	if (0 <= transfer_unpack_limit)
diff --git a/ident.c b/ident.c
index 6ad8fed..f967790 100644
--- a/ident.c
+++ b/ident.c
@@ -180,12 +180,21 @@ static const char *get_ident(const char *name, const char *email,
 		email = git_default_email;
 
 	if (!*name) {
-		if (name == git_default_name && env_hint) {
+		struct passwd *pw;
+
+		if (0 <= error_on_no_name &&
+		    name == git_default_name && env_hint) {
 			fprintf(stderr, env_hint, au_env, co_env);
 			env_hint = NULL; /* warn only once, for "git-var -l" */
 		}
-		if (error_on_no_name)
+		if (0 < error_on_no_name)
 			die("empty ident %s <%s> not allowed", name, email);
+		pw = getpwuid(getuid());
+		if (!pw)
+			die("You don't exist. Go away!");
+		strlcpy(git_default_name, pw->pw_name,
+			sizeof(git_default_name));
+		name = git_default_name;
 	}
 
 	strcpy(date, git_default_date);
@@ -218,18 +227,3 @@ const char *git_committer_info(int error_on_no_name)
 			 getenv("GIT_COMMITTER_DATE"),
 			 error_on_no_name);
 }
-
-void ignore_missing_committer_name()
-{
-	/* If we did not get a name from the user's gecos entry then
-	 * git_default_name is empty; so instead load the username
-	 * into it as a 'good enough for now' approximation of who
-	 * this user is.
-	 */
-	if (!*git_default_name) {
-		struct passwd *pw = getpwuid(getuid());
-		if (!pw)
-			die("You don't exist. Go away!");
-		strlcpy(git_default_name, pw->pw_name, sizeof(git_default_name));
-	}
-}
diff --git a/receive-pack.c b/receive-pack.c
index 8b59b32..7d26326 100644
--- a/receive-pack.c
+++ b/receive-pack.c
@@ -430,8 +430,6 @@ int main(int argc, char **argv)
 		die("attempt to push into a shallow repository");
 
 	setup_ident();
-	/* don't die if gecos is empty */
-	ignore_missing_committer_name();
 	git_config(receive_pack_config);
 
 	if (0 <= transfer_unpack_limit)
diff --git a/refs.c b/refs.c
index 8117328..4323e9a 100644
--- a/refs.c
+++ b/refs.c
@@ -958,7 +958,7 @@ static int log_ref_write(struct ref_lock *lock,
 				     lock->log_file, strerror(errno));
 	}
 
-	committer = git_committer_info(1);
+	committer = git_committer_info(-1);
 	if (msg) {
 		maxlen = strlen(committer) + strlen(msg) + 2*40 + 5;
 		logrec = xmalloc(maxlen);
Previous: Johannes SchindelinNext: Junio C Hamano
Message 55 of 70 in “[Announce] GIT v1.5.0-rc2”
  1. Junio C HamanoJan 21, 2007
  2. Jakub NarebskiJan 21, 2007
  3. Junio C HamanoJan 21, 2007
  4. Johannes SchindelinJan 21, 2007
  5. Bill LearJan 23, 2007
  6. Johannes SchindelinJan 23, 2007
  7. Bill LearJan 23, 2007
  8. Uwe Kleine-KönigJan 23, 2007
  9. Bill LearJan 23, 2007
  10. Uwe Kleine-KönigJan 24, 2007
  11. Johannes SchindelinJan 23, 2007
  12. Peter BaumannJan 23, 2007
  13. Bill LearJan 23, 2007
  14. Linus TorvaldsJan 23, 2007
  15. Mark NudelmanJan 24, 2007
  16. Linus TorvaldsJan 24, 2007
  17. Linus TorvaldsJan 24, 2007
  18. Junio C HamanoJan 24, 2007
  19. Mark NudelmanMar 27, 2007
  20. Junio C HamanoJan 21, 2007
  21. Bill LearJan 21, 2007
  22. Bill LearJan 21, 2007
  23. MichaelJan 21, 2007
  24. Johannes SchindelinJan 21, 2007
  25. Jakub NarebskiJan 21, 2007
  26. Johannes SchindelinJan 21, 2007
  27. Jakub NarebskiJan 21, 2007
  28. Willy TarreauJan 21, 2007
  29. Jakub NarebskiJan 21, 2007
  30. Junio C HamanoJan 21, 2007
  31. H. Peter AnvinJan 21, 2007
  32. Nicolas PitreJan 22, 2007
  33. Horst H. von BrandJan 21, 2007
  34. Junio C HamanoJan 22, 2007
  35. Horst H. von BrandJan 21, 2007
  36. Junio C HamanoJan 21, 2007
  37. Johannes SchindelinJan 21, 2007
  38. Jakub NarebskiJan 21, 2007
  39. Johannes SchindelinJan 21, 2007
  40. Jakub NarebskiJan 21, 2007
  41. Johannes SchindelinJan 21, 2007
  42. Jakub NarebskiJan 21, 2007
  43. Junio C HamanoJan 22, 2007
  44. Junio C HamanoJan 22, 2007
  45. 1/2 Refactor the pack header reading function out of receive-pack.cJunio C Hamano, Jan 23, 2007
  46. 2/2 Allow fetch-pack to decide keeping the fetched pack without explodingJunio C Hamano, Jan 23, 2007
  47. Johannes SchindelinJan 23, 2007
  48. Jakub NarebskiJan 23, 2007
  49. code movements in diffs, was Re: [PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without explodingJohannes Schindelin, Jan 23, 2007
  50. Nicolas PitreJan 23, 2007
  51. fetch-pack: remove --keep-auto and make it the default.Junio C Hamano, Jan 25, 2007
  52. Johannes SchindelinJan 25, 2007
  53. Junio C HamanoJan 25, 2007
  54. Johannes SchindelinJan 25, 2007
  55. Junio C HamanoJan 26, 2007
  56. Allow non-developer to clone, checkout and fetch easier.Junio C Hamano, Jan 26, 2007
  57. Alex RiesenJan 26, 2007
  58. Johannes SixtJan 26, 2007
  59. Consolidate {receive,fetch}.unpackLimitJunio C Hamano, Jan 25, 2007
  60. Nicolas PitreJan 25, 2007
  61. Shawn O. PearceJan 25, 2007
  62. Linus TorvaldsJan 23, 2007
  63. David KågedalJan 23, 2007
  64. Johannes SchindelinJan 23, 2007
  65. Jakub NarebskiJan 23, 2007
  66. Carl WorthJan 22, 2007
  67. Junio C HamanoJan 22, 2007
  68. Carl WorthJan 23, 2007
  69. Jakub NarebskiJan 22, 2007
  70. Junio C HamanoJan 22, 2007

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.