from mercurial import extensions, commands, scmutil
from mercurial import merge as mergemod
saved_ancestor = None
def update(orig, repo, node, branchmerge, force, partial, ancestor=None):
if saved_ancestor:
ancestor = scmutil.revsingle(repo, saved_ancestor).node()
return orig(repo, node, branchmerge, force, partial, ancestor)
def merge(orig, ui, repo, node=None, **opts):
global saved_ancestor
saved_ancestor = opts.get('ancestor')
return orig(ui, repo, node, **opts)
def extsetup(ui):
extensions.wrapfunction(mergemod, 'update', update)
entry = extensions.wrapcommand(commands.table, 'merge', merge)
entry[1].append(('', 'ancestor', '', 'override ancestor', 'REV'))
इसे एक फ़ाइल में रखें और एक्सटेंशन लोड करें। अब आप
hg merge --ancestor X
सामान्य पूर्वजों को ओवरराइड करने के लिए उपयोग कर सकते हैं। जैसा कि आपने पाया है, यह कई संभावित पूर्वजों के मामले में एक फर्क पड़ता है। यदि आप क्रिस-क्रॉस विलय करते हैं तो वह स्थिति उत्पन्न होती है।
@ changeset: 4:333411d2f751
|\
+---o changeset: 3:7d1f71140c74
| |/
| o changeset: 2:fdf4b78f5292
| |
o | changeset: 1:eb49ad46fd72
|/
o changeset: 0:e72ddea4d238
आप सामान्य रूप से विलय यदि आप पूर्वज के रूप में changeset eb49ad46fd72
हो और फ़ाइल x
शामिल हैं:: ग्राफ इस तरह दिखता है
hg init; echo a > x; hg commit -A -m a x
hg update 0; echo b >> x; hg commit -m b
hg update 0; echo c >> x; hg commit -m c
hg update 1; hg merge --tool internal:local 2; echo c >> x; hg commit -m bc
hg update 2; hg merge --tool internal:local 1; echo b >> x; hg commit -m cb
: आप इन आदेशों के साथ इस तरह के मामले बना सकते हैं
a
c
b
c
यदि आप इसके बजाय hg merge --ancestor 2
का उपयोग करते हैं तो आपको एक अलग परिणाम मिलता है:
a
b
c
b
दोनों मामलों में, मेरे KDiff3 किसी भी विवाद की रिपोर्ट किए बिना स्वचालित रूप से मर्ज को संभालने में सक्षम थे। अगर मैं "रिकर्सिव" विलय रणनीति का उपयोग करता हूं और पूर्वजों के रूप में e72ddea4d238
चुनता हूं, तो मुझे एक समझदार संघर्ष प्रस्तुत किया जाता है। गिट डिफ़ॉल्ट रूप से रिकर्सिव मर्ज रणनीति का उपयोग करता है।
यह एक वाह है! सही काम करता है। आपका बहुत बहुत धन्यवाद। वास्तव में, मुझे समझ में नहीं आता कि यह सुविधा Mercurial में क्यों शामिल नहीं है। ज्यादातर मामलों में किसी को इसकी आवश्यकता नहीं होगी, लेकिन मामलों में जब आवश्यक हो तो यह हल करने वाले संघर्षों के घंटों को बचा सकता है, या यहां तक कि गलत ऑटो विलय को भी रोक सकता है। रेपो में गलत बदलाव के बाद मुझे अभी ऐसे मुद्दों का सामना करना पड़ा है। –