سؤال

أنا أستخدم Workbench MySQL للحفاظ على مخطط قاعدة البيانات للتطبيق. ال .mwb يتم الاحتفاظ بالملف الذي يستخدمه Workbench ، وهو مستند XML المضغوط ، في مستودع التخريب.

يتم التعامل مع الملف كبيانات ثنائية عن طريق التخريب ، لذلك لا يمكنني استخدامه svn diff لإظهار التغييرات ، على سبيل المثال قبل الالتزام.

نظرًا لأن البيانات هي XML حقًا ، فأنا أعتقد أنه قد يكون هناك طريقة لإظهار الفرق على أي حال ، وربما بعض البرامج النصية التي تفصل الملف من قبل ، أو بعض البرنامج المساعد إلى svn diff.

الحل المثالي سيسمح بذلك:

$ svn diff db-model.mwb

أو حتى باستخدام Meld:

$ meld db-model.mwb

ما هو النهج الذي يمكن أن تفكر في تحقيق هذا؟ ربما واجه شخص آخر هذه المشكلة المتمثلة في إظهار Diff للملفات النصية المؤرشفة في Subversion.

هل كانت مفيدة؟

المحلول

التخريب يسمح لك بالاستخدام أدوات الاختلاف الخارجية . ما يمكنك فعله هو كتابة برنامج نصي لف ، واطلم التخريب لاستخدامه كأمر "Diff". من شأن غلافك تحليل الحجج التي تحصل عليها من التخريب لاختيار أسماء الملفات "اليسرى" و "اليمنى" ، والعمل عليها ، وإرجاع رمز الخطأ الذي يفسر Subversion على أنه النجاح أو الفشل. في حالتك ، يمكن أن يفصل Wrapper من ملفات XML ، ويمرر النتائج غير المليئة بـ "Diff" أو أداة أخرى من اختيارك.

سوف يتأرجح التخريب في ملفات Diff-ing التي تم اكتشافها على أنها "ثنائية" عند تسجيل الدخول. يتيح لك خيار "-القوة" تجاوز هذا الشيك ، لذلك سيتم تشغيل البرنامج النصي لفك حتى إذا تم تسجيل ملفات الإدخال كما الثنائيات.

نصائح أخرى

لقد كتبت برنامجًا نصيًا Diff لملفات WorkBench التي يمكن دمجها مع TortoisesVn و TortoiseGit ، والتي سيفعل بالضبط ما يقترحه Jim Lewis: استخراج XML الفعلي من الأرشيف و diff.

سيقوم البرنامج النصي أيضًا بإلغاء كل PTR-الضوضاء في الفرق. الاندماج غير ممكن وسيكون أكثر تعقيدًا قليلاً (اكتشف كيف PTR-من شأنه أن يتصرف ، أعد حزم XML في الأرشيف ، ما هو مع البيانات الوصفية الأخرى في الأرشيف؟ ، ...)

يتوفر نص Python في Pastebin بموجب CC-By 3.0:

http://pastebin.com/acd7dbnh

# extensions: mwb
# TortoiseSVN Diff script for MySQL Workbench scheme files
# 2012 by Oliver Iking, Z-Software GmbH, oliverikingREPLACETHISWITHANATz-software.net, http://www.z-software.net/
# This work is licensed under a Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/

# Will produce two diffable documents, which don't resemble the FULL MWB content, but the scheme relevant data. 
# Merging is not possible

# Open your TortoiseSVN (or TortoiseSomething) settings, go to the "Diff Viewer" tab and click on "Advanced". Add 
# a row with the extension ".mwb" and a command line of 
# "path\to\python.exe" "path\to\diff-mwb.py" %base %mine
# Apply changes and now you can diff mysql workbench scheme files

import sys
import zipfile
import os
import time
import tempfile
import re

# mysql workbench XML will have _ptr_ attributes which are modified on each save for almost each XML node. Remove the visual litter, 
# make actual changes stand out.
def sanitizeMwbXml( xml ):
    return re.sub('_ptr_="([0-9a-fA-F]{8})"', '', xml)

try:
    if len(sys.argv) < 2:
        print("Not enough parameters, cannot diff documents!")
        sys.exit(1)

    docOld = sys.argv[1]
    docNew = sys.argv[2]

    if not os.path.exists(docOld) or not os.path.exists(docNew):
        print("Documents don't exist, cannot diff!")
        sys.exit(1)

    # Workbench files are actually zip archives
    zipA = zipfile.ZipFile( docOld, 'r' )
    zipB = zipfile.ZipFile( docNew, 'r' )

    tempSubpath = os.tempnam(None,"mwbcompare")

    docA = os.path.join( tempSubpath, "mine.document.mwb.xml" )
    docB = os.path.join( tempSubpath, "theirs.document.mwb.xml" )

    os.makedirs( tempSubpath )

    if os.path.exists(docA) or os.path.exists(docB):
        print("Cannot extract documents, files exist!")
        sys.exit(1)

    # Read, sanitize and write actual scheme XML contents to temporary files

    docABytes = sanitizeMwbXml(zipA.read("document.mwb.xml" ))
    docBBytes = sanitizeMwbXml(zipB.read("document.mwb.xml" ))

    docAFile = open(docA, "w")
    docBFile = open(docB, "w")

    docAFile.write(docABytes)
    docBFile.write(docBBytes)

    docAFile.close()
    docBFile.close()

    os.system("TortoiseProc /command:diff /path:\"" + docA + "\" /path2:\"" + docB + "\"");

    # TortoiseProc will spawn a subprocess so we can't delete the files. They're in the tempdir, so they
    # will be cleaned up eventually
    #os.unlink(docA)
    #os.unlink(docB)

    sys.exit(0)
except Exception as e:
    print str(e)
    # Sleep, or the command window will close
    time.sleep(5)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top