logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

Email-driven-git.md (11383B)


  1. ---
  2. date: 2018-07-02
  3. title: The advantages of an email-driven git workflow
  4. layout: post
  5. tags: [philosophy, mail, git]
  6. ---
  7. [git 2.18.0][git 2.18.0] has been released, and with it my first contribution to
  8. git has shipped! My patch was for a git feature which remains disappointingly
  9. obscure: [git send-email](https://git-scm.com/docs/git-send-email). I want to
  10. introduce my readers to this feature and speak to the benefits of using an
  11. email-driven git workflow - the workflow git was originally designed for.
  12. [git 2.18.0]: https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.18.0.txt
  13. Email isn't as sexy as GitHub (and its imitators), but it has several
  14. advantages over the latter. Email is standardized, federated, well-understood,
  15. and venerable. A very large body of email-related software exists and is equally
  16. reliable and well-understood. You can interact with email using only open source
  17. software and customize your workflow at every level of the stack - filtering,
  18. organizing, forwarding, replying, and so on; in any manner you choose.
  19. Git has several built-in tools for leveraging email. The first one of note is
  20. [format-patch](https://git-scm.com/docs/git-format-patch). This can take a git
  21. commit (or series of commits) and format them as plaintext emails with embedded
  22. diffs. Here's a small example of its output:
  23. ```mail
  24. From 8f5045c871c3060ff5f5f99ce1ada09f4b4cd105 Mon Sep 17 00:00:00 2001
  25. From: Drew DeVault <sir@cmpwn.com>
  26. Date: Wed, 2 May 2018 08:59:27 -0400
  27. Subject: [PATCH] Silently ignore touch_{motion,up} for unknown ids
  28. ---
  29. types/wlr_seat.c | 2 --
  30. 1 file changed, 2 deletions(-)
  31. diff --git a/types/wlr_seat.c b/types/wlr_seat.c
  32. index f77a492d..975746db 100644
  33. --- a/types/wlr_seat.c
  34. +++ b/types/wlr_seat.c
  35. @@ -1113,7 +1113,6 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time,
  36. struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
  37. struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
  38. if (!point) {
  39. - wlr_log(L_ERROR, "got touch up for unknown touch point");
  40. return;
  41. }
  42. @@ -1128,7 +1127,6 @@ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time,
  43. struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
  44. struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
  45. if (!point) {
  46. - wlr_log(L_ERROR, "got touch motion for unknown touch point");
  47. return;
  48. }
  49. --
  50. 2.18.0
  51. ```
  52. git format-patch is at the bottom of git's stack of outgoing email features. You
  53. can send the emails it generates manually, but usually you'll use git send-email
  54. instead. It logs into the SMTP server of your choice and sends the email for
  55. you, after running git format-patch for you and giving you an opportunity to
  56. make any edits you like. Given that most popular email clients these days are
  57. awful and can't handle basic tasks like "sending email" properly, I strongly
  58. recommend this tool over attempting to send format-patch's output yourself.
  59. <img style="max-width: 75%" src="https://sr.ht/wmKv.jpg" />
  60. <p style="text-align: center; max-width: 80%; margin: 1rem auto">
  61. <em>
  62. I put a notch in my keyboard for each person who ignores my advice,
  63. struggles through sending emails manually, and eventually comes around
  64. to letting git send-email do it for them.
  65. </em>
  66. </p>
  67. I recommend a few settings to apply to git send-email to make your workflow a
  68. bit easier. One is `git config --global sendemail.verify off`, which turns off
  69. a sometimes-annoying and always-confusing validation step which checks for
  70. features only supported by newer SMTP servers - newer, in this case, meaning
  71. more recent than November of 1995. I started a thread on the git mailing list
  72. this week to discuss changing this option to off by default.
  73. You can also set the default recipient for a given repository by using a local
  74. git config: `git config sendemail.to admin@example.org`. This lets you skip a
  75. step if you send your patches to a consistent destination for that project, like
  76. a mailing list. I also recommend `git config --global sendemail.annotate yes`,
  77. which will always open the emails in your editor to allow you to make changes
  78. (you can get this with `--annotate` if you don't want it every time).
  79. The main edit you'll want to make when annotating is to provide what some call
  80. "timely commentary" on your patch. Immediately following the `---` after your
  81. commit message, you can add a summary of your changes which can be seen by the
  82. recipient, but doesn't appear in the final commit log. This is a useful place to
  83. talk about anything useful regarding the testing, review, or integration of your
  84. changes. You may also want to edit the `[PATCH]` text in the subject line to
  85. something like `[PATCH v2]` - this can also be done with the `-v` flag as well.
  86. I also like to add additional To's, Cc's, etc at this time.
  87. Git also provides tools for the recipient of your messages. One such tool is
  88. [git am](https://git-scm.com/docs/git-am), which accepts an email prepared with
  89. format-patch and integrates it into their repository. Several flags are provided
  90. to assist with common integration activities, like signing off on the commit or
  91. attempting a 3-way merge. The difficult part can be getting the email to git am
  92. in the first place. If you simply use the GMail web UI, this can be difficult. I
  93. use [mutt](http://www.mutt.org/), a TUI email client, to manage incoming
  94. patches. This is useful for being able to compose replies with vim rather than
  95. fighting some other mail client to write emails the way I want, but more
  96. importantly it has the `|` key, which prompts you for a command to pipe the
  97. email into. Other tools like [OfflineIMAP](http://www.offlineimap.org/) are also
  98. useful here.
  99. On the subject of composing replies, reviewing patches is quite easy with the
  100. email approach as well. Many bad, yet sadly popular email clients have
  101. popularized the idea that the sender's message is immutable, encouraging you to
  102. [top post][top posting] and leave an endlessly growing chain of replies
  103. underneath your message. A secret these email clients have kept from you is that
  104. you are, in fact, permitted by the mail RFCs to edit the sender's message as you
  105. please when replying - a style called [bottom posting][bottom posting]. I
  106. strongly encourage you to get comfortable doing this in general, but it's
  107. essential when reviewing patches received over email.
  108. [top posting]: https://en.wikipedia.org/wiki/Posting_style#Top-posting
  109. [bottom posting]: https://en.wikipedia.org/wiki/Posting_style#Bottom-posting
  110. In this manner, you can dissect the patch and respond to specific parts of it
  111. requesting changes or clarifications. It's just email - you can reply, forward
  112. the message, Cc interested parties, start several chains of discussion, and so
  113. on. I recently sent the following feedback on a patch I received:
  114. ```mail
  115. Date: Mon, 11 Jun 2018 14:19:22 -0400
  116. From: Drew DeVault <sir@cmpwn.com>
  117. To: Gregory Mullen <omitted>
  118. Subject: Re: [PATCH 2/3 todo] Filter private events from events feed
  119. On 2018-06-11 9:14 AM, Gregory Mullen wrote:
  120. > diff --git a/todosrht/alembic/versions/cb9732f3364c_clear_defaults_from_tickets_to_support_.py b/todosrht/alembic/versions/cb9732f3364c_clear_defaults_from_tickets_to_support_.py
  121. > -%<-
  122. > +class FlagType(types.TypeDecorator):
  123. I think you can safely import the srht FlagType here without implicating
  124. the entire sr.ht database support code
  125. > diff --git a/todosrht/blueprints/html.py b/todosrht/blueprints/html.py
  126. > -%<-
  127. > +def collect_events(target, count):
  128. > + events = []
  129. > + for e in EventNotification.query.filter(EventNotification.user_id == target.id).order_by(EventNotification.created.desc()):
  130. 80 cols
  131. I suspect this 'collect_events' function can be done entirely in SQL
  132. without having to process permissions in Python and do several SQL
  133. round-trips
  134. > @html.route("/~<username>")
  135. > def user_GET(username):
  136. > - print(username)
  137. Whoops! Nice catch.
  138. > user = User.query.filter(User.username == username.lower()).first()
  139. > if not user:
  140. > abort(404)
  141. > trackers, _ = get_tracker(username, None)
  142. > # TODO: only show public events (or events the current user can see)
  143. Can remove the comment
  144. ```
  145. Obviously this isn't the whole patch we're seeing - I've edited it down to just
  146. the parts I want to talk about. I also chose to leave the file names in to aid
  147. in navigating my feedback, with casual `-%<-` symbols indicating where I had
  148. trimmed out parts of the patch. This approach is common and effective.
  149. The main disadvantage of email driven development is that some people are more
  150. comfortable working with email in clients which are not well-suited to this kind
  151. of work. Popular email clients have caused terrible ideas like HTML email to
  152. proliferate, not only enabling spam, privacy leaks, and security
  153. vulnerabilities, but also making it more difficult for people to write emails
  154. that can be understood by git or tolerated by advanced email users.
  155. I don't think that the solution to these problems is to leave these powerful
  156. tools hanging in the wind and move to less powerful models like GitHub's pull
  157. requests. This is why on my own platform, [sr.ht](https://sr.ht), I chose to
  158. embrace git's email-driven approach, and extend it with new tools that make it
  159. easier to participate without directly using email. For those like me, I still
  160. want the email to be there so you can dig my heels in and do it old-school, but
  161. I appreciate that it's not for everyone.
  162. I started working on the sr.ht mailing list service a couple of weeks ago, which
  163. is where these goals will be realized with new email-driven code review tools.
  164. My friend [Simon](https://emersion.fr) has been helping out with a Python module
  165. named [emailthreads](https://git.sr.ht/~emersion/python-emailthreads/) which can
  166. be used to parse email discussions - with a surprising degree of accuracy,
  167. considering the flexibility of email. Once I get these tools into a usable
  168. state, we'll likely see sr.ht registrations finally opened to the general public
  169. (interested in trying it earlier? [Email me](mailto:sir@cmpwn.com)). Of course,
  170. it's all [open source](https://git.sr.ht/~sircmpwn/?search=sr.ht), so you can
  171. follow along and try it on your own infrastructure if you like.
  172. Using email for git scales extremely well. The canonical project, of course, is
  173. the Linux kernel. A change is made to the Linux kernel an average of 7 times per
  174. hour, constantly. It is maintained by dozens of veritable clans of software
  175. engineers hacking on dozens of modules, and email allows these changes to
  176. efficiently flow code throughout the system. Without email, Linux's maintenance
  177. model would be impossible. It's worth noting that git was designed for
  178. maintaining Linux, of course.
  179. With the right setup, it's well suited to small projects as well. Sending a
  180. patch along for review is a single git command. It lands directly in the
  181. maintainer's inbox and can be integrated with a handful of keystrokes. All of
  182. this works without any centralization or proprietary software involved. We
  183. should embrace this!
  184. ---
  185. Related articles sent in by readers:
  186. [Mailing lists vs Github](https://begriffs.com/posts/2018-06-05-mailing-list-vs-github.html)
  187. by Joe Nelson
  188. [You're using git wrong](https://web.archive.org/web/20180522180815/https://dpc.pw/blog/2017/08/youre-using-git-wrong/) by
  189. Dawid Ciężarkiewicz