X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=commit-tree.c;h=043c7aa371101a1ea8cfc467279abf6c8acc7fd1;hb=706bc531a19f268bb03dda7551929dee20172548;hp=50fe19652f1b440c4123f92af886e47bb418bb11;hpb=27de946d0ee70fad497253bbaab76d2fa7b1c77c;p=git.git diff --git a/commit-tree.c b/commit-tree.c index 50fe19652..043c7aa37 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -83,11 +83,11 @@ static void finish_buffer(char *tag, char **bufp, unsigned int *sizep) static void remove_special(char *p) { char c; - char *dst = p; + char *dst = p, *src = p; for (;;) { - c = *p; - p++; + c = *src; + src++; switch(c) { case '\n': case '<': case '>': continue; @@ -96,6 +96,21 @@ static void remove_special(char *p) if (!c) break; } + + /* + * Go back, and remove crud from the end: some people + * have commas etc in their gecos field + */ + dst--; + while (--dst >= p) { + unsigned char c = *dst; + switch (c) { + case ',': case ';': case '.': + *dst = 0; + continue; + } + break; + } } static const char *month_names[] = { @@ -240,6 +255,18 @@ static void parse_rfc2822_date(char *date, char *result, int maxlen) snprintf(result, maxlen, "%lu %5.5s", then, p); } +static void check_valid(unsigned char *sha1, const char *expect) +{ + void *buf; + char type[20]; + unsigned long size; + + buf = read_sha1_file(sha1, type, &size); + if (!buf || strcmp(type, expect)) + die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect); + free(buf); +} + /* * Having more than two parents may be strange, but hey, there's * no conceptual reason why the file format couldn't accept multi-way @@ -257,8 +284,8 @@ int main(int argc, char **argv) unsigned char tree_sha1[20]; unsigned char parent_sha1[MAXPARENT][20]; unsigned char commit_sha1[20]; - char *gecos, *realgecos; - char *email, realemail[1000]; + char *gecos, *realgecos, *commitgecos; + char *email, *commitemail, realemail[1000]; char date[20], realdate[20]; char *audate; char comment[1000]; @@ -271,11 +298,13 @@ int main(int argc, char **argv) if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0) usage("commit-tree [-p ]* < changelog"); + check_valid(tree_sha1, "tree"); for (i = 2; i < argc; i += 2) { char *a, *b; a = argv[i]; b = argv[i+1]; if (!b || strcmp(a, "-p") || get_sha1_hex(b, parent_sha1[parents])) usage("commit-tree [-p ]* < changelog"); + check_valid(parent_sha1[parents], "commit"); parents++; } if (!parents) @@ -288,20 +317,26 @@ int main(int argc, char **argv) memcpy(realemail, pw->pw_name, len); realemail[len] = '@'; gethostname(realemail+len+1, sizeof(realemail)-len-1); + if (!strchr(realemail+len+1, '.')) { + strcat(realemail, "."); + getdomainname(realemail+strlen(realemail), sizeof(realemail)-strlen(realemail)-1); + } time(&now); tm = localtime(&now); strftime(realdate, sizeof(realdate), "%s %z", tm); strcpy(date, realdate); + commitgecos = getenv("COMMIT_AUTHOR_NAME") ? : realgecos; + commitemail = getenv("COMMIT_AUTHOR_EMAIL") ? : realemail; gecos = getenv("AUTHOR_NAME") ? : realgecos; email = getenv("AUTHOR_EMAIL") ? : realemail; audate = getenv("AUTHOR_DATE"); if (audate) parse_rfc2822_date(audate, date, sizeof(date)); - remove_special(gecos); remove_special(realgecos); - remove_special(email); remove_special(realemail); + remove_special(gecos); remove_special(realgecos); remove_special(commitgecos); + remove_special(email); remove_special(realemail); remove_special(commitemail); init_buffer(&buffer, &size); add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1)); @@ -316,7 +351,7 @@ int main(int argc, char **argv) /* Person/date information */ add_buffer(&buffer, &size, "author %s <%s> %s\n", gecos, email, date); - add_buffer(&buffer, &size, "committer %s <%s> %s\n\n", realgecos, realemail, realdate); + add_buffer(&buffer, &size, "committer %s <%s> %s\n\n", commitgecos, commitemail, realdate); /* And add the comment */ while (fgets(comment, sizeof(comment), stdin) != NULL)