python-unidiff icon indicating copy to clipboard operation
python-unidiff copied to clipboard

Create a "Commit" data structure between PatchSet and PatchedFile

Open amollberg opened this issue 5 years ago • 0 comments

I would like to see an additional data structure between PatchSet and PatchedFile which groups PatchedFiles and has it's own header information. This would fit the concept of commits in e.g. git.

Suppose I have generated this unified diff that contains multiple git commits:

commit bd48487445b6ef3f24dac66ce00926b23d1fe24c
Author: amollberg <[email protected]>
Date:   Sun Jul 24 11:07:12 2016 +0200

    First commit message, changing two files

diff --git a/file_a.py b/file_a.py
index 0d159ab..e0e2137 100644
--- a/file_a.py
+++ b/file_a.py
@@ -13 +13 @@ def function(arg):
-  before
+  after

diff --git a/file_b.py b/file_b.py
index 5bd6d12..aaa5496 100644
--- a/file_b.py
+++ b/file_b.py
@@ -230 +230 @@ class SomeClass():
-  before
+  after

58a8c50cd6abc0b2ac50f71f459ddf6581d36368
commit 58a8c50cd6abc0b2ac50f71f459ddf6581d36368
Author: amollberg <[email protected]>
Date:   Sun Jul 24 11:26:21 2016 +0200

    Second commit, changing one file

diff --git a/file_a.py b/file_a.py
index e0e2137..43a675a 100644
--- a/file_a.py
+++ b/file_a.py
@@ -14,2 +14,3 @@ def function(arg):
-    before
+    after

Currently, this results in just a list of 3 PatchedFiles. The header of the first commit is prepended to the first PatchedFiles patch_info, the second PatchedFile only gets its own file header, and the third PatchedFile gets the header of the second commit prepended to it.

Another problem is that an empty commit with a message but no file that has changed will simply become an empty Patchset and the commit message is not stored anywhere.

Clearly there is more structure here than what three PatchedFile can convey. I would like to start the discussion about how this structure can be better represented.

An option is to change the relationship from PatchSet is list of PatchedFile to PatchSet is list of Commit (name obviously not final) and Commit is list of PatchedFile . This would be a breaking change at a very central point in the API, so I appreciate if someone would want a more backwards-compatible approach.

amollberg avatar Mar 31 '19 10:03 amollberg