[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-poppler
Subject:    Re: [poppler] Source code beautifiers
From:       Jakub Kucharski <jakubkucharski97 () gmail ! com>
Date:       2016-07-05 2:35:47
Message-ID: 1467686147.1341.16.camel () gmail ! com
[Download RAW message or body]

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
["reformatting.patch" (reformatting.patch)]

From 84db2a9a01b876ce0c172a1c546435c4bc6fb55a Mon Sep 17 00:00:00 2001
From: Jakub Kucharski <jakubkucharski97@gmail.com>
Date: Tue, 5 Jul 2016 04:09:26 +0200
Subject: [PATCH] add reformat.sh

---
 reformat.sh | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100755 reformat.sh

diff --git a/reformat.sh b/reformat.sh
new file mode 100755
index 0000000..6f78aae
--- /dev/null
+++ b/reformat.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+git diff -U0 | /usr/share/clang/clang-format-diff.py -i -p1 -style LLVM
-- 
2.9.0


["test.patch" (test.patch)]

From df7811e6260d09cd70b20426fe91aca6d2e000c5 Mon Sep 17 00:00:00 2001
From: Jakub Kucharski <jakubkucharski97@gmail.com>
Date: Tue, 5 Jul 2016 04:27:51 +0200
Subject: [PATCH] reformatting example

---
 qt4/src/poppler-document.cc | 5 +++++
 1 file changed, 5 insertions(+)

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();
-- 
2.9.0


[Attachment #5 (text/plain)]

_______________________________________________
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic