每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


今日推荐开源项目:《超级备忘录——Awesome-Cheatsheets

推荐理由:你可以把Awesome-Cheatsheets看作是一个备忘录,其实它的作用与备忘录很相似,但它又不止是一个备忘录,姑且叫“超级备忘录”好了!

开源周报2018年第7期:为你写诗,为你无所不知

这是一个存储了现在流行的编程语言,框架和开发工具的使用技巧和知识的地方,记录的许多人在使用一些语言,框架和工具的途中积累下来的知识于技巧,比如JavaScript,Bash, Node.js等。

Awesome-Cheatsheets就是这样一个工具。我们在学习一门新技巧,新语言时,许多人都会选择做一个Cheatsheets,随着时间的积累,我们积累的东西也会越来越多,Awesome-Cheatshoots系统的存储记录了这些零碎的知识。使用它将会是一个不错的体验。

Awesome-Cheatsheets现在还在继续完善中,不断收集在学习各种语言,框架,工具的知识,我想它一定会满足我们对知识的需求。


今日推荐英文原文:《Introducing Git protocol version 2》作者:Brandon Williams, Git Core Team

原文链接:https://opensource.googleblog.com/2018/05/introducing-git-protocol-version-2.html

推荐理由:Google 正式在其官方 Blog 宣布 Git protocal version 2,这个版本最主要的变化是客户端与服务器端一些 clone、fetch、push等一些操作的协议。

Introducing Git protocol version 2

Today we announce Git protocol version 2, a major update of Git’s wire protocol (how clones, fetches and pushes are communicated between clients and servers). This update removes one of the most inefficient parts of the Git protocol and fixes an extensibility bottleneck, unblocking the path to more wire protocol improvements in the future.

The protocol version 2 spec can be found here. The main improvements are:

The main motivation for the new protocol was to enable server side filtering of references (branches and tags). Prior to protocol v2, servers responded to all fetch commands with an initial reference advertisement, listing all references in the repository. This complete listing is sent even when a client only cares about updating a single branch, e.g.: git fetch origin master. For repositories that contain 100s of thousands of references (the Chromium repository has over 500k branches and tags) the server could end up sending 10s of megabytes of data that get ignored. This typically dominates both time and bandwidth during a fetch, especially when you are updating a branch that’s only a few commits behind the remote, or even when you are only checking if you are up-to-date, resulting in a no-op fetch.

We recently rolled out support for protocol version 2 at Google and have seen a performance improvement of 3x for no-op fetches of a single branch on repositories containing 500k references. Protocol v2 has also enabled a reduction of 8x of the overhead bytes (non-packfile) sent from googlesource.com servers. A majority of this improvement is due to filtering references advertised by the server to the refs the client has expressed interest in.

Getting over the hurdles

The Git project has tried on a number of occasions over the years to either limit the initial ref advertisement or move to a new protocol altogether but continued to run into two problems: (1) the initial request is rigid and does not include a field that could be used to request that new servers modify their response without breaking compatibility with existing servers and (2) error handling is not well enough defined to allow safely using a new protocol that existing servers do not understand with a quick fallback to the old protocol. To migrate to a new protocol version, we needed to find a side channel which existing servers would ignore but could be used to safely communicate with newer servers.

There are three main transports that are used to speak Git’s wire-protocol (git://, ssh://, and https://), and the side channel that we use to request v2 needs to communicate in such a way that an older server would ignore any additional data sent and not crash. The http transport was the easiest as we can simply include an additional http header in the request (“Git-Protocol: version=2”). The ssh transport is a bit more difficult as it requires sending an environment variable (“GIT_PROTOCOL=version=2”) to be set on the remote end. This is more challenging because it requires server administrators to configure sshd to accept the new environment variable on their server. The most difficult transport is the anonymous Git transport (git://).

Initial requests made to a server using the anonymous Git transport are made in the form of a single packet-line which includes the requested service (git-upload-pack for fetches and git-receive-pack for pushes), and the repository followed by a NUL byte. Later virtualization support was added and a hostname parameter could be tacked on and  terminated by a NUL byte: 0033git-upload-pack /project.git\0host=myserver.com\0. Ideally we’d be able to add a new parameter to be used to request v2 by adding it in the same manner as the hostname was added: 003dgit-upload-pack /project.git\0host=myserver.com\0version=2\0. Unfortunately due to a bug introduced in 2006 we aren’t able to place any extra arguments (separated by NULs) other than the host because otherwise the parsing of those arguments would enter an infinite loop. When this bug was fixed in 2009, a check was put in place to disallow extra arguments so that new clients wouldn’t trigger this bug in older servers.

Fortunately, that check doesn’t notice if we send additional request arguments hidden behind a second NUL byte, which was pointed out back in 2009.  This allows requests structured like: 003egit-upload-pack /project.git\0host=myserver.com\0\0version=2\0. By placing version information behind a second NUL byte we can skirt around both the infinite loop bug and the explicit disallowal of extra arguments besides hostname. Only newer servers will know to look for additional information hidden behind two NUL bytes and older servers won’t croak.

Now, in every case, a client can issue a request to use v2, using a transport-specific side channel, and v2 servers can respond using the new protocol while older servers will ignore the side channel and just respond with a ref advertisement.

Try it for yourself

To try out protocol version 2 for yourself you’ll need an up to date version of Git (support for v2 was recently merged to Git’s master branch and is expected to be part of Git 2.18) and a v2 enabled server (repositories on googlesource.com and Cloud Source Repositories are v2 enabled). If you enable tracing and run the ls-remote command querying for a single branch, you can see the server sends a much smaller set of references when using protocol version 2:

# Using the original wire protocol

GIT_TRACE_PACKET=1 git -c protocol.version=0 ls-remote https://chromium.googlesource.com/chromium/src.git master

# Using protocol version 2

GIT_TRACE_PACKET=1 git -c protocol.version=2 ls-remote https://chromium.googlesource.com/chromium/src.git master


每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;电报群 https://t.me/OpeningSourceOrg