From patchwork Tue Feb 27 16:02:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergius Nyah X-Patchwork-Id: 13574072 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4E30535AE for ; Tue, 27 Feb 2024 16:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709049788; cv=none; b=VRdOhDcgEXno2002ST6NIrHBCXo79Ektq2zcA5usadXqYnWKQaD0x3UhGY015IqTM3jl/6lkjw8ani/NeIpLQ/iOejNgg7LKLMMPILtMLInQAMSIVCU7eLd0Da5nV3++TH0Oko6yP25xYDxmkcLd505lo4SpsmKzb/dU7JOihmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709049788; c=relaxed/simple; bh=k0Mc46DnWHUAIS8GHynMptZz3uiwlY5VidaTXn1IkZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MjBfTdvmTxDSOTOr12DWySjj1ZDdUOyW1Zl6eq74rRMWjFhoUcKgVYY61wKaOo80PKB88eo4z/1mQvf7BcIHboglqaRXUkL1+7YFzEOVqlk+74i2tYyIiXS6gPx4e/Ul6qRAD1Hrcwt3r36gQK1ZswPDZU7NOEdBX++YHot0H3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gZprDHGv; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gZprDHGv" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-412a9e9c776so7826915e9.0 for ; Tue, 27 Feb 2024 08:03:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709049785; x=1709654585; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aUAQ5Vm6Lh5Ods16TuV6PfrUiAhO5cmoXWkppP4UWn0=; b=gZprDHGv/T5N1ebq6J28IWGA4w7tBEsxFRbJcxeev6VVV1USjxj0pVUqU0mYIVNhKo g+LwHXm+9nImAGHX9uzZUs44j/nOASUk+UJKt/mZs433lz+PZcPEwMn43n7yGON3qqwa cGgznmlAhMCI9amyBypuKPIjA7+pj65RJo1vp+0byVvwTSqysA05xj4o7NPUYdeeEj8i SxvgsO2Nw92azm4938S9Of94mzP+a6hH54Kf+NHLsi8Jd6HzLFWExVr8rK7DtuU9sPLI dGoDE8kAiZoAcEXKcl0AX8Xf2iG1NdMOKBrwv3OqsyFK5Xb0nfTVqKYF3v9o+YANuO1A QEIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709049785; x=1709654585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aUAQ5Vm6Lh5Ods16TuV6PfrUiAhO5cmoXWkppP4UWn0=; b=CJNxxYzbgvpEbQBEubIcfSsUo3r4WAP6ixWogbTYpxe5zGusqpzghX186phodbhUlp yHsKUgnp4C1kpKhNWnDotgFmXs33dghplUpI78dgTsQTh4DZmmCnoCqM6sASTB9pmfQ6 QimddtFuz+HnG+wFBWzLKF9DS1tDHrYFVWB1vhCfYcbmU2B/C3ZwM0brp5AY9tmEOQ+U 7Dkkgl7RPeSVk38KmUhuma1WTXg+QW4Qv40rd3Pz+w6KJxCC7T63Qg8OGEKAR1xmL8bb EiHXNWVvd03neL5uJxECkRhVpWCPrlakKSjPNLYTe2Oqfec72E858ksmx/9EflBLqYGS gK5Q== X-Gm-Message-State: AOJu0YwKXK9hRh/kQkAI2lofBsjwd4B6/pTTVa6kpK09NQr3OBNDQXnh EvX/FuglY+MtlfDm2w3MsqTOE7OzYEK8C0BkZjGh/op9OC/k+aIJkyOeQ9Vw0jQ= X-Google-Smtp-Source: AGHT+IEwzhN96HQ9XcGDEdZHAj19VO3RvtGQ5QkSQfj1WijfYSwbpfsnYB6OuQ+lWnoM5sxNB4zEUg== X-Received: by 2002:a5d:5650:0:b0:33d:eb13:9e27 with SMTP id j16-20020a5d5650000000b0033deb139e27mr2549220wrw.23.1709049785171; Tue, 27 Feb 2024 08:03:05 -0800 (PST) Received: from host-sergy.. ([154.72.153.219]) by smtp.gmail.com with ESMTPSA id a2-20020a5d5702000000b0033ce5b3390esm11714323wrv.38.2024.02.27.08.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:03:04 -0800 (PST) From: Sergius Nyah To: christian.couder@gmail.com, pk@pks.im Cc: git@vger.kernel.org, Sergius Nyah Subject: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff. Date: Tue, 27 Feb 2024 17:02:52 +0100 Message-ID: <20240227160253.104011-2-sergiusnyah@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227160253.104011-1-sergiusnyah@gmail.com> References: <20240227160253.104011-1-sergiusnyah@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks. --- userdiff.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/userdiff.c b/userdiff.c index e399543823..12e31ff14d 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,7 +1,7 @@ #include "git-compat-util.h" #include "config.h" #include "userdiff.h" -#include "attr.h" +#include "attr.h" #include "strbuf.h" static struct userdiff_driver *drivers; @@ -183,6 +183,19 @@ PATTERNS("java", "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" "|[-+*/<>%&^|=!]=" "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), +PATTERNS("javascript", + /* + * Looks for lines that start with optional whitespace, followed + * by 'function'* and any characters (for function declarations), + * or valid JavaScript identifiers, equals sign '=', 'function' keyword + * and any characters (for function expressions). + * Also considers functions defined inside blocks with '{...}'. + */ + "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n", + /* This pattern matches JavaScript identifiers */ + "[a-zA-Z_$][0-9a-zA-Z_$]*" + "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" + "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), PATTERNS("kotlin", "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$", /* -- */ @@ -192,7 +205,7 @@ PATTERNS("kotlin", /* integers and floats */ "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*" /* floating point numbers beginning with decimal point */ - "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?" + "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?" /* unary and binary operators */ "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"), PATTERNS("markdown", From patchwork Tue Feb 27 16:02:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergius Nyah X-Patchwork-Id: 13574073 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E089146910 for ; Tue, 27 Feb 2024 16:03:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709049798; cv=none; b=qEVO70oaoyjVpSjXYAa0o6YKz4iAxBUSXyxE9/Or7ObN2fzShBzAI1Fpy1PDanZV9I1Ooir1O+uGKt4Nh3/LrtMJtIzllEq7jyufmW7ih7PmF52E4IPe1mL0+XWFWPbc5lPSH0EhV0klFSxZHKzSGrS5HYk4+qD53fYullDxo6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709049798; c=relaxed/simple; bh=QoXU40IhfjYnfjUzBn2AL0XB6zAm+mtwfjIxxlXs99k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XODGQb9Ig9nMGtEnFpNViKCWs6oOsTCs8TNkXxzy0CXxGX97JIJo9wkQzCdgxaNBqGSpxG+UEi8nsc0HHh7MAXVJizka//vx0K5y+mBs2A+XZYNefS46RRcwGIFxN0yZioOX6nzXqTsTVfdERPcrPxtlGMyXc9WysbimBWepe7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gNLx4Irj; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gNLx4Irj" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-412ad927275so5488235e9.3 for ; Tue, 27 Feb 2024 08:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709049795; x=1709654595; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zuS2yvg1wo4U8mkfVTxOZsS+fosUZKsUvC0bLydMFY8=; b=gNLx4IrjLpLO9q+mXHaMMkY0mhMYmLB1BSNlKtHcJ2U5cAoUym6KoQ2bmRItsXfcMb 2SakvBZtbYVavygOdWv6eVCK/dW0G+psFlu5GHBLAtvG+5GdUwdhQJXO6T+sbYtoJr0r VwoNQQY4B/XiJYbd8ojwX6FWG4pUhNkhNev7P4SDPz4tkb6EA/UL+CxW3yVT3agy8QTo UsRMhONxOy7TiNReQNwImmUY5XdyNYq0ZSrzjmuzrfIMEApvU0YsE6RqIiGchVSmjf6V Ck2mBtV3QVjN62Z8TwokvqMTvoxSsGMwN0aqi0TH5c48KVtePP1NHlC/2DulFNG91PGx 5gxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709049795; x=1709654595; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zuS2yvg1wo4U8mkfVTxOZsS+fosUZKsUvC0bLydMFY8=; b=iLj/ScqgvtQgWhkFtXfqPRMur8i+Emu8gB37OOWOuZubjMwnXm3NGbVaq7072dqGhn ZWTVT+fbl9k+wCNUSieFMm4sDsyMLoer6BCUbhIF15JZq0TDvf9pA6hTbashEdpBEm7e 1SCSb/VmF9SeiGve7ShtoeMn+cIovk0EJP2sEj0ePLy6SHPTFYyn5eCFPXE88IyjcJll 689vZ0ClJd9Ymsgl0mwX6nYezC4j1FhVlK4bkdTPBc/McWBuVc8OZe4fPv2HRUXfzF7I RlM0RkfY5InN9p6sgfwuMud7p7D9A0/MP+DocCugCNLroGZ9eyJ9Fq6hnAfln6BHiE9R kacg== X-Gm-Message-State: AOJu0YzRaxG1jLQrYMsXYxX62gbMfOGwbMtne9gSJJZfvCHVPZr2yGRg ZSkttieBF9q3rui2+7e/Vsgnumb3uNh92kO7XKJFNGlyr1VpqUorZG6YFQtexJw= X-Google-Smtp-Source: AGHT+IFWdgKdwHfsyu/aaZ1TwRZm0mGpRVuSiwYsNbG4TVQNyRIpjPwgY5G0y1ktvj9fi4i7cr9lTg== X-Received: by 2002:a05:600c:a4c:b0:412:77cb:ae28 with SMTP id c12-20020a05600c0a4c00b0041277cbae28mr9054475wmq.11.1709049794617; Tue, 27 Feb 2024 08:03:14 -0800 (PST) Received: from host-sergy.. ([154.72.153.219]) by smtp.gmail.com with ESMTPSA id a2-20020a5d5702000000b0033ce5b3390esm11714323wrv.38.2024.02.27.08.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:03:14 -0800 (PST) From: Sergius Nyah To: christian.couder@gmail.com, pk@pks.im Cc: git@vger.kernel.org, Sergius Justus Chesami Nyah Subject: [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Date: Tue, 27 Feb 2024 17:02:53 +0100 Message-ID: <20240227160253.104011-3-sergiusnyah@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227160253.104011-1-sergiusnyah@gmail.com> References: <20240227160253.104011-1-sergiusnyah@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sergius Justus Chesami Nyah This commit introduces a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs. The test creates a JavaScript file with function declarations and expressions, modifies them, and then checks the output of git diff to ensure that the changes are correctly identified. This test validates the changes made to userdiff.c for improved JavaScript function detection. --- t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index e026fac1f4..e88e63bd1f 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -11,7 +11,7 @@ test_expect_success 'setup' ' # a non-trivial custom pattern git config diff.custom1.funcname "!static !String -[^ ].*s.*" && +[^ ].*s.*" && # a custom pattern which matches to end of line git config diff.custom2.funcname "......Beer\$" && @@ -119,4 +119,25 @@ do " done -test_done +test_expect_success 'identify builtin patterns in Javascript' ' + # setup + echo "function myFunction() { return true; }" > test.js && + echo "var myVar = function() { return false; }" >> test.js && + git add test.js && + git commit -m "add test.js" && + + # modify the file + echo "function myFunction() { return false; }" > test.js && + echo "var myVar = function() { return true; }" >> test.js && + + # command under test + git diff >output && + + # check results + test_i18ngrep "function myFunction() { return true; }" output && + test_i18ngrep "function myFunction() { return false; }" output && + test_i18ngrep "var myVar = function() { return false; }" output && + test_i18ngrep "var myVar = function() { return true; }" output +' + +test_done \ No newline at end of file