A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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