python:mercurial

文書の過去の版を表示しています。


Mercurial - 分散型バージョン管理システム

本家: Mercurial SCM

ここでは Python と pip の導入が完了していることを前提とする。

Python のインストール
easy_install、setuptools、pip - パッケージ管理

CentOS の場合は gcc と python-devel をインストールしておく。

$ sudo yum install gcc python-devel

pip によるインストール。

$ sudo pip install mercurial
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting mercurial
  Downloading https://files.pythonhosted.org/packages/79/54/ccc37f1f55b91d48ed1de38ffbb81e32697dc69accea017c8faad21360bf/mercurial-5.3.2.tar.gz (7.5MB)
     |████████████████████████████████| 7.5MB 1.2MB/s
Installing collected packages: mercurial
  Running setup.py install for mercurial ... done
Successfully installed mercurial-5.3.2

DietPi

$ sudo pip install mercurial

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple/
Collecting mercurial
  Downloading https://www.piwheels.org/simple/mercurial/mercurial-6.2.1-cp39-cp39-linux_armv6l.whl (6.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 693.1 kB/s eta 0:00:00
Installing collected packages: mercurial
Successfully installed mercurial-6.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

$ which hg

/usr/local/bin/hg

$ hg version

Mercurial Distributed SCM (version 6.2.1)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2022 Olivia Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

dnf によるインストール。

$ sudo dnf install mercurial-py3
Last metadata expiration check: 0:14:18 ago on 2021年05月09日 03時46分00秒.
Dependencies resolved.
====================================================================================================
 Package                    Architecture       Version                    Repository           Size
====================================================================================================
Installing:
 mercurial-py3              x86_64             5.4.2-3.fc33               updates             4.0 M
Installing dependencies:
 mercurial-lang             x86_64             5.4.2-3.fc33               updates             1.0 M

Transaction Summary
====================================================================================================
Install  2 Packages

Total download size: 5.0 M
Installed size: 24 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): mercurial-lang-5.4.2-3.fc33.x86_64.rpm                       189 kB/s | 1.0 MB     00:05
(2/2): mercurial-py3-5.4.2-3.fc33.x86_64.rpm                        237 kB/s | 4.0 MB     00:17
----------------------------------------------------------------------------------------------------
Total                                                               261 kB/s | 5.0 MB     00:19
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                            1/1
  Installing       : mercurial-lang-5.4.2-3.fc33.x86_64                                         1/2
  Installing       : mercurial-py3-5.4.2-3.fc33.x86_64                                          2/2
  Running scriptlet: mercurial-py3-5.4.2-3.fc33.x86_64                                          2/2
  Verifying        : mercurial-lang-5.4.2-3.fc33.x86_64                                         1/2
  Verifying        : mercurial-py3-5.4.2-3.fc33.x86_64                                          2/2

Installed:
  mercurial-lang-5.4.2-3.fc33.x86_64                mercurial-py3-5.4.2-3.fc33.x86_64

Complete!
$ hg version
Mercurial Distributed SCM (version 5.4.2)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2020 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ hg config --edit

もしくは

$ vi ~/.hgrc
~/.hgrc
[ui]
username = Tomoyan <tomoyan@example.com>

hg コマンドのデフォルトエディタは EDITOR 変数が設定されていない限りは vi である。
nano に変更する場合は以下のように実行する。

$ EDITOR=nano hg config --edit

もしくは、.bashrc に設定を保存する。

$ echo 'export EDITOR=nano' >> ~/.bashrc
$ . ~/.bashrc

既存のディレクトリでリポジトリを作成する。

$ mkdir repos
$ cd repos
$ hg init

新たにリポジトリのディレクトリを作成する。

$ hg init repos
$ vi .hgignore
.hgignore
# Shell 形式パターンマッチ
syntax: glob
 
*.pyc
.hgignore
# 正規表現パターンマッチ
syntax: regexp
 
^\.git/
$ hg add file.txt
$ hg status
A file.txt
$ hg commit
$ hg diff
$ hg revert file.txt
$ hg rollback
$ hg log

ssh経由でリモートリポジトリをローカルに複製する。

$ hg clone ssh://user@server:port//var/hg/hoge/fuga my-fuga
$ hg pull
$ hg update

作業領域の変更を破棄する場合

$ hg update -C
$ hg push ssh://user@server:port//var/hg/hoge/fuga

※push 先にリポジトリが存在している必要がある。存在しない場合は作成しておくこと。

$ ssh user@server -p22 hg init /var/hg/hoge/fuga

.hg/hgrc に以下の記載があるなら省略できる。

[paths]
default = ssh://user@server:port//var/hg/hoge/fuga
$ hg push

サーバーでリポジトリを作成する場合。
クライアントからサーバーへクローンすることもできるが…

$ hg init fuga
$ hg clone . ssh://user@server:port//var/hg/hoge/fuga

convert エクステンションを有効化する。

$ vi ~/.hgrc
~/.hgrc
[extensions]
convert =

git を Mercurial へ変換

$ hg convert [repository] [new-repository]
変換先リポジトリ new-repository の初期化中
変換元リポジトリの走査中...
並べ替え中...
変換中...
9625 Initial structure
〜省略〜
$ cd new-repository
$ hg update

hg convert で svn を Mercurial に変換する。

$ hg convert _wxHexEditor-v0.23-src_svn _wxHexEditor-v0.23-src_hg
変換先リポジトリ _wxHexEditor-v0.23-src_hg の初期化中
変換元リポジトリの走査中...
並べ替え中...
変換中...
$ cd _wxHexEditor-v0.23-src_hg
$ hg update

Subversion のリポジトリがリモートにしかない場合

git-svn を使って svn を一度 git に変換する。

$ sudo dnf install git-svn
$ git svn clone https://svn.code.sf.net/p/wxhexeditor/code/trunk wxHexEditor-v0.23-src_git
Initialized empty Git repository in /home/tomoyan/wxHexEditor-v0.23-src_git/.git/
	A	testfile
	A	HexEditorCtrl/wx_pch.h
	A	HexEditorCtrl/HexEditorCtrl.cpp
〜省略〜
W: -empty_dir: contrib/wxhexeditor_0.22-1.dsc
r464 = 9d76f35dbaf4053a5b90771b65147d5a940f0fca (refs/remotes/git-svn)
Checked out HEAD:
  https://svn.code.sf.net/p/wxhexeditor/code/trunk r464
creating empty directory: mhash/mhash-0.9.9/lib

hg convert で git を Mercurial に変換する。

$ hg convert wxHexEditor-v0.23-src_git wxHexEditor-v0.23-src_hg
変換先リポジトリ wxHexEditor-v0.23-src_hg の初期化中
変換元リポジトリの走査中...
並べ替え中...
変換中...
435 Reset svn
434 DataInterpreter Added.
433 DataInterpreter big endian and unsigned swithces fixed.
〜省略〜
2 Last touches for wxMSW.                                                                           
1 Fixed assertions due ~wxHexCtrl() cleanup code.                                                   
0 Updated to v0.23                                                                                  
ブックマークの更新中
$ cd wxHexEditor-v0.23-src_hg
$ hg update

hgrc の所有者やグループが自分ではない時に発生する。
表示される所有者やグループが本当に信頼できるものであれば、~/.hgrc に以下の記述を追加する。

$ vi ~/.hgrc
~/.hgrc
[trusted]
users = root
groups = root

日本語では、gcc: エラー: /usr/lib/rpm/redhat/redhat-hardened-cc1: そのようなファイルやディレクトリはありません
英語では、g++: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory が発生する。

redhat-rpm-config パッケージをインストールしてから行う。

$ sudo dnf install redhat-rpm-config
  • python/mercurial.1661979986.txt.gz
  • 最終更新: 2022/09/01 06:06
  • by ともやん