diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-09-03 02:47:18 +0000 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-09-03 02:47:18 +0000 |
commit | d9564c0642b9a8280f8e4dfe9ff15a2c65b6d93d (patch) | |
tree | 5c956042dbc6eea3d4ee776a74a50d6424c5d6e2 /sys/src/cmd/git/save.c | |
parent | 485b334608910bbf6930a4f52ca946ba092fad04 (diff) |
git: separate author and committer
Git has the ability to track the person who
creates a commit separately from the person
who wrote the commit. For git9, we ignored
this feature.
However, as we start using git/import more,
it will be useful to figure out who imported
a commit, as well as who wrote it.
This change adds support for seeing this
information in git, as well as setting the
author and committer separately in git/import.
Diffstat (limited to 'sys/src/cmd/git/save.c')
-rw-r--r-- | sys/src/cmd/git/save.c | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/sys/src/cmd/git/save.c b/sys/src/cmd/git/save.c index d6062769c..08a1a50cf 100644 --- a/sys/src/cmd/git/save.c +++ b/sys/src/cmd/git/save.c @@ -14,6 +14,14 @@ enum { Maxparents = 16, }; +char *authorname; +char *authoremail; +char *committername; +char *committeremail; +char *commitmsg; +Hash parents[Maxparents]; +int nparents; + int gitmode(Dirent *e) { @@ -299,7 +307,7 @@ err: void -mkcommit(Hash *c, char *msg, char *name, char *email, vlong date, Hash *parents, int nparents, Hash tree) +mkcommit(Hash *c, vlong date, Hash tree) { char *s, h[64]; int ns, nh, i; @@ -309,10 +317,10 @@ mkcommit(Hash *c, char *msg, char *name, char *email, vlong date, Hash *parents, fmtprint(&f, "tree %H\n", tree); for(i = 0; i < nparents; i++) fmtprint(&f, "parent %H\n", parents[i]); - fmtprint(&f, "author %s <%s> %lld +0000\n", name, email, date); - fmtprint(&f, "committer %s <%s> %lld +0000\n", name, email, date); + fmtprint(&f, "author %s <%s> %lld +0000\n", authorname, authoremail, date); + fmtprint(&f, "committer %s <%s> %lld +0000\n", committername, committeremail, date); fmtprint(&f, "\n"); - fmtprint(&f, "%s", msg); + fmtprint(&f, "%s", commitmsg); s = fmtstrflush(&f); ns = strlen(s); @@ -346,9 +354,9 @@ usage(void) void main(int argc, char **argv) { - Hash th, ch, parents[Maxparents]; - char *msg, *name, *email, *dstr, cwd[1024]; - int i, r, ncwd, nparents; + Hash th, ch; + char *dstr, cwd[1024]; + int i, r, ncwd; vlong date; Object *t; @@ -357,19 +365,29 @@ main(int argc, char **argv) sysfatal("could not find git repo: %r"); if(getwd(cwd, sizeof(cwd)) == nil) sysfatal("getcwd: %r"); - msg = nil; - name = nil; - email = nil; dstr = nil; date = time(nil); - nparents = 0; ncwd = strlen(cwd); ARGBEGIN{ - case 'm': msg = EARGF(usage()); break; - case 'n': name = EARGF(usage()); break; - case 'e': email = EARGF(usage()); break; - case 'd': dstr = EARGF(usage()); break; + case 'm': + commitmsg = EARGF(usage()); + break; + case 'n': + authorname = EARGF(usage()); + break; + case 'e': + authoremail = EARGF(usage()); + break; + case 'N': + committername = EARGF(usage()); + break; + case 'E': + committeremail = EARGF(usage()); + break; + case 'd': + dstr = EARGF(usage()); + break; case 'p': if(nparents >= Maxparents) sysfatal("too many parents"); @@ -378,21 +396,26 @@ main(int argc, char **argv) break; default: usage(); + break; }ARGEND; - if(!msg) + if(commitmsg == nil) sysfatal("missing message"); - if(!name) + if(authorname == nil) sysfatal("missing name"); - if(!email) + if(authoremail == nil) sysfatal("missing email"); + if((committername == nil) != (committeremail == nil)) + sysfatal("partially specified committer"); + if(committername == nil && committeremail == nil){ + committername = authorname; + committeremail = authoremail; + } if(dstr){ date=strtoll(dstr, &dstr, 10); if(strlen(dstr) != 0) sysfatal("could not parse date %s", dstr); } - if(msg == nil || name == nil) - usage(); for(i = 0; i < argc; i++){ cleanname(argv[i]); if(*argv[i] == '/' && strncmp(argv[i], cwd, ncwd) == 0) @@ -405,7 +428,7 @@ main(int argc, char **argv) r = treeify(t, argv, argv + argc, 0, &th); if(r == -1) sysfatal("could not commit: %r\n"); - mkcommit(&ch, msg, name, email, date, parents, nparents, th); + mkcommit(&ch, date, th); print("%H\n", ch); exits(nil); } |