Skip to content

Configure diff drivers for php, phpt, c and h in .gitattributes #8343

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

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

TimWolla
Copy link
Member

Example for *.phpt:

git diff -U7 2145f80^..2145f80

Old:

@@ -22,14 +22,18 @@ enum CustomFoo implements JsonSerializable {
         return 'Custom ' . $this->name;
     }
 }
 
 function test($value) {
     var_dump(json_encode($value));
     echo json_last_error_msg() . "\n";
+    if (json_last_error() !== JSON_ERROR_NONE) {
+        echo json_last_error() . ' === '  . JSON_ERROR_NON_BACKED_ENUM . ":\n";
+        var_dump(json_last_error() === JSON_ERROR_NON_BACKED_ENUM);
+    }
 
     try {
         var_dump(json_encode($value, JSON_THROW_ON_ERROR));
         echo json_last_error_msg() . "\n";
     } catch (Exception $e) {
         echo get_class($e) . ': ' . $e->getMessage() . "\n";
     }

New:

@@ -22,14 +22,18 @@ public function jsonSerialize(): mixed {
         return 'Custom ' . $this->name;
     }
 }
 
 function test($value) {
     var_dump(json_encode($value));
     echo json_last_error_msg() . "\n";
+    if (json_last_error() !== JSON_ERROR_NONE) {
+        echo json_last_error() . ' === '  . JSON_ERROR_NON_BACKED_ENUM . ":\n";
+        var_dump(json_last_error() === JSON_ERROR_NON_BACKED_ENUM);
+    }
 
     try {
         var_dump(json_encode($value, JSON_THROW_ON_ERROR));
         echo json_last_error_msg() . "\n";
     } catch (Exception $e) {
         echo get_class($e) . ': ' . $e->getMessage() . "\n";
     }

👉 git understands that return 'Custom ' . $this->name; is in a method called jsonSerialize and not just in an enum called CustomFoo.

Example for *.c:

git diff --word-diff 7710f99^..7710f99

Old:

@@ -257,7 +257,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplFileObject_hasChildren, 0, 0, IS_FALSE, 0)
ZEND_END_ARG_INFO()

[-ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SplFileObject_getChildren,-]{+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplFileObject_getChildren,+} 0, 0, [-MAY_BE_NULL)-]{+IS_NULL, 1)+}
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplFileObject_seek, 0, 1, IS_VOID, 0)

New:

@@ -257,7 +257,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplFileObject_hasChildren, 0, 0, IS_FALSE, 0)
ZEND_END_ARG_INFO()

[-ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX-]{+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX+}(arginfo_class_SplFileObject_getChildren, 0, 0, [-MAY_BE_NULL-]{+IS_NULL, 1+})
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplFileObject_seek, 0, 1, IS_VOID, 0)

👉 git understands that ( is a token / word delimiter for C and thus realizes that arginfo_class_SplFileObject_getChildren is unchanged.

@codecov-commenter
Copy link

Codecov Report

Merging #8343 (7710f99) into master (7710f99) will not change coverage.
The diff coverage is n/a.

❗ Current head 7710f99 differs from pull request most recent head ed30df3. Consider uploading reports for the commit ed30df3 to get more accurate results

@@           Coverage Diff           @@
##           master    #8343   +/-   ##
=======================================
  Coverage   67.45%   67.45%           
=======================================
  Files         806      806           
  Lines      306039   306039           
=======================================
  Hits       206440   206440           
  Misses      99599    99599           

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Nice one, thank you!

Copy link
Contributor

@morrisonlevi morrisonlevi left a comment

Choose a reason for hiding this comment

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

According to the git-scm gitattributes docs, diff=cpp is also suitable for C, so looks good to me.

@TimWolla TimWolla merged commit ddf7e35 into php:master Apr 12, 2022
@TimWolla TimWolla deleted the diff-driver branch April 12, 2022 19:08
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.

4 participants