====== Mercurial - 分散型バージョン管理システム ====== 本家: [[https://www.mercurial-scm.org/|Mercurial SCM]]\\ 関連: [[linux:tortoisehg|TortoiseHg - Mercurial 分散型バージョン管理システム用ツール]]\\ ===== 前提条件 ===== ここでは Python と pip の導入が完了していることを前提とする。\\ [[python:python_install|Python のインストール]]\\ [[python:easy_install|easy_install、setuptools、pip - パッケージ管理]]\\ Fedora の場合は gcc と python-devel をインストールしておく。
$ sudo yum install gcc python-devel
===== インストール ===== **pip** によるインストール。\\
$ pip install --user mercurial
Collecting mercurial
  Downloading mercurial-6.6.3.tar.gz (8.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.3/8.3 MB 846.3 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mercurial
  Building wheel for mercurial (pyproject.toml) ... done
  Created wheel for mercurial: filename=mercurial-6.6.3-cp312-cp312-linux_x86_64.whl size=4743353 sha256=a592c0a7feb366d2f05ce876e9ca095602dee4e3944359c46678136601ca6cd3
  Stored in directory: /home/tomoyan/.cache/pip/wheels/57/df/cd/77d5eb43b732c34dfdd051d941d9f361391f4160b799994b7c
Successfully built mercurial
Installing collected packages: mercurial
Successfully installed mercurial-6.6.3
**DietPi**\\
$ pip install --user  mercurial
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple/
Collecting mercurial
  Downloading https://www.piwheels.org/simple/mercurial/mercurial-6.6.3-cp311-cp311-linux_armv6l.whl (6.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.2/6.2 MB 239.6 kB/s eta 0:00:00
Installing collected packages: mercurial
Successfully installed mercurial-6.6.3
$ which hg
/home/dietpi/.local/bin/hg
**dnf** によるインストール。\\
$ sudo dnf install -y mercurial
メタデータの期限切れの最終確認: 2:21:11 前の 2024年02月27日 03時39分09秒 に実施しました。
依存関係が解決しました。
==============================================================================================================
 パッケージ                       アーキテクチャー     バージョン                 リポジトリー          サイズ
==============================================================================================================
インストール:
 mercurial                        x86_64               6.5.3-1.fc39               updates               6.4 M
依存関係のインストール:
 python3-zombie-imp               noarch               0.0.2-2.fc39               fedora                 29 k

トランザクションの概要
==============================================================================================================
インストール  2 パッケージ

ダウンロードサイズの合計: 6.5 M
インストール後のサイズ: 31 M
パッケージのダウンロード:
(1/2): python3-zombie-imp-0.0.2-2.fc39.noarch.rpm                             108 kB/s |  29 kB     00:00    
(2/2): mercurial-6.5.3-1.fc39.x86_64.rpm                                      1.8 MB/s | 6.4 MB     00:03    
--------------------------------------------------------------------------------------------------------------
合計                                                                          1.3 MB/s | 6.5 MB     00:04     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                      1/1 
  インストール中   : python3-zombie-imp-0.0.2-2.fc39.noarch                                               1/2 
  インストール中   : mercurial-6.5.3-1.fc39.x86_64                                                        2/2 
  scriptletの実行中: mercurial-6.5.3-1.fc39.x86_64                                                        2/2 
  検証             : python3-zombie-imp-0.0.2-2.fc39.noarch                                               1/2 
  検証             : mercurial-6.5.3-1.fc39.x86_64                                                        2/2 

インストール済み:
  mercurial-6.5.3-1.fc39.x86_64                     python3-zombie-imp-0.0.2-2.fc39.noarch                    

完了しました!
===== 動作確認 =====
$ hg version
Mercurial - 分散構成管理ツール(バージョン 6.6.3)
(詳細は https://mercurial-scm.org を参照)

Copyright (C) 2005-2023 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.
===== 使い方 ===== ==== 初期設定 ====
$ hg config --edit
もしくは\\
$ EDITOR=nano hg config --edit
もしくは\\
$ nano ~/.hgrc
※**hg** コマンドのデフォルトエディタは **EDITOR** 変数が設定されていない限りは **vi** である。\\ 永続的に **nano** に変更する場合は、以下のように設定を保存する。\\ **zsh**\\
$ echo 'export EDITOR=nano' >> ~/.zshrc
$ . ~/.zshrc
**Bash**\\
$ echo 'export EDITOR=nano' >> ~/.bashrc
$ . ~/.bashrc
Mercurial のユーザー名を設定する🤔\\
$ hg config --edit
[ui] username = Tomoyan
==== リポジトリの作成 ==== 既存のディレクトリでリポジトリを作成する。
$ mkdir repos && cd repos
$ hg init
新たにリポジトリのディレクトリを作成する。
$ hg init repos
==== ソース管理から除外するファイルの設定 ====
$ nano .hgignore
# Shell 形式パターンマッチ syntax: glob *.pyc # 正規表現パターンマッチ 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
==== git を Mercurial へリポジトリ変換 ==== convert エクステンションを有効化する。\\
$ nano ~/.hgrc
[extensions] convert =
git を Mercurial へ変換\\
$ hg convert [repository] [new-repository]
変換先リポジトリ new-repository の初期化中
変換元リポジトリの走査中...
並べ替え中...
変換中...
9625 Initial structure
〜省略〜
$ cd new-repository
$ hg update
==== Subversion のリポジトリ を Mercurial へリポジトリ変換 ==== 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
===== トラブルシューティング ===== ===== 信頼できないファイル .hg/hgrc (所有者 root, グループ root)と言われる ===== hgrc の所有者やグループが自分ではない時に発生する。\\ 表示される所有者やグループが本当に信頼できるものであれば、~/.hgrc に以下の記述を追加する。\\
$ nano ~/.hgrc
[trusted] users = root groups = root
==== インストール時に「gcc: エラー」が発生する ==== 日本語では、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
===== 参考文献 ===== [[http://mercurial.selenic.com/wiki/JapaneseTutorial|JapaneseTutorial - Mercurial]]\\ [[http://www.proton.jp/main/programming/mercurial.html|【Proton.jp】 Mercurial Tips]]\\ [[http://route477.net/w/?MercurialTutorial|Route 477 - Mercurialを使ってみよう]]\\ [[http://mercurial-users.jp/manual/hgignore.5.html|hgignore]]\\ [[https://ask.fedoraproject.org/en/question/61075/mysql_config-cflags-does-not-work-on-fedora-21/|"mysql_config --cflags" does not work on fedora 21]]\\ [[https://swcarpentry.github.io/hg-novice/02-configuration/|Version Control with Mercurial: Configuring Mercurial]]\\