Mercurial > public > mercurial-scm > hg
diff mercurial/cext/mpatch.c @ 41336:763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
I find this easier to read. Cleanup performed like this:
hg files 'set:(**.c or **.cc or **.h) and not "listfile:contrib/clang-format-ignorelist"' | while read f ; do
clang-tidy -fix -checks=readability-braces-around-statements $f -- $(python-config --cflags) -Imercurial/cext -Imercurial
done
make format-c
I had to revert chg/chg.c as it's got a construct that seems to confuse
clang-tidy, so I'll work on that file later if this change is acceptable. I
only tackle files that are under clang-format's authority because otherwise
I'd have to do a bunch of manual formatting. A few files didn't get edited
because clang-tidy couldn't find some headers. Again, I'll figure that out
later assuming this change is accepted.
No check-code rule added for now because writing the regex sounds hard. In a
perfect world I guess we could write a test that uses clang-tidy on these
files, but I think clang-tidy is pretty rarely installed. :/
Differential Revision: https://phab.mercurial-scm.org/D5675
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 24 Jan 2019 10:21:59 -0500 |
parents | ec3c06a1c554 |
children | d4ba4d51f85f |
line wrap: on
line diff
--- a/mercurial/cext/mpatch.c Thu Jan 24 11:35:40 2019 -0500 +++ b/mercurial/cext/mpatch.c Thu Jan 24 10:21:59 2019 -0500 @@ -55,13 +55,16 @@ int r; PyObject *tmp = PyList_GetItem((PyObject *)bins, pos); - if (!tmp) + if (!tmp) { return NULL; - if (PyObject_GetBuffer(tmp, &buffer, PyBUF_CONTIG_RO)) + } + if (PyObject_GetBuffer(tmp, &buffer, PyBUF_CONTIG_RO)) { return NULL; + } if ((r = mpatch_decode(buffer.buf, buffer.len, &res)) < 0) { - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { setpyerr(r); + } res = NULL; } @@ -78,8 +81,9 @@ char *out; Py_ssize_t len, outlen; - if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins)) + if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins)) { return NULL; + } len = PyList_Size(bins); if (!len) { @@ -94,8 +98,9 @@ patch = mpatch_fold(bins, cpygetitem, 0, len); if (!patch) { /* error already set or memory error */ - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { PyErr_NoMemory(); + } result = NULL; goto cleanup; } @@ -126,8 +131,9 @@ cleanup: mpatch_lfree(patch); PyBuffer_Release(&buffer); - if (!result && !PyErr_Occurred()) + if (!result && !PyErr_Occurred()) { setpyerr(r); + } return result; } @@ -138,15 +144,18 @@ Py_ssize_t patchlen; char *bin; - if (!PyArg_ParseTuple(args, PY23("ls#", "ly#"), &orig, &bin, &patchlen)) + if (!PyArg_ParseTuple(args, PY23("ls#", "ly#"), &orig, &bin, + &patchlen)) { return NULL; + } while (pos >= 0 && pos < patchlen) { start = getbe32(bin + pos); end = getbe32(bin + pos + 4); len = getbe32(bin + pos + 8); - if (start > end) + if (start > end) { break; /* sanity check */ + } pos += 12 + len; outlen += start - last; last = end; @@ -154,9 +163,10 @@ } if (pos != patchlen) { - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { PyErr_SetString(mpatch_Error, "patch cannot be decoded"); + } return NULL; }