From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17069 invoked from network); 24 Aug 2021 22:12:42 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 24 Aug 2021 22:12:42 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 1ess; Tue Aug 24 18:08:10 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 617e11e0 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Tue, 24 Aug 2021 15:07:59 -0700 (PDT) Message-ID: To: 9front@9front.org Date: Tue, 24 Aug 2021 18:07:57 -0400 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: event-scale general-purpose configuration interface Subject: [9front] git: separate author and committer Reply-To: 9front@9front.org Precedence: bulk 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. diff ad26f82e44a5f59383edfde5f4c3727c225f4b0a uncommitted --- a//sys/lib/git/common.rc +++ b//sys/lib/git/common.rc @@ -38,7 +38,22 @@ status=() } -# merge1 out theirs base ours +fn whoami{ + name=`{git/conf user.name} + email=`{git/conf user.email} + if(test -f /adm/keys.who){ + if(~ $name '') + name=`{awk -F'|' '$1=="'$user'" {x=$3} END{print x}' mode = 0755 | DMDIR; d->name = estrdup9p("tree"); d->qid.type = QTDIR; - d->qid.path = qpath(c, i, o->id, Qcommittree); + d->qid.path = qpath(c, i, o->id, Qtree); break; case 1: d->name = estrdup9p("parent"); - d->qid.path = qpath(c, i, o->id, Qcommitparent); + d->qid.path = qpath(c, i, o->id, Qparent); break; case 2: d->name = estrdup9p("msg"); - d->qid.path = qpath(c, i, o->id, Qcommitmsg); + d->qid.path = qpath(c, i, o->id, Qmsg); break; case 3: d->name = estrdup9p("hash"); - d->qid.path = qpath(c, i, o->id, Qcommithash); + d->qid.path = qpath(c, i, o->id, Qhash); break; case 4: d->name = estrdup9p("author"); - d->qid.path = qpath(c, i, o->id, Qcommitauthor); + d->qid.path = qpath(c, i, o->id, Qauthor); break; default: return -1; @@ -491,18 +492,20 @@ q->type = 0; c->mtime = o->commit->mtime; c->mode = 0644; - assert(qdir == Qcommit || qdir == Qobject || qdir == Qcommittree || qdir == Qhead); + assert(qdir == Qcommit || qdir == Qobject || qdir == Qtree || qdir == Qhead || qdir == Qcommitter); if(strcmp(name, "msg") == 0) - q->path = qpath(p, 0, o->id, Qcommitmsg); + q->path = qpath(p, 0, o->id, Qmsg); else if(strcmp(name, "parent") == 0) - q->path = qpath(p, 1, o->id, Qcommitparent); + q->path = qpath(p, 1, o->id, Qparent); else if(strcmp(name, "hash") == 0) - q->path = qpath(p, 2, o->id, Qcommithash); + q->path = qpath(p, 2, o->id, Qhash); else if(strcmp(name, "author") == 0) - q->path = qpath(p, 3, o->id, Qcommitauthor); + q->path = qpath(p, 3, o->id, Qauthor); + else if(strcmp(name, "committer") == 0) + q->path = qpath(p, 3, o->id, Qcommitter); else if(strcmp(name, "tree") == 0){ q->type = QTDIR; - q->path = qpath(p, 4, o->id, Qcommittree); + q->path = qpath(p, 4, o->id, Qtree); unref(c->obj); c->mode = DMDIR | 0755; c->obj = readobject(o->commit->tree); @@ -640,14 +643,15 @@ case Qcommit: e = objwalk1(q, o->obj, o, c, name, Qcommit, aux); break; - case Qcommittree: - e = objwalk1(q, o->obj, o, c, name, Qcommittree, aux); + case Qtree: + e = objwalk1(q, o->obj, o, c, name, Qtree, aux); break; - case Qcommitparent: - case Qcommitmsg: - case Qcommitdata: - case Qcommithash: - case Qcommitauthor: + case Qparent: + case Qmsg: + case Qcdata: + case Qhash: + case Qauthor: + case Qcommitter: case Qctl: return Enodir; default: @@ -760,20 +764,24 @@ else dirread9p(r, objgen, aux); break; - case Qcommitmsg: + case Qmsg: readbuf(r, o->commit->msg, o->commit->nmsg); break; - case Qcommitparent: + case Qparent: readcommitparent(r, o); break; - case Qcommithash: + case Qhash: snprint(buf, sizeof(buf), "%H\n", o->hash); readstr(r, buf); break; - case Qcommitauthor: + case Qauthor: snprint(buf, sizeof(buf), "%s\n", o->commit->author); readstr(r, buf); break; + case Qcommitter: + snprint(buf, sizeof(buf), "%s\n", o->commit->committer); + readstr(r, buf); + break; case Qctl: e = readctl(r); break; @@ -785,8 +793,8 @@ objread(r, aux); break; case Qcommit: - case Qcommittree: - case Qcommitdata: + case Qtree: + case Qcdata: objread(r, aux); break; default: --- a/sys/src/cmd/git/import +++ b/sys/src/cmd/git/import @@ -7,9 +7,11 @@ rm -f $diffpath } +whoami + fn apply @{ git/fs - email='' + author='' name='' msg='' parents='-p'^`{git/query HEAD} @@ -27,10 +29,10 @@ state=="headers" && /^From:/ { sub(/^From:[ \t]*/, "", $0); name=$0; - email=$0; + author=$0; sub(/[ \t]*<.*$/, "", name); - sub(/.*/, "", email); + sub(/.*/, "", author); } state=="headers" && /^Date:/{ sub(/^Date:[ \t]*/, "", $0) @@ -57,10 +59,10 @@ END{ if(state != "diff") exit("malformed patch: " state); - if(name == "" || email == "" || date == "" || gotmsg == "") + if(name == "" || author == "" || date == "" || gotmsg == "") exit("missing headers"); printf "%s", name > "/env/name" - printf "%s", email > "/env/email" + printf "%s", author > "/env/author" printf "%s", date > "/env/date" } ' || die 'could not import:' $status @@ -79,7 +81,7 @@ } git/walk -fRMA $files if(~ $#nocommit 0){ - hash=`{git/save -n $name -e $email -m $msg -d $date $parents $files} + hash=`{git/save -n $name -e $author -c $email -m $msg -d $date $parents $files} echo $hash > $refpath } status='''' --- a/sys/src/cmd/git/log.c +++ b/sys/src/cmd/git/log.c @@ -153,6 +153,9 @@ tmtime(&tm, o->commit->mtime, tzload("local")); Bprint(out, "Hash:\t%H\n", o->hash); Bprint(out, "Author:\t%s\n", o->commit->author); + if(o->commit->committer != nil + && strcmp(o->commit->author, o->commit->committer) != 0) + Bprint(out, "Landed:\t%s\n", o->commit->committer); Bprint(out, "Date:\t%τ\n", tmfmt(&tm, "WW MMM D hh:mm:ss z YYYY")); Bprint(out, "\n"); p = o->commit->msg; --- a/sys/src/cmd/git/merge +++ b/sys/src/cmd/git/merge @@ -12,7 +12,7 @@ ours=$ourbr/$f base=$basebr/$f theirs=$theirbr/$f - merge1 ./$f $theirs $base $ours + merge1 ./$f $ours $base $theirs } } --- a/sys/src/cmd/git/save.c +++ b/sys/src/cmd/git/save.c @@ -299,7 +299,7 @@ void -mkcommit(Hash *c, char *msg, char *name, char *email, vlong date, Hash *parents, int nparents, Hash tree) +mkcommit(Hash *c, char *msg, char *name, char *email, char *comitter, vlong date, Hash *parents, int nparents, Hash tree) { char *s, h[64]; int ns, nh, i; @@ -310,7 +310,7 @@ 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, "committer %s <%s> %lld +0000\n", name, comitter, date); fmtprint(&f, "\n"); fmtprint(&f, "%s", msg); s = fmtstrflush(&f); @@ -347,7 +347,7 @@ main(int argc, char **argv) { Hash th, ch, parents[Maxparents]; - char *msg, *name, *email, *dstr, cwd[1024]; + char *msg, *name, *email, *committer, *dstr, cwd[1024]; int i, r, ncwd, nparents; vlong date; Object *t; @@ -360,6 +360,7 @@ msg = nil; name = nil; email = nil; + committer = nil; dstr = nil; date = time(nil); nparents = 0; @@ -366,10 +367,11 @@ 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': msg = EARGF(usage()); break; + case 'n': name = EARGF(usage()); break; + case 'e': email = EARGF(usage()); break; + case 'c': committer = EARGF(usage()); break; + case 'd': dstr = EARGF(usage()); break; case 'p': if(nparents >= Maxparents) sysfatal("too many parents"); @@ -386,6 +388,8 @@ sysfatal("missing name"); if(!email) sysfatal("missing email"); + if(!committer) + committer = email; if(dstr){ date=strtoll(dstr, &dstr, 10); if(strlen(dstr) != 0) @@ -405,7 +409,7 @@ 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, msg, name, email, committer, date, parents, nparents, th); print("%H\n", ch); exits(nil); }