ããããã¸ã§ã¯ãã®Mercurialå°å ¥ã®è»è·¡
ãã®ã¨ã³ããªã¯Mercurial Advent Calendar 2011 - PARTAKEã®25æ¥ç®ã§ãã
3æããMercurialã使ãå§ããã®ã§12æã§9ã¶æç®ã«ãªãã¾ããä¸å¹´ã®æ¯ãè¿ãã¨ããäºã§ãMercurialå°å
¥ã®è»è·¡ã«ã¤ãã¦ç°¡åã«ã¾ã¨ãããã¨æãã¾ãã*1
Mercurialã¨ã®åºä¼ã
Mercurialã¨åºä¼ãåã¯Subversionã¨ã¡ãã£ã¨ã ãGitã触ã£ã¦ãã¾ãããã¨ãã«Subversionã¯ä»äºã§ããªããã£ã¤ããã©ã³ãã®éç¨*2ãè¡ã£ã¦ãã¾ããã
å«ã«ãªãã»ã©Subversionã使ãããã¸ã§ã¯ãã§ã¯æ¬¡ã®åé¡ãçºçãã¦ãã¾ããã
- Subversionã§ã®ãã©ã³ãããã¸ã¡ã³ãã¯ãã¼ã¸æ å½è ã®è² è·ãé«ããã
- ãªãã¸ããªã巨大ã«ãªãããã¦svn stããã ãã§ã20ç§
- ãªãã¸ããªã巨大ã«ãªãããã¦svn upãçµãããªã
- é¨åsvn upãåºã人ãå¢ããæ´åæ§ã«é¢ããã¨ã©ã¼ã«ã¯ã¾ã人ãç¶åº
- svn switchã¯ã¾ã失æãã
- ãªãªã¼ã¹ã¿ã¼ã²ãããåãæ¿ããã«ã¯ãã§ãã¯ã¢ã¦ããå¿ é
- ã§ãsvn coããã ãã§1æé以ä¸
Subversionããã¼ãã«ä½¿ã£ã人ã¯ãã¶ãåãåé¡ã«ã¶ã¡å½ããã®ã§ã¯ç¡ãã§ãããããä¸ã¤ä¸ã¤ã®æä½ã«æéããããããã®é ãã¯æ¬¡ç¬¬ã«éçºã¹ãã¼ããéçºè ã®ã¢ããã¼ã·ã§ã³ã«ãå½±é¿ãã¦ãã¾ãã
ãã®çµæãã¨ã«ããSubversionãã移è¡ããã¨ããã ãã®åæãå¾ã¦ã移è¡å ã¨ãªãåæ£ãã¼ã¸ã§ã³ç®¡çã·ã¹ãã (以ä¸DVCS)ã®æ¤è¨ã«å ¥ãã¾ãã*3ã
çµæãMeruciralãå¯ä¸ç§»è¡ã§ããDVCSã ã¨ããäºãããããæ¬æ ¼çãªç§»è¡ãå§ã¾ãã¾ããã
Mercurialã®å°å ¥
Mercurialã®å°å ¥ã«ã¯å¤§ããä¸ã¤ã®éå£ãããã¾ãããä¸ã¤ç®ã¯ãªãã¸ããªã®ç§»è¡ãäºã¤ç®ã¯ã¡ã³ãã¼ã¸ã®Meruciralã®å±éã§ããä¸ã¤ç®ããããã¤ãã¼ã«ã®å¯¾å¿ã§ãã
ãªãã¸ããªã®ç§»è¡
ãªãã¸ããªå¤æç¨ã®æ¡å¼µConvertExtension - Mercurialãå©ç¨ããäºã«ãã£ã¦ãç°¡åã«SubversionããMercurialã¸å¤æããäºãåºæ¥ã¾ããã
ConvertExtensionã使ãä¸ã§ã®æ³¨æç¹ã¨ãã¦ã¯ãå±¥æ´ãä¿æãããå ´åã¯å¤æåã«Subversionãªãã¸ããªã®ãã£ã¬ã¯ããªæ§æãå¤æ´ããªãã¨ããäºã§ãããã£ã¬ã¯ããªä»¥ä¸ã®å±¥æ´ãã移è¡åºæ¥ãªãã®ã§ããã£ã¬ã¯ããªæ§æãå¤æ´ãã¦ãã¾ãã¨ããã®å±¥æ´ã失ã£ã¦ãã¾ãã¾ãã
ããã¦ãã®å ´åãç´è¿ã®å±¥æ´ã ãæãã°äºè¶³ããã®ã§ã移è¡æã¯æãåã£ã¦æ¨ã¦ã¦ãã¾ãã¨ããã®ãæã§ããå±¥æ´ãæ¨ã¦ãã¨ãªãã¸ããªã®ãµã¤ãºãå°ãããªãã¨è¨ãå©ç¹ãæãã¾ãã
ã¡ã³ãã¼ã¸ã®Meruciralã®å±é
Mercurialã®ä½¿ãæ¹ãããã人éã«ãªãå¿ è¦ãããã¨è¨ããã¨ã§ãèªåã®åå¼·ãã¦ã次ã®ããã¥ã¡ã³ããä½æãã¾ããã
ãªãã¸ããªãMercurailã«åãæ¿ããåã«ãã¾ããå ¨å¡ã«ãã®ãã¥ã¼ããªã¢ã«*4ãå®æ½ãã¦è²°ãã¾ããããã¨ãã»ã¼å ¨å¡ã«å ¥éMercurialãè²·ã£ã¦è²°ãã¾ããã
ãã®ãã¥ã¼ããªã¢ã«ä»¥å¤ã«æ¬¡ã®ç¹ã«ä»ãã¦ãè¬ç¾©å½¢å¼ã§2ã3ååå¼·ä¼ãéãã¾ããã
- DVCSã®æ¦å¿µ
- ãã©ã³ãã®æ¦å¿µã®éã
ä»ããåãäºãè¡ãå ´åã¯æ¬¡ã®ããã¥ã¡ã³ããå©ç¨åºæ¥ãã¨æãã¾ãã
ãããæåã®Mercurialå°å ¥ã®çºã®æºåã§ããã
ãããã¤ãã¼ã«ã®å¯¾å¿
ãã®ãããã®è©±ã¯ãã¾ã詳ããããã¾ããããããã¾ãããã
Mercurialã®éç¨
Mercurialå°å ¥å¾ããã©ã³ããåããã«Subversionã®æ§ãªéç¨ãåºæ¥ã¾ã*5ãã§ããããã£ããã®Mercurialããã®ãããªéç¨ããã¦ãã¾ã£ããæ¨å³ãåæ¸ãã¦ãã¾ãã¾ãã
ãã©ã³ãæ¦ç¥
次ã®ããã¥ã¡ã³ããåèã«ãããã¸ã§ã¯ãã®éç¨ã«ãããããã©ã³ãæ¦ç¥ãã¨ãã¾ããã
æ¬çªã®ãã¼ã¸ã§ã³ã1ã¤ããæããªãã¢ããªã±ã¼ã·ã§ã³ã ã£ãã®ã§ã次ã®æ§ãªæ¯ã®é·ããã©ã³ããç¨æãã¾ããããA successful Git branching modelãã®developã¨releaseãåä½ãã¦ããããè¤æ°æãéç¨ã ã¨æã£ã¦ãã ããã
- default
- ãªãªã¼ã¹ãã©ã³ãããã®ãã©ã³ãã®å 容ãæ¬çªã«ãªãªã¼ã¹ããããå¤æ´ããã£ãå ´åã¯develop/YYYYMMDDãhotfix/YYYYMMDDã«å¤æ´å 容ããã¼ã¸ãã
- develop/YYYYMMDD
- YYYYMMDDãªãªã¼ã¹ç¨ãã©ã³ããéçº+ãã¹ããè¡ãããªãªã¼ã¹ã¿ã¼ã²ãããè¤æ°æãå ´åã¯è¤æ°ä½æãããdefaultããä½æããdefaultã«ãã¼ã¸ããã
- hotfix/YYYYMMDD
- YYYYMMDDã¡ã³ããã³ã¹ãªãªã¼ã¹ç¨ãã©ã³ããåºæ¬ãã°ä¿®æ£ã®ã¿ãdefaultããä½æããdefaultã«ãã¼ã¸ããã
ãã©ã³ãæ¦è¡
ãbpmercurial-workflow ããã¥ã¡ã³ãããåèã«æ¬¡ã®ã«ã¼ã«ãå®ãã¾ããã
- ã¤ã·ã¥ã¼ãã©ãã«ã¼ã®ã¤ã·ã¥ã¼çªå·æ¯ã«ãã©ã³ããåã
- ã³ããããã°ã«ã¤ã·ã¥ã¼çªå·ãå«ãã
ããã«ããã©ã³ãã®å½åè¦åã¯æ¬¡ã®æ§ã«å®ãã¾ããã
- å
ã®çµ±åãã©ã³ãã®ååãã¤ã·ã¥ã¼æ¯ã®ãã©ã³ãåã«å«ãããã¨
- ä¾: issue/XXXX-{ç°¡åãªèª¬æ}
- ä¾: develop/YYYYMMDD/issue/XXXX-{ç°¡åãªèª¬æ}
- ä¾: hotfix/YYYYMMDD/issue/XXXX-{ç°¡åãªèª¬æ}
ãã®ã«ã¼ã«ã«ãããã¤ã·ã¥ã¼æ¯ã®ãã©ã³ããã©ãã«ãã¼ã¸ã§ããããæ確ã«ãªãã¾ãã(YYYYMMDDãèªåã¨åããèªåãã大ãããã©ã³ãã«ãããã¼ã¸åºæ¥ãªãã§ã)
Mercurialæ¡å¼µã®ä½ç½®ã¥ãã«ã¤ãã¦
ç´¹ä»ãããã©ã³ãæ¦ç¥ããã©ã³ãæ¦è¡ã¯ãMercurialæ¡å¼µãªãã§éç¨åºæ¥ã¾ããããã¯Mercurialã®ã³ãã³ãã©ã¤ã³ä½ç³»ã®ã»ã³ã¹ã®è¯ããç¾ãã¦ããã®ã ã¨èãã¦ãã¾ãã
ãã便å©ã«éç¨ããããã«ã¯Mercurialæ¡å¼µã使ãããªãå¿
è¦ãããã¾ãããã³ãã«ããã¦ããMercurialæ¡å¼µã使ãããªãã ãã§ãéç¨ããéçºè
ä¸äººä¸äººã®æ¦è¡ãå¤ããã¾ãã
éç¨å¾ãã°ããç«ã£ããåå¼·ä¼ãéãã¦è¦ãã¨ããã¨æãã¾ããå®éã«å¼ç¤¾ã§ã¯@yoppiblog ã«ããMercurialæ¡å¼µã®èª¬æä¼*6ãããã¾ããã
rebaseã¯è¡ãã¹ãï¼
1日目ã23日目ã«æ¸ããrebaseã§ããããã®ãã©ã³ãã®éç¨ã§rebaseãã¹ããªã®ã§ããããï¼
åã®ä»ã®ã¨ããã®çµè«ã¯ãrebaseåºæ¥ãæéããããªãããªãã¹ãè¡ãã¹ããã§ããçç±ã¯æ¬¡ã®éãã§ãã
- å±¥æ´ãä¸ç´ç·ã«ãªãã®ã§ãªãã¸ã§ã³ã°ã©ããç®ã§è¦ã¦ããããããã*7
- å±¥æ´ãä¸ç´ç·ã«ãªãã®ã§backoutãããã
ãªãã¹ãã¨ãã¦ããçç±ã¯æ¬¡ã®éãã§ãã
- rebaseæ¹æ³ã«ãã£ã¦ã¯3-way mergeã®æ©æµã«ãããããªãå¯è½æ§ããã
- ãã¤ã¾ã§ãpushåºæ¥ãªãã¦rebaseå°çã®é¥ãå¯è½æ§ããã(mergeå°çããããã©ãã)
- rebsetsãããã®ã§ãå±¥æ´ãè·¯ç·å³ã§ãããããããã¯ã¨ãªã§æ¢ãã
ã¾ããrebaseã使ãããªãããMQ*8使ãã¾ããããããæè»ãªéç¨ãåºæ¥ã¾ãã®ãMQã®æ§è³ªä¸ãå±¥æ´ãã¾ãã¾ããããã«ãªãã¾ãã
ãã©ãã¼ã¢ãã
DVCSãå°å ¥ããããã¨è¨ã£ã¦ãä½ã§ãåé¡ã解決ããããã§ã¯ããã¾ãããé©åã«éç¨ãã¦ããç価ãçºæ®ããã¾ããéç¨ãæ¥ããããã¯å大ãªç¿æ £ã身ã«ä»ããããäºãããã¨ã«VCSã®ä½¿ãæ¹ãææ³ã説æãã¦è¡ãã¾ããã
ãããã
é·ãSubversionã使ã£ã¦ããããã¨è¨ã£ã¦VCSã使ãããªãããã®è¯ãç¿æ £ã身ã«ã¤ãã¦ããããã§ã¯ããã¾ãããå°å ¥ãçç±ã«æ¬¡ã®äºã«ã¤ãã¦ãããããã¾ããã
- ã³ãããåã«diffã確èªãããã¨
- ã³ããããè«çåä½ã§åå²ãããã¨
- 1ã³ãããã«1ã¤ã ãã®ä¿®æ£
- ââä½æ¥ä¸ã¨ããã³ããããããã
- ãªãã¸ã§ã³ã°ã©ãã®è¦æ¹ããã©ã³ãã®ä½¿ãæ¹
çåã解決ãã
Mercurialã®åºæ¬çãªä½¿ãæ¹ãå¦ãã§æºè¶³ãã¦ãã¾ãã¨æé·ãããã§æ¢ã¾ã£ã¦ãã¾ãã¾ããæ £ãã¦ããã¡ã³ãã¼ã«ã¯ããã¡ãããããããââ使ã£ã¦ãã ããã¨ãé¡ãããããçåç¹ãæãã¦ããã£ã¦ä¸ç·ã«è§£æ±ºããããã«åªãã¾ãããå ·ä½çã«ã¯æ¬¡ã®ãããªçåãããã¾ããã
- transplantã®ä½¿ãæ¹
- å¤æ´ã®åãæ¶ãæ¹
- éæ¹æ³ãã¼ã¸ã«ã¤ãã¦
- rebaseã®ã¦ã¼ã¹ã±ã¼ã¹
- MQã®ã¦ã¼ã¹ã±ã¼ã¹
- MQã使ãå§ããã¨æããçå(ãã©ã³ããæ¬å½ã«åãå¿ è¦ãããã®ã)
- pushåã®ãªãã¸ã§ã³ã®åé¤(hg strip)
- ããããã¡ã¤ã«ã®å ±ææ¹æ³(hg export)
åã¯ç¥æ§ãããªãã®ã§ãã¹ã¦ã®çåã解決ãããã¨ã¯ã§ãã¾ããã§ããããã®æã¯ã¾ã åã®ç¥èã§ã¯è§£æ±ºã§ããªãã¨ãããã¨ãä¼ããèªåã§ã調ã¹ã¦ãããããã«ãé¡ãããã¾ããã
Mercurial(DVCS)ãå°å ¥ãã¦å¤åãããã¨
ããé«æ©è½ãªéå ·ãå©ç¨ããäºã«ãããä»ã¾ã§å½ããåã®ã³ã¹ãã ã¨æã£ã¦ããç©ããä½æ©è½ãªéå ·ãå©ç¨ããäºã«ããå¼å®³ã ã¨ããäºã«æ°ã¥ãã¾ããã
ãã©ã³ããå¹æçã«å©ç¨åºæ¥ãããã«ãªã£ã
Subversionã§ã¯ãªãã¹ããã¼ã¸ãçºçãããªãããã®ãã©ã³ãæ¦ç¥ãã¨ãã¾ãããã®çµæããªãªã¼ã¹ãã©ã³ããæ¨ã¦ãéç¨ã«ãªããã¡ã§ãããã®èãã®æ ¹åºã«ã¯ãå¤æ´ãããªãããã«ãã©ã³ããåããã¨ããææ³ãæãã¾ãã
Mercurial移è¡å¾ã¯èããé転ãã¦éçºãã©ã³ãããªãªã¼ã¹ãã©ã³ãã«åãè¾¼ãéç¨ã«å¤åãã¾ããããã®èãã®æ ¹åºã«ã¯ãå¤æ´ãè¡ãããã«ãã©ã³ããåããã¨ããææ³ãããã¾ãã
Mercurialã§ã¯ãµã³ãããã¯ã¹ã¨ãã¦ãã©ã³ããå©ç¨åºæ¥ããããä»ã®ã¡ã³ãã¼ã«èªåã®ä½æ¥éä¸ã®å¤æ´ã®å½±é¿ãä¼æ¬ãã¾ãããSubversionæ代ã¯ãââä½æ¥ä¸ãã¨ããã³ããããã°ã«æ³£ãããã¾ããããMeruciralã§ã¯ä¿®æ£ãå®äºããå¾çµ±åãã©ã³ãã«åãè¾¼ã¾ããã®ã§äºæ ãæ¸ãã¾ããã
ä¸äººã®éçºè ã«ç°ãªããªãªã¼ã¹ã¿ã¼ã²ããã®ä½æ¥ããé¡ãã§ããããã«ãªã£ã
ãæ°è¦æ©è½ãéæéçºä¸ã®ã¡ã³ãã¼ã«ç·æ¥ã®ä¿®æ£ããé¡ããããã®ã¯ãããã話ã ã¨æãã¾ãã
ä»ã¾ã§ã¯svn switchã«æéãããããããçºãç·æ¥ã®ä¿®æ£ã§ãå³åº§ã«å¯¾å¿åºæ¥ãªãã£ãããsvn switch失æã®ãªã¹ã¯ã®å¤§ããããããããããé¡ãããäºãåºæ¥ãªãã£ãããã¾ããã
Mercurial移è¡å¾ã¯ãå½ããåã§ãããã©ã³ããå®å
¨ã«ç´ æ©ãåãæ¿ããäºãåºæ¥ãããã«ãªã£ãããããã®ãããªæ©ã¿ã¯ã»ã¨ãã©ç¡ããªãã¾ãããã¾ããéçºè
å´ããã¨ããããç¾å¨ã®ãã©ã³ãã§ä½æ¥ããå¾ãå¤æ´ç¹ãMQã§ç®çã®ãã©ã³ãã«å½ã¦ã¦ç¢ºèªãããã¨ãã£ãæè»ãªéçºãè¡ããããã«ãªãã¾ããã
ã¡ã³ãã¼ã®VCSã¸ã®ç解ãæ·±ã¾ã£ã
Subversionãå©ç¨ãã¦ãã¦svn mergeããããã¨ãããéçºè ã¯ããã¸ã§ã¯ãã«ä½äººå± ãã®ã§ããããï¼ãã©ã³ãã®ä½¿ãæ¹ãç解ãã¦ãã¾ããï¼
Mercurialã§ã¯ç©ºæ°ã®ããã«ãã¼ã¸ãè¡ãå¿ è¦ãããã¾ãããã®ãããå¿ ãå ¨å¡ããã¼ã¸ã®ä»æ¹ãè¦ãã¾ããSubversionã§ã¯éããã人ãã使ããªãã£ããã©ã³ãã§ãããMercurialã§ã¯ç°¡åã«ãã©ã³ããä½æåºæ¥ãããããå¤æ´ãè¡ãããã«ãã©ã³ããåããã¨ããèªç¶ãªèãã§ãã©ã³ããå©ç¨åºæ¥ãããã«ãªãã¾ããã
ä»ã¾ã§éç¨ãã¦ãã¦æããMercurialã®å¼·ã¿
åãç¹ã«å¼·ãæãã¦ããå¼·ã¿ã¯æ¬¡ã®éãã§ããæ®éã®ä¼æ¥*9ãé¸æããDVCSã¨ãã¦ã¯æé©ã ã¨æãã¾ãã
- ã³ãã³ãã©ã¤ã³ä½ç³»ãç°¡åãªã®ã§ãå¦ç¿ã³ã¹ããä½ã
- ãã«ããã«ããããç解ã§ããã°ã¨ãããã使ãã
- èªåã®ç解度ã«å¿ãã¦Mercurialæ¡å¼µãé¸æã§ãã
- ã¿ããªã«è¿·æããããæä½ãã»ã¨ãã©è¡ããªãã®ã§å®å ¨ã«éç¨ã§ãã
ãããã
å½é¢ã®ç®æ¨ã¯ãããããã人ã«ãªã£ã¦å±¥æ´æ¹å¤ãã¦ãã ããï¼ãã§ãã
ãªãã¹ãæè»ãªéç¨ãè¡ããããã«ãã¡ã³ãã¼å
¨å¡ã«å±¥æ´æ¹å¤ã¹ãã«ãæã£ã¦ããããã¨ãç®æ¨ã§ããå±¥æ´æ¹å¤ã¹ãã«ãããã°å½±é¿ã®å¤§ããããªæ©è½ã¯ããããã¼ã¹ã§ããåãããã¦éçºããããbackoutããããããã«rebaseããããä½ã§ãã§ããããã«ãªãã¾ãã*10
ã¾ã¨ã
Mercurialå°å ¥ã®è»è·¡ãç°¡åã«ç´¹ä»ãã¾ããããã®ã¨ã³ããªãåèã«ãã¦Mercurialãå°å ¥ãã¦è¡ã人ãã¡ãå¢ãããããããã§ãã
æ¬ã¨ã³ããªã§2011å¹´ã®MercurialAdventCalendarã¯çµããã§ããä»å¹´ããå§ã¾ã£ãã¢ããã³ãã«ã¬ã³ãã¼ã§ãããåå è ã®çããã®ãããã§ã¨ã¦ãçãä¸ããã¾ããããããã¨ããããã¾ããã
*1:@gab_kmããã¿ããã«å¤æ ã«ãªãããããã£ã
*2:subversionでのブランチマネジメント - TIM Labs
*3:svnからの切り替え先にbzrを検討するなど(最終的にはhgになった‥) - Togetterまとめ
*4:å½åééã£ããã ããã¼
*5:MQ(MercurialQueue)ã使ãã¨ãã©ã³ããåããªãéç¨ã«ãªããã¡ã§ããããã¯Mercurialã¬ãã«ãä¸ãã£ã¦ãä¸å¨ãã¦ãã¾ã£ãã¨ãããã¤ã§ããè¦ãç®ã¯åãã§ãããã¡ã³ã¿ã«ã¯å ¨ãå¥ç©ã§ãã
*6:å 容ã¯Git使いがMercurial使いに転職するとき設定しておくべきMercurial拡張 - TIM Labs
*7:ããã¯RabbitMQã®ãªãã¸ããªã®ãªãã¸ã§ã³ã°ã©ããè¦ããã¨ããããï¼ï¼
*8:MercurialQueue
*9:ã¨ãã£ã¦ãªãä¼æ¥
*10:ãªã®ã§ãåã®æ å½ããMercurialAdventCalendarã§ã¯å±¥æ´æ¹å¤ã«ã¤ãã¦åãå ¥ãã¾ããã社å ã®Skypeã«ãããèªãã§ä½¿ããããã«ãªã£ã¦ï¼ãã¨ãã¹ãã§ããã®ã§ã¨ã£ã¦ã楽ã§ãã