4 * create git identifier lines of the form "name <email> date"
6 * Copyright (C) 2005 Linus Torvalds
14 static char real_email
[1000];
15 static char real_name
[1000];
16 static char real_date
[50];
21 struct passwd
*pw
= getpwuid(getuid());
24 die("You don't exist. Go away!");
26 /* Get the name ("gecos") */
27 len
= strlen(pw
->pw_gecos
);
28 if (len
>= sizeof(real_name
))
29 die("Your parents must have hated you!");
30 memcpy(real_name
, pw
->pw_gecos
, len
+1);
32 /* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
33 len
= strlen(pw
->pw_name
);
34 if (len
> sizeof(real_email
)/2)
35 die("Your sysadmin must hate you!");
36 memcpy(real_email
, pw
->pw_name
, len
);
37 real_email
[len
++] = '@';
38 gethostname(real_email
+ len
, sizeof(real_email
) - len
);
39 #ifndef NO_GETDOMAINNAME
40 if (!strchr(real_email
+len
, '.')) {
41 len
= strlen(real_email
);
42 real_email
[len
++] = '.';
43 getdomainname(real_email
+len
, sizeof(real_email
)-len
);
46 /* And set the default date */
47 datestamp(real_date
, sizeof(real_date
));
51 static int add_raw(char *buf
, int size
, int offset
, const char *str
)
53 int len
= strlen(str
);
54 if (offset
+ len
> size
)
56 memcpy(buf
+ offset
, str
, len
);
60 static int crud(unsigned char c
)
62 static char crud_array
[256];
63 static int crud_array_initialized
= 0;
65 if (!crud_array_initialized
) {
68 for (k
= 0; k
<= 31; ++k
) crud_array
[k
] = 1;
78 crud_array_initialized
= 1;
84 * Copy over a string to the destination, but avoid special
85 * characters ('\n', '<' and '>') and remove crud at the end
87 static int copy(char *buf
, int size
, int offset
, const char *src
)
92 /* Remove crud from the beginning.. */
93 while ((c
= *src
) != 0) {
99 /* Remove crud from the end.. */
109 * Copy the rest to the buffer, but avoid the special
110 * characters '\n' '<' and '>' that act as delimeters on
111 * a identification line
113 for (i
= 0; i
< len
; i
++) {
116 case '\n': case '<': case '>':
126 char *get_ident(const char *name
, const char *email
, const char *date_str
)
128 static char buffer
[1000];
136 strcpy(date
, real_date
);
138 parse_date(date_str
, date
, sizeof(date
));
140 i
= copy(buffer
, sizeof(buffer
), 0, name
);
141 i
= add_raw(buffer
, sizeof(buffer
), i
, " <");
142 i
= copy(buffer
, sizeof(buffer
), i
, email
);
143 i
= add_raw(buffer
, sizeof(buffer
), i
, "> ");
144 i
= copy(buffer
, sizeof(buffer
), i
, date
);
145 if (i
>= sizeof(buffer
))
146 die("Impossibly long personal identifier");
151 char *git_author_info(void)
153 return get_ident(getenv("GIT_AUTHOR_NAME"), getenv("GIT_AUTHOR_EMAIL"), getenv("GIT_AUTHOR_DATE"));
156 char *git_committer_info(void)
158 return get_ident(getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"), getenv("GIT_COMMITTER_DATE"));