Fri, 09 Dec 2016 15:20:22 -0800
doc it
180 | 1 | #!/usr/bin/env ruby |
2 | exit if ENV['CTAGS_SKIP'] | |
441 | 3 | ARGV.each { |o| exec('perldoc', $0) if o.match('help') } |
180 | 4 | |
440 | 5 | ctags = 'ctags' |
180 | 6 | |
7 | dir = `git rev-parse --show-toplevel`.chomp | |
8 | ||
9 | conf = "#{dir}/.git/ctags.conf" | |
10 | target = "#{dir}/.tags" | |
440 | 11 | tmp = "#{dir}/.tags.#{$$}~" |
180 | 12 | |
13 | opts = File.exists?(conf) ? "--options=#{conf}" : '' | |
14 | ||
187
84c6fa7ebc05
only wait 5 sec to try updating tags
Meredith Howard <mhoward@roomag.org>
parents:
180
diff
changeset
|
15 | sleep 5 if ENV['CTAGS_HOOK'] |
180 | 16 | |
440 | 17 | open(target, File::RDONLY|File::CREAT, 0644) do |f| |
180 | 18 | if ENV['CTAGS_HOOK'] |
440 | 19 | exit unless f.flock(File::LOCK_EX|File::LOCK_NB) |
20 | exit unless (Time.now - f.mtime) > 60 | |
180 | 21 | end |
22 | ||
440 | 23 | system(<<-CMD) or exit $?.exitstatus |
180 | 24 | git ls-files \ |
25 | | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \ | |
26 | && mv #{tmp} #{target} | |
27 | CMD | |
28 | end | |
29 | ||
441 | 30 | exit 0 |
180 | 31 | |
441 | 32 | <<'=cut' |
33 | =head1 NAME | |
180 | 34 | |
441 | 35 | git-ctags - run ctags on git tracked files |
36 | ||
37 | =head1 SYNOPSIS | |
38 | ||
39 | git ctags | |
40 | ||
41 | echo 'CTAGS_HOOK=1 git ctags &' >> .git/hooks/post-checkout | |
42 | ||
43 | git checkout some/branch | |
44 | CTAGS_SKIP=1 git checkout some/branch | |
45 | ||
46 | =head1 DESCRIPTION | |
47 | ||
48 | Create a .tags file (target) using git's list of tracked files. If | |
49 | C<.git/ctags.conf> exists in the repo it is passed to the ctags invocation. | |
50 | ||
51 | When run w/o env, immediately run ctags and replace tags file. | |
52 | ||
53 | When run with C<CTAGS_HOOK>, it's assumed to be a BG process and we want to | |
54 | wait for git to be done applying changes no matter how the hook is triggered. | |
55 | Wait five seconds, then bail if we can't get a lock on the tags file or if it's | |
56 | been updated within the last minute. Only then, run ctags and replace the tags | |
57 | file. | |
58 | ||
59 | =cut |