Linux中國

Mercurial 版本控制入門

Mercurial 是一個用 Python 編寫的分散式版本控制系統。因為它是用高級語言編寫的,所以你可以用 Python 函數編寫一個 Mercurial 擴展。

官方文檔中說明了幾種安裝 Mercurial 的方法。我最喜歡的一種方法不在裡面:使用 pip。這是開發本地擴展的最合適方式!

目前,Mercurial 僅支持 Python 2.7,因此你需要創建一個 Python 2.7 虛擬環境:

python2 -m virtualenv mercurial-env
./mercurial-env/bin/pip install mercurial

為了讓命令簡短一些,以及滿足人們對化學幽默的渴望,該命令稱之為 hg

$ source mercurial-env/bin/activate
(mercurial-env)$ mkdir test-dir
(mercurial-env)$ cd test-dir
(mercurial-env)$ hg init
(mercurial-env)$ hg status
(mercurial-env)$

由於還沒有任何文件,因此狀態為空。添加幾個文件:

(mercurial-env)$ echo 1 > one
(mercurial-env)$ echo 2 > two
(mercurial-env)$ hg status
? one
? two
(mercurial-env)$ hg addremove
adding one
adding two
(mercurial-env)$ hg commit -m 'Adding stuff'
(mercurial-env)$ hg log
changeset: 0:1f1befb5d1e9
tag: tip
user: Moshe Zadka <[moshez@zadka.club][4]>
date: Fri Mar 29 12:42:43 2019 -0700
summary: Adding stuff

addremove 命令很有用:它將任何未被忽略的新文件添加到託管文件列表中,並移除任何已刪除的文件。

如我所說,Mercurial 擴展用 Python 寫成,它們只是常規的 Python 模塊。

這是一個簡短的 Mercurial 擴展示例:

from mercurial import registrar
from mercurial.i18n import _

cmdtable = {}
command = registrar.command(cmdtable)

@command(&apos;say-hello&apos;,
[(&apos;w&apos;, &apos;whom&apos;, &apos;&apos;, _(&apos;Whom to greet&apos;))])
def say_hello(ui, repo, `opts):
ui.write("hello ", opts[&apos;whom&apos;], "n")

簡單的測試方法是將它手動加入虛擬環境中的文件中:

`$ vi ../mercurial-env/lib/python2.7/site-packages/hello_ext.py`

然後你需要啟用擴展。你可以僅在當前倉庫中啟用它:

$ cat >> .hg/hgrc
[extensions]
hello_ext =

現在,問候有了:

(mercurial-env)$ hg say-hello --whom world
hello world

大多數擴展會做更多有用的東西,甚至可能與 Mercurial 有關。 repo 對象是 mercurial.hg.repository 的對象。

有關 Mercurial API 的更多信息,請參閱官方文檔。並訪問官方倉庫獲取更多示例和靈感。

via: https://opensource.com/article/19/4/getting-started-mercurial

作者:Moshe Zadka 選題:lujun9972 譯者:geekpi 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的郵箱地址不會被公開。 必填項已用 * 標註

    這個站點使用 Akismet 來減少垃圾評論。了解你的評論數據如何被處理

    More in:Linux中國

    Linux中國

    捐贈 Let&apos;s Encrypt,共建安全的互聯網

    隨著 Mozilla、蘋果和谷歌對沃通和 StartCom 這兩家 CA 公司處罰落定,很多使用這兩家 CA 所簽發證書的網站紛紛尋求新的證書籤發商。有一個非盈利組織可以為大家提供了免費、可靠和安全的 SSL 證書服務,這就是 Let's Encrypt 項目。現在,它需要您的幫助
    Linux中國

    關於Linux防火牆iptables的面試問答

    Nishita Agarwal是Tecmint的用戶,她將分享關於她剛剛經歷的一家公司(印度的一家私人公司Pune)的面試經驗。在面試中她被問及許多不同的問題,但她是iptables方面的專家,因此她想分享這些關於iptables的問題和相應的答案給那些以後可能會進行相關面試的人。 所有的問題和相應的答案都基於Nishita Agarwal的記憶並經過了重寫。 嗨,朋友!我叫Nishita Agarwal。我已經取得了理學學士學位,我的專業集中在UNIX和它的變種(BSD,Linux)。它們一直深深的吸引著我。我在存儲方面有1年多的經驗。我正在尋求職業上的變化,並將供職於印度的P
    Linux中國

    Lets Encrypt 已被所有主流瀏覽器所信任

    旨在讓每個網站都能使用 HTTPS 加密的非贏利組織 Lets Encrypt 已經得了 IdenTrust的交叉簽名,這意味著其證書現在已經可以被所有主流的瀏覽器所信任。從這個裡程碑事件開始,訪問者訪問使用了Lets Encrypt 證書的網站不再需要特別配置就可以得到 HTTPS 安全保護了。 Lets Encrypt 的兩個中級證書 ...