diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-01-25 17:36:11 +0100 |
---|---|---|
committer | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-03-27 16:31:58 +0200 |
commit | 14227ab516d4e7226b007fc6d9f5e80e9297c890 (patch) | |
tree | 6ea8f9aa523f8e58e71db5ff60ecb318ea1eef76 | |
parent | 4c160a9374cbef664d0eec034a7d86fd78543f03 (diff) | |
download | libproxy-git-14227ab516d4e7226b007fc6d9f5e80e9297c890.tar.gz |
Enforce check-code-style as pre-commit-hook (#16)
-rw-r--r-- | data/canonicalize_filename.sh | 48 | ||||
-rw-r--r-- | data/install-git-hook.sh | 12 | ||||
-rw-r--r-- | data/pre-commit-hook | 17 | ||||
-rw-r--r-- | meson.build | 4 | ||||
-rw-r--r-- | src/backend/plugins/config-env/config-env.c | 3 | ||||
-rw-r--r-- | src/backend/plugins/config-osx/config-osx.c | 12 | ||||
-rw-r--r-- | src/backend/plugins/config-sysconfig/config-sysconfig.c | 4 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.c | 3 | ||||
-rw-r--r-- | src/backend/plugins/download-soup/download-soup.c | 3 | ||||
-rw-r--r-- | src/backend/px-manager.c | 8 | ||||
-rw-r--r-- | src/tests/px-manager-test.c | 6 |
11 files changed, 101 insertions, 19 deletions
diff --git a/data/canonicalize_filename.sh b/data/canonicalize_filename.sh new file mode 100644 index 0000000..49c4dec --- /dev/null +++ b/data/canonicalize_filename.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# Provide the canonicalize filename (physical filename with out any symlinks) +# like the GNU version readlink with the -f option regardless of the version of +# readlink (GNU or BSD). + +# This file is part of a set of unofficial pre-commit hooks available +# at github. +# Link: https://github.com/ddddavidmartin/Pre-commit-hooks +# Contact: David Martin, ddddavidmartin@fastmail.com + +########################################################### +# There should be no need to change anything below this line. + +# Canonicalize by recursively following every symlink in every component of the +# specified filename. This should reproduce the results of the GNU version of +# readlink with the -f option. +# +# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac +canonicalize_filename () { + local target_file="$1" + local physical_directory="" + local result="" + + # Need to restore the working directory after work. + local working_dir="`pwd`" + + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + + # Iterate down a (possible) chain of symlinks + while [ -L "$target_file" ] + do + target_file="$(readlink -- "$target_file")" + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + done + + # Compute the canonicalized name by finding the physical path + # for the directory we're in and appending the target file. + physical_directory="`pwd -P`" + result="$physical_directory/$target_file" + + # restore the working directory after work. + cd -- "$working_dir" + + echo "$result" +} diff --git a/data/install-git-hook.sh b/data/install-git-hook.sh new file mode 100644 index 0000000..7fd5550 --- /dev/null +++ b/data/install-git-hook.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cd "$MESON_SOURCE_ROOT" + +[ -d .git ] || exit 0 # not a git repo +[ ! -f .git/hooks/pre-commit ] || exit 0 # already installed + +echo "Copying pre commit hook" +cp data/pre-commit-hook .git/hooks/pre-commit +echo "Copying helper" +cp data/canonicalize_filename.sh .git/hooks/canonicalize_filename.sh +echo "Done"
\ No newline at end of file diff --git a/data/pre-commit-hook b/data/pre-commit-hook new file mode 100644 index 0000000..24b2ff2 --- /dev/null +++ b/data/pre-commit-hook @@ -0,0 +1,17 @@ +#!/bin/bash + +. "$(dirname -- "$0")/canonicalize_filename.sh" + + +# exit on error +set -e + +# Absolute path to this script +SCRIPT="$(canonicalize_filename "$0")" +# Absolute path this script is in, e.g. /home/user/bin/ +SCRIPTPATH="$(dirname -- "$SCRIPT")" + +echo $SCRIPTPATH +cd $SCRIPTPATH/../../ +data/check-code-style +cd -
\ No newline at end of file diff --git a/meson.build b/meson.build index 0b28bba..402a724 100644 --- a/meson.build +++ b/meson.build @@ -123,3 +123,7 @@ summary({ 'host system' : host_system, 'C Compiler' : cc.get_id(), }, section: 'Build environment') + +# Install pre-commit hook +git_hook_installer = find_program('data/install-git-hook.sh') +run_command(git_hook_installer)
\ No newline at end of file diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index 5b3a686..cbc4de5 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -57,7 +57,7 @@ px_config_env_init (PxConfigEnv *self) self->no_proxy = g_strsplit (no_proxy, ",", -1); self->ftp_proxy = g_getenv ("ftp_proxy"); - if (!self->ftp_proxy ) + if (!self->ftp_proxy) self->ftp_proxy = g_getenv ("FTP_PROXY"); self->https_proxy = g_getenv ("https_proxy"); @@ -67,7 +67,6 @@ px_config_env_init (PxConfigEnv *self) self->http_proxy = g_getenv ("http_proxy"); if (!self->http_proxy) self->http_proxy = g_getenv ("HTTP_PROXY"); - } static void diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index 6ccd298..a4041eb 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -65,7 +65,7 @@ getobj (CFDictionaryRef settings, if (!k) return NULL; - retval = (CFNumberRef) CFDictionaryGetValue(settings, k); + retval = (CFNumberRef)CFDictionaryGetValue (settings, k); CFRelease (k); return retval; @@ -73,7 +73,7 @@ getobj (CFDictionaryRef settings, static CFStringRef getobj_str (CFDictionaryRef settings, - char *key) + char *key) { CFStringRef k; CFStringRef retval; @@ -85,7 +85,7 @@ getobj_str (CFDictionaryRef settings, if (!k) return NULL; - retval = (CFStringRef) CFDictionaryGetValue(settings, k); + retval = (CFStringRef)CFDictionaryGetValue (settings, k); CFRelease (k); return retval; @@ -113,7 +113,7 @@ getbool (CFDictionaryRef settings, { int64_t i = 0; - if (!getint(settings, key, &i)) + if (!getint (settings, key, &i)) return FALSE; return i != 0; @@ -133,7 +133,7 @@ px_config_osx_get_config (PxConfig *self, return FALSE; } - if (getbool(proxies, "ProxyAutoDiscoveryEnable")) { + if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { CFRelease (proxies); g_strv_builder_add (builder, "wpad://"); return TRUE; @@ -143,7 +143,7 @@ px_config_osx_get_config (PxConfig *self, CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString"); const char *tmp = CFStringGetCStringPtr (ref, CFStringGetFastestEncoding (ref)); GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL); - + if (tmp_uri) { g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri)); CFRelease (proxies); diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 22f536f..29e8420 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -66,13 +66,13 @@ px_config_sysconfig_init (PxConfigSysConfig *self) return; } - istr = g_file_read(file, NULL, NULL); + istr = g_file_read (file, NULL, NULL); if (!istr) { g_print ("Could not read file\n"); return; } - dstr = g_data_input_stream_new(G_INPUT_STREAM(istr)); + dstr = g_data_input_stream_new (G_INPUT_STREAM (istr)); if (!dstr) return; diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 7bde950..06a91b8 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -60,7 +60,8 @@ store_data (void *contents, } static GBytes * -px_download_curl_download (PxDownload *download, const char *uri) +px_download_curl_download (PxDownload *download, + const char *uri) { PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); g_autoptr (GBytes) bytes = NULL; diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c index de338d1..905f173 100644 --- a/src/backend/plugins/download-soup/download-soup.c +++ b/src/backend/plugins/download-soup/download-soup.c @@ -47,7 +47,8 @@ px_download_soup_class_init (PxDownloadSoupClass *klass) } static GBytes * -px_download_soup_download (PxDownload *download, const char *uri) +px_download_soup_download (PxDownload *download, + const char *uri) { PxDownloadSoup *self = PX_DOWNLOAD_SOUP (download); g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 097f020..ca80eab 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -186,10 +186,10 @@ px_manager_class_init (PxManagerClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); obj_properties[PROP_CONFIG_PLUGIN] = g_param_spec_string ("config-plugin", - NULL, - NULL, - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + NULL, + NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, LAST_PROP, obj_properties); } diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index ba1c6b7..428f5d2 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -32,7 +32,7 @@ typedef struct { } Fixture; static void -server_callback (SoupServer *server, +server_callback (SoupServer *server, SoupServerMessage *msg, const char *path, GHashTable *query, @@ -47,8 +47,8 @@ server_callback (SoupServer *server, gsize len; if (!g_file_get_contents (pac, &pac_data, &len, &error)) { - g_warning ("Could not read pac file: %s", error ? error->message : ""); - return; + g_warning ("Could not read pac file: %s", error ? error->message : ""); + return; } soup_server_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY, pac_data, len); } |