From: Jeff King <peff@peff.net>
To: Peter.Dolland@mt.com
Cc: git@vger.kernel.org, notifications@github.com
Subject: Re: WG: [git-for-windows/git] log -L/<regex>/,+1 not accepted (#1856)
Date: Tue, 2 Oct 2018 10:43:42 -0400 [thread overview]
Message-ID: <20181002144342.GB24480@sigill.intra.peff.net> (raw)
In-Reply-To: <C19A54411B361046A786B5FA02D5689FE3B01FF9@ch00sem22.mt.mtnet>
On Tue, Oct 02, 2018 at 06:56:29AM +0000, Peter.Dolland@mt.com wrote:
> Please see my original observation below.
> Is it possible, to extend the git-log syntax in the way, that it
> accepts the short -L option (without :file) of blame in unique cases
> (only one file is logged or respectively the -L expression may be
> valid for all logged files)? It would be nice for command line users!
That would be nice, but I suspect in many cases the regex will be less
unique than you might hope. E.g., if you're looking for the log of a
particular function, you care about where it's defined. But unless you
write your regex very carefully, you're going to also match places where
it's called.
I have a hacky script (included below) that uses an already-built ctags
index to pick the correct file.
> Alternatively I could also imagine the extension of the blame
> functionality in the direction to see a whole history instead of only
> the last modification.
Have you tried using a blame interface that supports parent-reblaming
(i.e., once you blame a line to a particular commit, you can restart the
blame from that commit's parent, digging further into history each
time)? I use "tig blame" for this, and I find that I very rarely
actually turn to "log -L".
-Peff
-- >8 --
#!/usr/bin/env perl
if (!@ARGV) {
print STDERR "usage: git flog [options] <function>\n";
exit 1;
}
my $func = pop @ARGV;
my $file = get_file_from_tags($func);
my $regex = '[^A-Za-z_]' . $func . '[^A-Za-z0-9_]';
exec qw(git log), "-L:$regex:$file", @ARGV;
exit 1;
sub get_file_from_tags {
my $token = shift;
open(my $fh, '<', 'tags')
or die "unable to open tags: $!\n";
while (<$fh>) {
chomp;
# this isn't exactly right, as the Ex command may contain
# embedded tabs, but it's accurate for the token and filename,
# which come before, and probably good enough to match extension fields
# which come after
my @fields = split /\t/;
next unless $fields[0] eq $token;
# only look for functions; assumes your ctags uses the "kind"
# extension field. Note also that some implementations write the "kind:"
# header and some do not. This handles both.
next unless grep { /^(kind:\s*)?f$/ } @fields;
# there may be more, but we don't have any way of disambiguating,
# so just return the first match
return $fields[1];
}
die "unknown token: $token\n";
}
prev parent reply other threads:[~2018-10-02 14:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <git-for-windows/git/issues/1856@github.com>
[not found] ` <git-for-windows/git/issues/1856/426092877@github.com>
2018-10-02 6:56 ` WG: [git-for-windows/git] log -L/<regex>/,+1 not accepted (#1856) Peter.Dolland
2018-10-02 14:43 ` Jeff King [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181002144342.GB24480@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Peter.Dolland@mt.com \
--cc=git@vger.kernel.org \
--cc=notifications@github.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).