How can I distinguish between patch / merge strings instead of files?

I am working on a project in which people can represent stories and invest other people in them. Instead of just editing the record in the database, I would like to save the changes made by people, and not the whole new set of changes. Then I can dynamically apply diffs if people want to revert to the previous version. I can also easily introduce to users who are Editors with only the changed text so that they can go directly to the changes.

I know how to take diff files and fix other files with them. But I am building a web application with Python and Django, and I will store all these differences in a MySQL database. Given that performance is not a serious problem for this application, I am ready to pull out of the database data files and make a run git diffand patchin those files.

Is there a better way than creating new files and deleting them every time I want to create a new version or apply a new diff? Is there a way to run diff on plain text instead of files? For instance. set the variables in bash as the contents (what will be) of the file (but in fact it is data from the database) and run git diffon them? I would like to control these actions from the Python file after the user submits the form.

I am really looking for a good way to get started on this issue, so any help would be greatly appreciated.

Thank you for your time,

ParagonRG

+5
source share
2 answers

. Python difflib , , , , diff , . , , git diff, , , . difflib unified_diff, diff, diff. . diff text1 text2, diff1, text2 text1 diff1.

Python, , , , . merge_in_memory https://github.com/danielmoniz/merge_in_memory. setup.py.

:

import merge_in_memory as mim_module

str1 = """line 1
line 2"""
str2 = """line 1
line 2 changed"""

merger = mim_module.Merger()
print merger.diff_make(str1, str2)

:

--- 
+++ 
@@ -1,2 +1,2 @@
 line 1
-line 2
+line 2 changed

diffs - (, tan, difflib). (, ) diff_apply_bulk() .

, , reverse True diff_bulk() diff_apply_bulk. :

merge = self.inline_merge.diff_apply_bulk(text3, [diff1, diff2], reverse=True)

text1 text2 text3 diff1 diff2, text1 . , . "", .. diff , .

diffs VARCHAR ( --). , , .

, , Python.

,

ParagonRG

+4

libgit. C ( ), git .

, commit, diff .. , , , blob .

, , os.system.

+1

All Articles