Don't force everybody to call setup_ident().
Back when only handful commands that created commit and tag were the only users of committer identity information, it made sense to explicitly call setup_ident() to pre-fill the default value from the gecos information. But it is much simpler for programs to make the call automatic when get_ident() is called these days, since many more programs want to use the information when updating the reflog. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 28, 2007 at 00:50 UTC
01754769ab9bf9ff2fe2b12590e7ee2c7c3448ca
13 files changed
+35
-28
builtin-branch.c
-1
@@ -394,7 +394,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
394
int kinds = REF_LOCAL_BRANCH;
395
int i;
396
397
- setup_ident();
397
git_config(git_branch_config);
398
399
for (i = 1; i < argc; i++) {
builtin-commit-tree.c
-1
@@ -94,7 +94,6 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
94
unsigned int size;
95
int encoding_is_utf8;
96
97
- setup_ident();
97
git_config(git_default_config);
98
99
if (argc < 2)
builtin-log.c
-1
@@ -380,7 +380,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
380
char message_id[1024];
381
char ref_message_id[1024];
382
383
- setup_ident();
383
git_config(git_format_config);
384
init_revisions(&rev, prefix);
385
rev.commit_format = CMIT_FMT_EMAIL;
builtin-update-ref.c
-1
@@ -13,7 +13,6 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
13
int i, delete;
14
15
delete = 0;
16
- setup_ident();
16
git_config(git_default_config);
17
18
for (i = 1; i < argc; i++) {
cache.h
-1
@@ -319,7 +319,6 @@ int parse_date(const char *date, char *buf, int bufsize);
319
void datestamp(char *buf, int bufsize);
320
unsigned long approxidate(const char *);
321
322
-extern int setup_ident(void);
322
extern const char *git_author_info(int);
323
extern const char *git_committer_info(int);
324
fetch-pack.c
-1
@@ -670,7 +670,6 @@ int main(int argc, char **argv)
670
struct stat st;
671
672
setup_git_directory();
673
- setup_ident();
673
git_config(fetch_pack_config);
674
675
if (0 <= transfer_unpack_limit)
http-fetch.c
-1
@@ -1003,7 +1003,6 @@ int main(int argc, const char **argv)
1003
int arg = 1;
1004
int rc = 0;
1005
1006
- setup_ident();
1006
setup_git_directory();
1007
git_config(git_default_config);
1008
http-push.c
-1
@@ -2299,7 +2299,6 @@ int main(int argc, char **argv)
2299
struct ref *ref;
2300
2301
setup_git_directory();
2302
- setup_ident();
2302
2303
remote = xcalloc(sizeof(*remote), 1);
2304
ident.c
+35
-16
@@ -43,19 +43,13 @@ static void copy_gecos(struct passwd *w, char *name, int sz)
43
44
}
45
46
-int setup_ident(void)
46
+static void copy_email(struct passwd *pw)
47
{
48
- int len;
49
- struct passwd *pw = getpwuid(getuid());
50
-
51
- if (!pw)
52
- die("You don't exist. Go away!");
53
-
54
- /* Get the name ("gecos") */
55
- copy_gecos(pw, git_default_name, sizeof(git_default_name));
56
-
57
- /* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
58
- len = strlen(pw->pw_name);
48
+ /*
49
+ * Make up a fake email address
50
+ * (name + '@' + hostname [+ '.' + domainname])
51
+ */
52
+ int len = strlen(pw->pw_name);
53
if (len > sizeof(git_default_email)/2)
54
die("Your sysadmin must hate you!");
55
memcpy(git_default_email, pw->pw_name, len);
@@ -68,13 +62,37 @@ int setup_ident(void)
62
len = strlen(git_default_email);
63
git_default_email[len++] = '.';
64
if (he && (domainname = strchr(he->h_name, '.')))
71
- strlcpy(git_default_email + len, domainname + 1, sizeof(git_default_email) - len);
65
+ strlcpy(git_default_email + len, domainname + 1,
66
+ sizeof(git_default_email) - len);
67
else
73
- strlcpy(git_default_email + len, "(none)", sizeof(git_default_email) - len);
68
+ strlcpy(git_default_email + len, "(none)",
69
+ sizeof(git_default_email) - len);
70
}
71
+}
72
+
73
+static void setup_ident(void)
74
+{
75
+ struct passwd *pw = NULL;
76
+
77
+ /* Get the name ("gecos") */
78
+ if (!git_default_name[0]) {
79
+ pw = getpwuid(getuid());
80
+ if (!pw)
81
+ die("You don't exist. Go away!");
82
+ copy_gecos(pw, git_default_name, sizeof(git_default_name));
83
+ }
84
+
85
+ if (!git_default_email[0]) {
86
+ if (!pw)
87
+ pw = getpwuid(getuid());
88
+ if (!pw)
89
+ die("You don't exist. Go away!");
90
+ copy_email(pw);
91
+ }
92
+
93
/* And set the default date */
76
- datestamp(git_default_date, sizeof(git_default_date));
77
- return 0;
94
+ if (!git_default_date[0])
95
+ datestamp(git_default_date, sizeof(git_default_date));
96
}
97
98
static int add_raw(char *buf, int size, int offset, const char *str)
@@ -174,6 +192,7 @@ static const char *get_ident(const char *name, const char *email,
192
char date[50];
193
int i;
194
195
+ setup_ident();
196
if (!name)
197
name = git_default_name;
198
if (!email)
local-fetch.c
-1
@@ -210,7 +210,6 @@ int main(int argc, const char **argv)
210
char **commit_id;
211
int arg = 1;
212
213
- setup_ident();
213
setup_git_directory();
214
git_config(git_default_config);
215
receive-pack.c
-1
@@ -429,7 +429,6 @@ int main(int argc, char **argv)
429
if (is_repository_shallow())
430
die("attempt to push into a shallow repository");
431
432
- setup_ident();
432
git_config(receive_pack_config);
433
434
if (0 <= transfer_unpack_limit)
ssh-fetch.c
-1
@@ -124,7 +124,6 @@ int main(int argc, char **argv)
124
prog = getenv("GIT_SSH_PUSH");
125
if (!prog) prog = "git-ssh-upload";
126
127
- setup_ident();
127
setup_git_directory();
128
git_config(git_default_config);
129
var.c
-1
@@ -56,7 +56,6 @@ int main(int argc, char **argv)
56
}
57
58
setup_git_directory();
59
- setup_ident();
59
val = NULL;
60
61
if (strcmp(argv[1], "-l") == 0) {