Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare buffers in diff example #5125

Merged
merged 2 commits into from
Aug 1, 2019
Merged

Conversation

albfan
Copy link
Contributor

@albfan albfan commented Jun 18, 2019

Adding compare buffers feature in diff example

This tries to mimic git diff --no-index

echo hello > file1
echo bye > file2
git diff --no-index file1 file2
diff --git 1/file1 2/file2
index 5c1b14949..b023018ca 100644
--- 1/file1
+++ 2/file2
@@ -1 +1 @@
-hello
+bye

Right now this patch does:

$ ./diff --files --text --color
buf: diff --git a/file1 b/file2
index ce01362..b023018 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
-hello
+bye
diff --git a/file1 b/file2
index ce01362..b023018 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
-hello
+bye

Actual problems:

  • Read real files
  • Do not detect buffers as binary files
  • Use --no-index as parameter
  • Check two files are passed and they exists

@albfan
Copy link
Contributor Author

albfan commented Jun 18, 2019

Not sure if there is any better code to load an entire file into a char* (or void*):

https://codereview.stackexchange.com/q/163424

@neithernut
Copy link
Contributor

mmap (or rather the portability-interface provided by libgit2)?

@ethomson
Copy link
Member

mmap (or rather the portability-interface provided by libgit2)?

Let's not add an example that uses that, it's private API and not available to consumers.

I think that the best example would be simplest, and avoiding mmap is definitely the simple route.

@albfan albfan force-pushed the wip/albfan/diff_buffers branch 4 times, most recently from 61687c1 to 1a214d6 Compare June 18, 2019 19:27
@albfan albfan closed this Jun 18, 2019
@albfan albfan reopened this Jun 18, 2019
@albfan albfan force-pushed the wip/albfan/diff_buffers branch from 1a214d6 to 93de380 Compare June 18, 2019 19:35
@albfan
Copy link
Contributor Author

albfan commented Jun 18, 2019

Read files is implemented right now:

$ echo hello > file1
$ echo bye > file2
$ ./lg2 diff --no-index file1 file2
diff --git a/file1 b/file2
index ce01362..b023018 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
-hello
+bye

@neithernut @ethomson Let me know any further change to do.

We plan to use this on https://gitlab.gnome.org/albfan/diferencia/issues/3 and integrate in libgit2-glib so anyone can diff files without being in a repo.

Copy link
Contributor

@tiennou tiennou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor nitpicks, but other that that LGTM. Thanks for working on this @albfan!

examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
@tiennou
Copy link
Contributor

tiennou commented Jun 18, 2019

Let's not add an example that uses that, it's private API and not available to consumers.

You do realize some of us are itching to run git's test suite against our "examples", right? Right 😉? Just to say that I'd like to revisit that. Not being able to access libgit2's stdlib makes writing examples painful when you're left longing for futils

Copy link
Contributor

@neithernut neithernut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: not a maintainer. Commenting nonetheless, since requested.

I only had a quick look, mainly at read_file() since that's the part were I meddled initially. Your indentation is partially inconsistent both with the rest of the code-base and in itself. As already pointed out, it's tabs equivalent to 8 spaces for this project.

examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch 2 times, most recently from b82a02e to 64dbe94 Compare June 19, 2019 00:29
Copy link
Contributor

@tiennou tiennou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another batch of review comments: there's still a few issues with the file reading function, a few more style issues, and a possible cleanup request (which you must feel free to disregard). I can't merge though, so it'll have to wait for someone who can.

examples/common.c Outdated Show resolved Hide resolved
examples/common.c Outdated Show resolved Hide resolved
examples/common.c Outdated Show resolved Hide resolved
examples/common.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
examples/common.c Outdated Show resolved Hide resolved
examples/diff.c Outdated Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch 2 times, most recently from 35dc4c3 to d08fd11 Compare June 19, 2019 10:06
@albfan
Copy link
Contributor Author

albfan commented Jun 20, 2019

We are on air! https://gitlab.gnome.org/GNOME/libgit2-glib/commit/d5f41735489ac31f389de66edaba7a2c55d67024

thanks!. If you want to avoid creating a patch to extract a diff to do this, I would be glad to help.

examples/diff.c Outdated Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch from d08fd11 to 4d8aec5 Compare June 20, 2019 10:54
@pks-t
Copy link
Member

pks-t commented Jun 27, 2019 via email

@pks-t
Copy link
Member

pks-t commented Jun 27, 2019 via email

@albfan
Copy link
Contributor Author

albfan commented Jun 27, 2019

Just to mention, we are facing a problem when differing files with no newline at end. Seems patch is not parseable.

Is there any config or workaround? Compare buffers without need to convert to a patch would be nice. Right now we just always add newline at end if it not exists.

Let me know if I can rework any part to get this merged

@pks-t
Copy link
Member

pks-t commented Jun 27, 2019 via email

@albfan
Copy link
Contributor Author

albfan commented Jun 29, 2019

@pks-t check #5153

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, took me longer than expected to review this

examples/common.c Outdated Show resolved Hide resolved
examples/common.h Outdated Show resolved Hide resolved
examples/diff.c Show resolved Hide resolved
examples/diff.c Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch from 4d8aec5 to 52d887a Compare July 4, 2019 08:53
@albfan albfan force-pushed the wip/albfan/diff_buffers branch from 52d887a to 3caab05 Compare July 4, 2019 09:08
Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your updates! Some more nits and then we should be mostly good to go.

examples/common.c Show resolved Hide resolved
examples/common.c Outdated Show resolved Hide resolved
examples/diff.c Show resolved Hide resolved
examples/diff.c Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch 2 times, most recently from 93fdb01 to bae7597 Compare July 5, 2019 10:48
examples/common.h Outdated Show resolved Hide resolved
@albfan albfan force-pushed the wip/albfan/diff_buffers branch from bae7597 to 3be09b6 Compare July 5, 2019 12:12
Consolidate all standard includes and defines into "common.h". This lets
us avoid having to handle platform-specific things in multiple places.
@pks-t
Copy link
Member

pks-t commented Jul 5, 2019

I've amended a commit to this PR to fix Win32 builds so that you don't have to handle this :)

@albfan
Copy link
Contributor Author

albfan commented Jul 5, 2019

@pks-t Nice to see you in action! haha

@albfan
Copy link
Contributor Author

albfan commented Jul 8, 2019

Still finding github PR hard to follow

Merging can be performed automatically once the requested changes are addressed.

Can't find anything else to do. Is there some "I approve this PR" check to press or something?

@neithernut
Copy link
Contributor

One of the maintainers has to approve the changes (and then merge them). This may take a while for this project due to them being understaffed/limited in bandwidth. So there is nothing else to do except for waiting patiently.

@albfan
Copy link
Contributor Author

albfan commented Jul 8, 2019

@neithernut I was sure about that. All the process was really awesome and supportive. We will try to provide feedback on #5161, and use as patch meanwhile it is being reviewed.

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, nothing you have to do now :) I'll wait with merging until #5158 has landed though, as you have uncovered a lifetime issue with how we handle parsed patches

@pks-t pks-t merged commit 56e7aaf into libgit2:master Aug 1, 2019
@pks-t
Copy link
Member

pks-t commented Aug 1, 2019

#5158 has been merged, so I've merged this now. Thanks a lot for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants