Patchwork D2181: charencode: allow clang-format oversight

login
register
mail settings
Submitter phabricator
Date Feb. 12, 2018, 3:44 p.m.
Message ID <differential-rev-PHID-DREV-oyuohz6x3d2gvncnn4bk-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27667/
State Superseded
Headers show

Comments

phabricator - Feb. 12, 2018, 3:44 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Nice and easy.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2181

AFFECTED FILES
  contrib/clang-format-blacklist
  mercurial/cext/charencode.c
  mercurial/cext/charencode.h

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 12, 2018, 7:20 p.m.
indygreg requested changes to this revision.
indygreg added a comment.
This revision now requires changes to proceed.


  I want a second opinion about the `#include` order.

INLINE COMMENTS

> charencode.h:11-12
>  
> +#include "compat.h"
>  #include <Python.h>
>  

Huh? Why is it putting a system include after a local include? This feels wrong to me.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2181

To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
phabricator - Feb. 12, 2018, 8:10 p.m.
durin42 added inline comments.

INLINE COMMENTS

> indygreg wrote in charencode.h:11-12
> Huh? Why is it putting a system include after a local include? This feels wrong to me.

Per a colleague, https://clang.llvm.org/docs/ClangFormatStyleOptions.html - look for IncludeCategories.

Basically, it looks like we need to configure that. :/

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2181

To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/cext/charencode.h b/mercurial/cext/charencode.h
--- a/mercurial/cext/charencode.h
+++ b/mercurial/cext/charencode.h
@@ -8,8 +8,8 @@ 
 #ifndef _HG_CHARENCODE_H_
 #define _HG_CHARENCODE_H_
 
+#include "compat.h"
 #include <Python.h>
-#include "compat.h"
 
 /* This should be kept in sync with normcasespecs in encoding.py. */
 enum normcase_spec {
diff --git a/mercurial/cext/charencode.c b/mercurial/cext/charencode.c
--- a/mercurial/cext/charencode.c
+++ b/mercurial/cext/charencode.c
@@ -151,9 +151,8 @@ 
 	Py_RETURN_TRUE;
 }
 
-static inline PyObject *_asciitransform(PyObject *str_obj,
-					const char table[128],
-					PyObject *fallback_fn)
+static inline PyObject *
+_asciitransform(PyObject *str_obj, const char table[128], PyObject *fallback_fn)
 {
 	char *str, *newstr;
 	Py_ssize_t i, len;
@@ -173,12 +172,12 @@ 
 		char c = str[i];
 		if (c & 0x80) {
 			if (fallback_fn != NULL) {
-				ret = PyObject_CallFunctionObjArgs(fallback_fn,
-					str_obj, NULL);
+				ret = PyObject_CallFunctionObjArgs(
+				    fallback_fn, str_obj, NULL);
 			} else {
 				PyObject *err = PyUnicodeDecodeError_Create(
-					"ascii", str, len, i, (i + 1),
-					"unexpected code byte");
+				    "ascii", str, len, i, (i + 1),
+				    "unexpected code byte");
 				PyErr_SetObject(PyExc_UnicodeDecodeError, err);
 				Py_XDECREF(err);
 			}
@@ -220,10 +219,9 @@ 
 	Py_ssize_t pos = 0;
 	const char *table;
 
-	if (!PyArg_ParseTuple(args, "O!O!O!:make_file_foldmap",
-			      &PyDict_Type, &dmap,
-			      &PyInt_Type, &spec_obj,
-			      &PyFunction_Type, &normcase_fallback))
+	if (!PyArg_ParseTuple(args, "O!O!O!:make_file_foldmap", &PyDict_Type,
+	                      &dmap, &PyInt_Type, &spec_obj, &PyFunction_Type,
+	                      &normcase_fallback))
 		goto quit;
 
 	spec = (int)PyInt_AS_LONG(spec_obj);
@@ -251,19 +249,19 @@ 
 	while (PyDict_Next(dmap, &pos, &k, &v)) {
 		if (!dirstate_tuple_check(v)) {
 			PyErr_SetString(PyExc_TypeError,
-					"expected a dirstate tuple");
+			                "expected a dirstate tuple");
 			goto quit;
 		}
 
 		tuple = (dirstateTupleObject *)v;
 		if (tuple->state != 'r') {
 			PyObject *normed;
 			if (table != NULL) {
 				normed = _asciitransform(k, table,
-					normcase_fallback);
+				                         normcase_fallback);
 			} else {
 				normed = PyObject_CallFunctionObjArgs(
-					normcase_fallback, k, NULL);
+				    normcase_fallback, k, NULL);
 			}
 
 			if (normed == NULL)
@@ -292,13 +290,13 @@ 
 			char c = buf[i];
 			if (c & 0x80) {
 				PyErr_SetString(PyExc_ValueError,
-						"cannot process non-ascii str");
+				                "cannot process non-ascii str");
 				return -1;
 			}
 			esclen += jsonparanoidlentable[(unsigned char)c];
 			if (esclen < 0) {
 				PyErr_SetString(PyExc_MemoryError,
-						"overflow in jsonescapelen");
+				                "overflow in jsonescapelen");
 				return -1;
 			}
 		}
@@ -308,7 +306,7 @@ 
 			esclen += jsonlentable[(unsigned char)c];
 			if (esclen < 0) {
 				PyErr_SetString(PyExc_MemoryError,
-						"overflow in jsonescapelen");
+				                "overflow in jsonescapelen");
 				return -1;
 			}
 		}
@@ -336,17 +334,17 @@ 
 	case '\\':
 		return '\\';
 	}
-	return '\0';  /* should not happen */
+	return '\0'; /* should not happen */
 }
 
 /* convert 'origbuf' to JSON-escaped form 'escbuf'; 'origbuf' should only
    include characters mappable by json(paranoid)lentable */
 static void encodejsonescape(char *escbuf, Py_ssize_t esclen,
-			     const char *origbuf, Py_ssize_t origlen,
-			     bool paranoid)
+                             const char *origbuf, Py_ssize_t origlen,
+                             bool paranoid)
 {
 	const uint8_t *lentable =
-		(paranoid) ? jsonparanoidlentable : jsonlentable;
+	    (paranoid) ? jsonparanoidlentable : jsonlentable;
 	Py_ssize_t i, j;
 
 	for (i = 0, j = 0; i < origlen; i++) {
@@ -377,15 +375,15 @@ 
 	const char *origbuf;
 	Py_ssize_t origlen, esclen;
 	int paranoid;
-	if (!PyArg_ParseTuple(args, "O!i:jsonescapeu8fast",
-			      &PyBytes_Type, &origstr, &paranoid))
+	if (!PyArg_ParseTuple(args, "O!i:jsonescapeu8fast", &PyBytes_Type,
+	                      &origstr, &paranoid))
 		return NULL;
 
 	origbuf = PyBytes_AS_STRING(origstr);
 	origlen = PyBytes_GET_SIZE(origstr);
 	esclen = jsonescapelen(origbuf, origlen, paranoid);
 	if (esclen < 0)
-		return NULL;  /* unsupported char found or overflow */
+		return NULL; /* unsupported char found or overflow */
 	if (origlen == esclen) {
 		Py_INCREF(origstr);
 		return origstr;
@@ -395,7 +393,7 @@ 
 	if (!escstr)
 		return NULL;
 	encodejsonescape(PyBytes_AS_STRING(escstr), esclen, origbuf, origlen,
-			 paranoid);
+	                 paranoid);
 
 	return escstr;
 }
diff --git a/contrib/clang-format-blacklist b/contrib/clang-format-blacklist
--- a/contrib/clang-format-blacklist
+++ b/contrib/clang-format-blacklist
@@ -2,8 +2,6 @@ 
 # Do not add new files here!
 mercurial/cext/base85.c
 mercurial/cext/bdiff.c
-mercurial/cext/charencode.c
-mercurial/cext/charencode.h
 mercurial/cext/dirs.c
 mercurial/cext/manifest.c
 mercurial/cext/mpatch.c