gerrit(2) | 为什么使用 gerrit

gerrit(2) | 为什么使用 gerrit

本文以 Use Gerrit to Be a Rockstar Programmer 的翻译为基础, 增加一点个人笔记。

依照惯例, 中文的括号里是个人的粗浅看法。

概要 (Overview)

The term rockstar is often used to describe those talented programmers who seem to work faster and better than everyone else, much like a composer who seems to effortlessly churn out fantastic music. However, just as the spontaneity of masterful music is a fantasy, so is the development of exceptional code.

“摇滚明星”这个词经常用来形容那些比其他人工作更快更好的有才华的程序员,就像作曲家似的毫不费力地创作出了惊人的音乐一样。然而,就像精湛音乐的自发性一样,卓越代码的开发也是一个幻想。
(10倍程序员、全站程序员的说法,早就听说过了, 这些人产出高是事实; 作者似乎认为, 这些高质量的产出是需要练习而得到的?)

The process of composing and then recording music is painstaking — the artist records portions of a composition over and over, changing each take until one song is completed by combining those many takes into a cohesive whole. The end result is the recording of the best performance of the best version of the song.

创作然后录制音乐的过程是很费力的——艺术家一遍又一遍地录制作品的部分,改变每次的录音,直到通过将这些多次录音合并成一个连贯的整体来完成一首歌曲。最终结果是录制下了这首歌最佳版本的最佳表演。
(台上一分钟, 台下十年功 – 貌似说的有点夸张, 但是对于作曲家来说, 是经过练习而不是一下子演奏出高质量的曲子)

Consider Queen’s six-minute long Bohemian Rhapsody, which took three weeks to record. Some segments were overdubbed 180 times!

考虑一下女王乐队演唱的长达六分钟的《波西米亚狂想曲》,录制这首歌花了三个星期的时间。有些部分甚至进行了180次的重叠录音!

Software engineering is much the same. Changes that seem logical and straightforward in retrospect actually required many revisions and many hours of work before they were ready to be merged into a code base. A single conceptual code change (fix bug 123) often requires numerous iterations before it can be finalized. Programmers typically:

软件工程也是如此。事后看来似乎合乎逻辑且直截了当的改变实际上需要许多修订和许多工作小时,然后才能准备好合并到代码库中。一个概念上的代码变更(修复错误123)通常需要多次迭代才能最终确定下来。程序员通常:
(简洁的代码, 你看着挺自然, 但是可能是经过反复推敲修改的)。

  • 修复编译错误 (Fix compilation errors)
  • 提取一个方法,避免重复代码 (Factor out a method, to avoid duplicate code)
  • 使用更好的算法,使其更快 (Use a better algorithm, to make it faster)
  • 处理错误条件,使其更加健壮 (Handle error conditions, to make it more robust)
  • 添加测试,防止错误再次出现 (Add tests, to prevent a bug from regressing)
  • 调整测试,以反映更改的行为 (Adapt tests, to reflect changed behavior)
  • 优化代码,使其更易阅读 (Polish code, to make it easier to read)
  • 改进提交信息,解释为什么进行了更改 (Improve the commit message, to explain why a change was made)
    (这一段是说, clean code, 单元测试, 甚至 commit message 的编写也要符合规范)

In fact, first drafts of code changes are best kept out of project history. Not just because rockstar programmers want to hide sloppy first attempts at making something work. It’s more that keeping intermediate states hampers effective use of version control. Git works best when one commit corresponds to one functional change, as is required for:

实际上,最好将代码更改的初稿保留在项目历史记录之外。这不仅仅是因为rockstar程序员想要隐藏制作东西的杂乱初次尝试。更重要的是,保留中间状态会妨碍有效使用版本控制。Git 在一个提交对应一个功能性更改时效果最佳,这也是必需的。

(好的代码仓库, 连代码提交历史也是清爽的。 Every git commit counts. 每个 commit 都要有意义, 功能达到最佳。 感觉这挺难的)

Git 在进行版本控制时,最好是一个提交对应一个功能性的改变,这对以下操作是必须的:

  • git revert
  • git cherry-pick
  • git bisect

修订提交 (Amending commits)

Git provides a mechanism to continually update a commit until it’s perfect: use git commit --amend to remake (re-record) a code change. After you update a commit in this way, your branch then points to the new commit. However, the older (imperfect) revision is not lost. It can be found via the git reflog.

Git提供了一种机制,可以不断更新提交,直到完美为止:使用git commit --amend重新制作(重新记录)代码更改。以这种方式更新提交后,您的分支将指向新的提交。但是,旧的(不完美的)修订版本并没有丢失。可以通过git reflog找到它。
(问题在于: git reflog 里记录的东西, 在 git remote 上不会永远存在。。)

代码审查 (Code review)

At least two well-known open source projects insist on these practices:

至少有两个知名的开源项目坚持这些做法:

  • Git
  • Linux Kernel

However, contributors to these projects don’t refine and polish their changes in private until they’re perfect. Instead, polishing code is part of a review process — the contributor offers their change to the project for other developers to evaluate and critique. This process is called code review and results in numerous benefits:

然而,这些项目的贡献者并不会在私下里完善和润色他们的改动直到完美为止。相反,润色代码是审查过程的一部分 - 贡献者将他们的改动提交给项目,供其他开发人员评估和批评。这个过程被称为代码审查,带来了许多好处:

Code reviews mean that every change effectively has shared authorship

代码审查意味着每一次变更都有共同的作者。 (code review 意味着多个人共同完成了最终的代码)

Developers share knowledge in two directions: Reviewers learn from the patch author how the new code they will have to maintain works, and the patch author learns from reviewers about best practices used in the project.

开发人员在两个方向上分享知识:审阅者从补丁作者那里学习新代码的工作原理,而补丁作者则从审阅者那里了解项目中使用的最佳实践。
(有两个角色: 提交补丁的人, 以及审核代码的人。 相互学习。)

Code review encourages more people to read the code contained in a given change. As a result, there are more opportunities to find bugs and suggest improvements.

代码审查鼓励更多的人阅读特定更改中包含的代码。因此,有更多的机会发现错误并提出改进建议。
(code review 鼓励的是: 在一次代码修改中, 让更多人的阅读修改的代码, 是的更容易发现 bug 和改进的地方。 然而, 对方万一发现了也不肯说呢? 万一 Team Leader 不肯开放代码权限, 只让单个人和 Team Leader 本人有权看代码, 其他人就算水平很高也不能参与进来呢?)

The more people who read the code, the more bugs can be identified. Since code review occurs before code is submitted, bugs are squashed during the earliest stage of the software development lifecycle.

阅读代码的人越多,就能发现更多的bug。由于代码审查发生在代码提交之前,因此在软件开发生命周期的最早阶段就能消除bug。
(好嘛, 越多的人读代码就约可能发现问题, 那么干脆开源算了, 完全开源是最好的。 真的么?)

The review process provides a mechanism to enforce team and company policies. For example, all tests shall pass on all platforms or at least two people shall sign off on code in production.

审查流程提供了执行团队和公司政策的机制。例如,所有测试都必须在所有平台上通过,或者至少有两个人必须签署生产代码。
(搞得很严格: code review 是说, 代码要在所有平台上通过所有单元测试, 至少有两个人必须同意才能合并代码)

Many successful software companies, including Google, use code review as a standard, integral stage in the software development process.

许多成功的软件公司,包括谷歌在内,都将代码审查作为软件开发过程中的标准和重要阶段。
(成功的软件公司, 确实是看重 Code Review 的)

基于 Web 的代码审查 (Web-based code review)

To review work, the Git and Linux Kernel projects send patches via email.

Git 和 Linux 的代码, 通过邮件发送

Code Review (Gerrit) adds a modern web interface to this workflow. Rather than send patches and comments via email, Gerrit users push commits to Gerrit where diffs are displayed on a web page. Reviewers can post comments directly on the diff. If a change must be reworked, users can push a new, amended revision of the same change. Reviewers can then check if the new revision addresses the original concerns. If not, the process is repeated.

代码审查(Gerrit)为这个工作流程添加了现代的网页界面。与通过电子邮件发送补丁和评论不同,Gerrit 用户将提交推送到 Gerrit,在那里差异显示在一个网页上。审阅者可以直接在差异上发表评论。如果需要重新修改,用户可以推送同一更改的新修订版本。审阅者随后可以检查新版本是否解决了最初的问题。如果没有,就重复这个过程。
(Git 和 Linux kernel 真的太老派了; 咱 Gerrit 很先进的 – 在网页上显示代码差异, 你在差异的代码上可以评论。 提交后的修改, 被review后,或者自己发现了bug,可以继续增量式的提交修改)

格里特的魔法 (Gerrit’s magic)

When you push a change to Gerrit, how does Gerrit detect that the commit amends a previous change? Gerrit can’t use the SHA-1, since that value changes when git commit --amend is called. Fortunately, upon amending a commit, the commit message is retained by default.

当您向Gerrit推送更改时,Gerrit如何检测提交是否修改了先前的更改?Gerrit无法使用SHA-1,因为当调用git commit --amend时,该值会发生变化。幸运的是,在修改提交时,默认情况下会保留提交消息。

This is where Gerrit’s solution lies: Gerrit identifies a conceptual change with a footer in the commit message. Each commit message footer contains a Change-Id message hook, which uniquely identifies a change across all its drafts. For example:

这就是Gerrit的解决方案所在:Gerrit在提交消息的页脚中标识了一个概念性的变化。每个提交消息的页脚都包含一个Change-Id消息挂钩,它可以唯一地标识所有草稿中的变化。例如:

Change-Id: I9e29f5469142cc7fce9e90b0b09f5d2186ff0990

Thus, if the Change-Id remains the same as commits are amended, Gerrit detects that each new version refers to the same conceptual change. The Gerrit web interface groups versions so that reviewers can see how your change evolves during the code review.

因此,如果 Change-Id 在提交修订时保持不变,Gerrit 会检测到每个新版本指的是同一个概念性变更。Gerrit 网页界面会将各个版本分组,以便审阅者可以看到您的变更在代码审查过程中是如何演变的。

To Gerrit, the identifier can be random.

对于Gerrit来说,标识符可以是随机的。

Gerrit provides a client-side message hook to automatically add to commit messages when necessary.

Gerrit提供了一个客户端消息挂钩,可以在必要时自动添加到提交消息中。

个人总结

  • Gerrit 是一个 code review 的系统
  • gerrit 和 git 无缝连接
  • gerrit 在网页上显示提交的代码修改,并且可以在修改的地方添加评论
  • 对于多次代码修改, git 本身是支持 git commit --ammend 的, 不过这会导致 SHA-1 的变更
  • gerrit 的解决方案是, 绑定一个 Change-Id 到 commit message, 虽然 SHA-1 变了, 但是 Change-Id 不变, 就能维持

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/667891.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

新版MQL语言程序设计:外观模式的原理、应用及代码实现

文章目录 一、什么是外观模式二、外观模式的实现原理三、外观模式的应用范围四、外观模式应用实例银行系统的设计量化交易系统的设计 五、外观模式的代码实现 一、什么是外观模式 外观模式(Facade Pattern)是一种结构型设计模式,它提供了一个…

parameter ‘MAX_BYTE‘ used as named parameter override, is a localparam

在驱动模块里把常量定义的 localparam, 然后在顶层文件里面做了修改报错。改成parameter解决 1. localparam在模块内部使用且不能实例化,parameter才可以在实例化的时候修改参数 2. 常量如果在顶层模块和其他模块的值不一样,会使用顶层模块里面的值…

机器学习中的有监督学习和无监督学习

有监督学习 简单来说,就是人教会计算机学会做一件事。 给算法一个数据集,其中数据集中包含了正确答案,根据这个数据集,可以对额外的数据希望得到一个正确判断(详见下面的例子) 回归问题 例如现在有一个…

[SWPUCTF 2021 新生赛]easyupload1.0

发现是上传文件第一想到是文件木马 <?php eval ($_POST[123]);?>木马上传burp修改后缀发现flag里面这个是假的 我们猜想是在phpinfo我们上传<?php eval(phpinfo(););?>木马上传burp修改后缀里面 CtrlF 发现flag

AI智能电销机器人有哪方面的技术优势?

随着科学技术的发展&#xff0c;人工智能逐渐进入了公众的视野&#xff0c;与人工智能相关的智能产品&#xff0c;也从工业革命的诞生开始在生活中不断涌现&#xff0c;虽然说人类没有被机器所取代&#xff0c;但在之后的人工智能时代&#xff0c;人类真的会被取代吗&#xff1…

Linux文件编译

一、GCC编译 我们都知道想要实现一个程序首先需要写好代码让其能运行起来&#xff0c;那么写出来的.c文件是如何被编译出来的呢&#xff1f; 1.直接编译 首先将程序直接编译为可执行文件可以通过Linux中的GCC编译器。 GCC&#xff08;是一套广泛使用的编译器工具集&#xff…

读论文:DiffBIR: Towards Blind Image Restoration with Generative Diffusion Prior

DiffBIR 发表于2023年的ICCV&#xff0c;是一种基于生成扩散先验的盲图像恢复模型。它通过两个阶段的处理来去除图像的退化&#xff0c;并细化图像的细节。DiffBIR 的优势在于提供高质量的图像恢复结果&#xff0c;并且具有灵活的参数设置&#xff0c;可以在保真度和质量之间进…

[office] sumifs函数和sump #媒体#学习roduct哪个运算更快--Excel函数 #职场发展#媒体

sumifs函数和sumproduct哪个运算更快?-Excel函数 今天&#xff0c;我了解到Excel报表需求看起来像这样&#xff1a; Excel数据库中将维护大约150,000行数据。会有数十个报告&#xff0c;每个报告都有数百种不同的过滤器设置。&#xff08;不同的产品&#xff0c;部门等&…

解决The Tomcat connector configured to listen on port 8080 failed to start

问题 启动javar报错&#xff0c;提示如下 Description: The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured. Action: Verify the connector’s configuration, identify a…

【论文笔记】Lift-Attend-Splat: Bird’s-eye-view camera-lidar fusion using transformers

原文链接&#xff1a;https://arxiv.org/abs/2312.14919 1. 引言 多模态融合时&#xff0c;由于不同模态有不同的过拟合和泛化能力&#xff0c;联合训练不同模态可能会导致弱模态的不充分利用&#xff0c;甚至会导致比单一模态方法性能更低。 目前的相机-激光雷达融合方法多基…

【JMeter】使用技巧

在这此对新版本jmeter的学习温习的过程&#xff0c;发现了一些以前不知道的功能&#xff0c;所以&#xff0c;整理出来与大分享。本文内容如下。 如何使用英文界面的jmeter如何使用镜像服务器Jmeter分布式测试启动Debug 日志记录搜索功能线程之间传递变量 如何使用英文界面的…

Vite 的全景:颠覆前端开发的新潮流

Vite 的全景:颠覆前端开发的新潮流 1. 简介 在现代前端开发领域,Vite已经成为一种引人注目的选择。Vite是一种快速、简单、可扩展的构建工具,为前端开发者提供了高效的开发体验。让我们一起深入了解这个令人兴奋的技术。 1.1 定义和概述 Vite是一个基于Vue.js的构建工具…

YOLO部署实战(5):NVIDIA Jetson Tx2部署YOLO

1 一些概念 Jetson Tx2 NVIDIA Jetson 是NVIDIA为新一代自主机器设计的的嵌入式系统&#xff0c;是一个AI平台&#xff0c;它的优势就是可以覆盖不同领域、不同行业。目前Jetson产品线已经有四个产品系列&#xff0c;包括Jetson Nano、Jetson TX2、Xavier NX和AGX Xavier。四…

MySQL温故篇(一)SQL语句基础

一、SQL语句基础 1、SQL语言分类 DDL&#xff1a;数据定义语言 DCL&#xff1a;数据控制语言 DML&#xff1a;数据操作语言 DQL&#xff1a;数据的查询语言 2、数据类型 3、字符类型 char(11) &#xff1a; 定长 的字符串类型,在存储字符串时&#xff0c;最大字符长度11个&a…

【HarmonyOS应用开发】HTTP数据请求(十四)

文章末尾含相关内容源代码 一、概述 日常生活中我们使用应用程序看新闻、发送消息等&#xff0c;都需要连接到互联网&#xff0c;从服务端获取数据。例如&#xff0c;新闻应用可以从新闻服务器中获取最新的热点新闻&#xff0c;从而给用户打造更加丰富、更加实用的体验。 那么…

【分享】我的调试nRF2401时的一些心得

无线传输,好处很多.记得调试的第一块数传模块是nRF2401.那时我在做个小项目&#xff08;液位自动控制装置&#xff09;的时候&#xff0c;用到这对nRF2401.下面就说下调试nRF2401的调试过程遇到的问题。 MSP430F149&#xff08;两块&#xff09; nRF2401(一对)4*4键盘&#xf…

计算机网络——03网络核心

网络核心 网络核心 网络核心&#xff1a;路由器的网络状态基本问题&#xff1a;数据怎样通过网络进行传输 电路交换&#xff1a;为每个呼叫预留一条专有电路分组交换 将要传送的数据分成一个个单位&#xff1a;分组将分组从一个路由器传到相邻路由器&#xff08;hop&#xff…

101 C++内存高级话题 内存池概念,代码实现和详细分析

零 为什么要用内存池&#xff1f; 从前面的知识我们知道&#xff0c;当new 或者 malloc 的时候&#xff0c;假设您想要malloc 10个字节&#xff0c; char * pchar new char[10]; char *pchar1 malloc(10); 实际上编译器为了 记录和管理这些数据&#xff0c;做了不少事情&…

01-Datahub是什么?

Datahub是LinkedIn开源的基于现代数据栈的元数据管理平台&#xff0c;原来叫做WhereHows 。经过一段时间的发展datahub于2020年2月在Github开源。 官网地址为&#xff1a;A Metadata Platform for the Modern Data Stack | DataHub 源码地址为&#xff1a;GitHub - datahub-p…

easyexcel解析跨多行的数据

在使用easyexcel计息excel文件的时候&#xff0c;存在某列横跨多行&#xff0c;这是要怎么解决呢&#xff1f;代码如下 定义实体对应excel文件 public class EtcParkingReconciliationDailyImportModel implements Serializable {/** 创建时间 */private String insertTime L…