From: Oleg Nesterov <oleg@redhat.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "René Scharfe" <l.s.r@web.de>,
git@vger.kernel.org, "Alexey Gladkov" <legion@kernel.org>
Subject: Re: [PATCH 1/1] git-grep: improve the --show-function behaviour
Date: Wed, 13 Sep 2023 11:46:39 +0200 [thread overview]
Message-ID: <20230913094638.GA535@redhat.com> (raw)
In-Reply-To: <xmqq1qf2lxrm.fsf@gitster.g>
I think I should trim CC to not spam the people who are not
interested in this discussion...
On 09/12, Junio C Hamano wrote:
>
> Documentation may not match the behaviour, but do we know what the
> behaviour we want is? To me, the last example that shows the same
> line twice (one as a real hit, the other because of "-p") looks a
> bit counter-intuitive for the purpose of "help me locate where the
> grep hits are". I dunno.
I have another opinion. To me the 2nd "=..." marker does help to
understand the hit location. But this doesn't matter.
Let me repeat: scripts.
I tried to explain this in 0/1 and in my other replies, but lets
start from the very beginning once again.
I've never used git-grep with -p/-n and most probably never will.
But 3 days ago my text editor (vi clone) started to use "grep -pn".
$ cat -n TEST.c
1 void func1(struct pid *);
2
3 void func2(struct pid *pid)
4 {
5 use1(pid);
6 }
7
8 void func3(struct pid *pid)
9 {
10 use2(pid);
11 }
when I do
:git-grep --untracked -pn pid TEST.c
in my editor it calls the script which parses the output from git-grep
and puts this
<pre>
<a href="TEST.c?1">TEST.c </a> 1 <b> </b> void func1(struct <i>pid</i> *);
<a href="TEST.c?3">TEST.c </a> 3 <b> </b> void func2(struct <i>pid</i> *<i>pid</i>)
<a href="TEST.c?5">TEST.c </a> 5 <b>func2 </b> use1(<i>pid</i>);
<a href="TEST.c?8">TEST.c </a> 8 <b> </b> void func3(struct <i>pid</i> *<i>pid</i>)
<a href="TEST.c?10">TEST.c </a> 10 <b>func3 </b> use2(<i>pid</i>);
</pre>
html to the text buffer which is nicely displayed as
TEST.c 1 void func1(struct pid *);
TEST.c 3 void func2(struct pid *pid)
TEST.c 5 func2 use1(pid);
TEST.c 8 void func3(struct pid *pid)
TEST.c 10 func3 use2(pid);
and I can use Ctrl-] to jump to the file/function/location.
And this script is very simple, it parses the output line-by-line. When
it sees the "=" marker it does some minimal post-processing, records the
function name to display it in the 3rd column later, and goes to the next
line.
But without my patch, in this case I get
TEST.c 1 void func1(struct pid *);
TEST.c 3 void func2(struct pid *pid)
TEST.c 5 use1(pid);
TEST.c 8 void func3(struct pid *pid)
TEST.c 10 use2(pid);
because the output from git-grep
$ git grep --untracked -pn pid TEST.c
TEST.c:1:void func1(struct pid *);
TEST.c:3:void func2(struct pid *pid)
TEST.c:5: use1(pid);
TEST.c:8:void func3(struct pid *pid)
TEST.c:10: use2(pid);
doesn't have the "=..." markers at all.
But TEST.c is just the trivial/artificial example. From 0/1,
When I do
:git-grep -pw pid kernel/sys.c
in my editor without this patch, I get
kernel/sys.c 224 sys_setpriority struct pid *pgrp;
kernel/sys.c 294 sys_getpriority struct pid *pgrp;
kernel/sys.c 952 * Note, despite the name, this returns the tgid not the pid. The tgid and
kernel/sys.c 953 * the pid are identical unless CLONE_THREAD was specified on clone() in
kernel/sys.c 963 /* Thread ID - the internal kernel "pid" */
kernel/sys.c 977 sys_getppid int pid;
kernel/sys.c 980 sys_getppid pid = task_tgid_vnr(rcu_dereference(current->real_parent));
kernel/sys.c 983 sys_getppid return pid;
kernel/sys.c 1073 SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
kernel/sys.c 1077 sys_times struct pid *pgrp;
kernel/sys.c 1080 sys_times if (!pid)
kernel/sys.c 1081 sys_times pid = task_pid_vnr(group_leader);
kernel/sys.c 1083 sys_times pgid = pid;
kernel/sys.c 1094 sys_times p = find_task_by_vpid(pid);
kernel/sys.c 1120 sys_times if (pgid != pid) {
kernel/sys.c 1144 static int do_getpgid(pid_t pid)
kernel/sys.c 1147 sys_times struct pid *grp;
kernel/sys.c 1151 sys_times if (!pid)
kernel/sys.c 1155 sys_times p = find_task_by_vpid(pid);
kernel/sys.c 1172 SYSCALL_DEFINE1(getpgid, pid_t, pid)
kernel/sys.c 1174 sys_times return do_getpgid(pid);
kernel/sys.c 1186 SYSCALL_DEFINE1(getsid, pid_t, pid)
kernel/sys.c 1189 sys_getpgrp struct pid *sid;
kernel/sys.c 1193 sys_getpgrp if (!pid)
kernel/sys.c 1197 sys_getpgrp p = find_task_by_vpid(pid);
kernel/sys.c 1214 static void set_special_pids(struct pid *pid)
kernel/sys.c 1218 sys_getpgrp if (task_session(curr) != pid)
kernel/sys.c 1219 sys_getpgrp change_pid(curr, PIDTYPE_SID, pid);
kernel/sys.c 1221 sys_getpgrp if (task_pgrp(curr) != pid)
kernel/sys.c 1222 sys_getpgrp change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c 1228 ksys_setsid struct pid *sid = task_pid(group_leader);
kernel/sys.c 1684 SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
kernel/sys.c 1705 check_prlimit_permission tsk = pid ? find_task_by_vpid(pid) : current;
And only the first 5 funcnames are correct.
And note that this case is very simple too (I mostly use :git-grep to scan
the whole linux kernel tree), but even in this simple case I don't think it
makes sense to use "git-grep -pn" directly, the output is hardly readable
(at least to me) with or without my patch.
Oleg.
next prev parent reply other threads:[~2023-09-13 9:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 12:11 [PATCH 0/1] git-grep: improve the --show-function behaviour Oleg Nesterov
2023-09-11 12:12 ` [PATCH 1/1] " Oleg Nesterov
2023-09-11 20:11 ` René Scharfe
2023-09-11 21:54 ` Oleg Nesterov
2023-09-11 22:34 ` Junio C Hamano
2023-09-11 23:17 ` Oleg Nesterov
2023-09-12 13:04 ` Oleg Nesterov
2023-09-12 13:51 ` Oleg Nesterov
2023-09-12 18:07 ` René Scharfe
2023-09-13 0:31 ` Junio C Hamano
2023-09-13 9:46 ` Oleg Nesterov [this message]
2023-09-14 19:34 ` René Scharfe
2023-09-17 16:44 ` Oleg Nesterov
2023-09-14 19:34 ` René Scharfe
2023-09-13 10:15 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230913094638.GA535@redhat.com \
--to=oleg@redhat.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=legion@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).