[poppler] Source code beautifiers

Jakub Kucharski jakubkucharski97 at gmail.com
Tue Jul 5 02:35:47 UTC 2016


On Tue, 2016-07-05 at 01:21 +0200, Albert Astals Cid wrote:
> Maybe you can work on a patch that does this so we can try it?

I've slightly modified what's on the Clang website. (If clang-format-
diff.py is somewhere else on your distro, let me know.) This script
should by run *before* committing. It makes things much more
convenient. The patch introducing the script (reformat.sh) is in the
"reformatting.patch" attachment. I've chosen LLVM style just to show it
in action, but the style in general is up for discussion.

It isn't perfect though. If you apply the patch in the attachment
"test.patch" (do it with git apply, not git am, so that you can run the
script before committing) and compare "git diff" output before and
after running the script it's clear that it may sometimes change single
surrounding lines.

"git diff" before running the script:

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 94f997d..4112e41 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -298,6 +298,11 @@ namespace Poppler {
        GooString *s1;
        Dict *infoDict = info.getDict();
 
+    printf("hello\n");
+    if (something) {
+        hello();
+    }
+
        if ( infoDict->lookup( type.toLatin1().data(), &obj )-
>isString() )
        {
            s1 = obj.getString();

"git diff" after running the script:

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 94f997d..de7185f 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -298,7 +298,12 @@ namespace Poppler {
        GooString *s1;
        Dict *infoDict = info.getDict();
 
-       if ( infoDict->lookup( type.toLatin1().data(), &obj )-
>isString() )
+        printf("hello\n");
+        if (something) {
+          hello();
+        }
+
+        if ( infoDict->lookup( type.toLatin1().data(), &obj )-
>isString() )
        {
            s1 = obj.getString();
            result = UnicodeParsedString(s1);

It looks like Uncrustify cannot reformat single patches. If we were to
go for ClangFormat, I could make the script edit only C/C++ files, but
for now it (ClangFormat) doesn't seem that good after all...

Jakub
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reformatting.patch
Type: text/x-patch
Size: 509 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20160705/5509b046/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.patch
Type: text/x-patch
Size: 725 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20160705/5509b046/attachment-0001.bin>


More information about the poppler mailing list