git/builtin
Jeff King f932729cc7 memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:

  1. The return value is a static buffer, and the lifetime
     is dependent on other calls to git_path, etc.

  2. There's no compile-time checking of the pathname. This
     is OK for a one-off (after all, we have to spell it
     correctly at least once), but many of these constant
     strings appear throughout the code.

This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls.  cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.

Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.

Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.

Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:37:14 -07:00
..
add.c Merge branch 'nd/diff-i-t-a' 2015-06-25 10:47:46 -07:00
annotate.c annotate: use argv_array 2014-07-16 11:10:11 -07:00
apply.c Merge branch 'jc/apply-reject-noop-hunk' 2015-06-24 12:21:39 -07:00
archive.c replace {pre,suf}fixcmp() with {starts,ends}_with() 2013-12-05 14:13:21 -08:00
bisect--helper.c Replace deprecated OPT_BOOLEAN by OPT_BOOL 2013-08-05 11:32:19 -07:00
blame.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
branch.c delete_ref(): use the usual convention for old_sha1 2015-06-22 13:17:14 -07:00
bundle.c bundle: verify arguments more strictly 2015-05-08 10:52:11 -07:00
cat-file.c cat-file: sort and de-dup output of --batch-all-objects 2015-06-26 09:24:42 -07:00
check-attr.c standardize usage info string format 2015-01-14 09:32:04 -08:00
check-ignore.c standardize usage info string format 2015-01-14 09:32:04 -08:00
check-mailmap.c standardize usage info string format 2015-01-14 09:32:04 -08:00
check-ref-format.c standardize usage info string format 2015-01-14 09:32:04 -08:00
checkout-index.c prefix_path(): unconditionally free results in the callers 2015-05-05 10:31:51 -07:00
checkout.c Merge branch 'dt/refs-backend-preamble' 2015-08-03 11:01:29 -07:00
clean.c Merge branch 'rs/janitorial' into maint 2015-06-16 14:33:47 -07:00
clone.c get_repo_path: refactor path-allocation 2015-08-10 15:37:14 -07:00
column.c standardize usage info string format 2015-01-14 09:32:04 -08:00
commit-tree.c commit-tree: simplify parsing of option -S using skip_prefix() 2014-12-29 09:32:45 -08:00
commit.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
config.c Merge branch 'pt/xdg-config-path' into maint 2015-06-05 12:00:04 -07:00
count-objects.c count-objects: report unused files in $GIT_DIR/worktrees/... 2014-12-01 11:00:18 -08:00
credential.c
describe.c get_name(): rewrite to take an object_id argument 2015-05-25 12:19:29 -07:00
diff-files.c standardize usage info string format 2015-01-14 09:32:04 -08:00
diff-index.c standardize usage info string format 2015-01-14 09:32:04 -08:00
diff-tree.c standardize usage info string format 2015-01-14 09:32:04 -08:00
diff.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
fast-export.c refs: move the remaining ref module declarations to refs.h 2015-06-22 13:17:12 -07:00
fetch-pack.c standardize usage info string format 2015-01-14 09:32:04 -08:00
fetch.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
fmt-merge-msg.c refs: move the remaining ref module declarations to refs.h 2015-06-22 13:17:12 -07:00
for-each-ref.c for-each-ref: introduce filter_refs() 2015-08-03 10:24:07 -07:00
fsck.c prefer git_pathdup to git_path in some possibly-dangerous cases 2015-08-10 15:37:12 -07:00
gc.c Merge branch 'nd/multiple-work-trees' 2015-07-13 14:02:02 -07:00
get-tar-commit-id.c use skip_prefix() to avoid more magic numbers 2014-10-07 11:09:16 -07:00
grep.c Merge branch 'ps/grep-help-all-callback-arg' 2015-04-20 15:28:34 -07:00
hash-object.c Merge branch 'jc/hash-object' into maint 2015-05-26 13:49:25 -07:00
help.c Merge branch 'sb/leaks' 2015-03-20 13:11:53 -07:00
index-pack.c Merge branch 'js/fsck-opt' 2015-08-03 11:01:18 -07:00
init-db.c refs: move the remaining ref module declarations to refs.h 2015-06-22 13:17:12 -07:00
interpret-trailers.c trailer: add interpret-trailers command 2014-10-13 13:55:27 -07:00
log.c Merge branch 'jk/date-mode-format' 2015-08-03 11:01:27 -07:00
ls-files.c Merge branch 'jc/report-path-error-to-dir' into maint 2015-03-31 14:53:08 -07:00
ls-remote.c standardize usage info string format 2015-01-14 09:32:04 -08:00
ls-tree.c ls-tree: disable negative pathspec because it's not supported 2014-12-01 11:33:45 -08:00
mailinfo.c standardize usage info string format 2015-01-14 09:32:04 -08:00
mailsplit.c mailsplit: remove unnecessary unlink(2) call 2014-10-07 10:49:57 -07:00
merge-base.c standardize usage info string format 2015-01-14 09:32:04 -08:00
merge-file.c Merge branch 'ab/merge-file-prefix' 2015-02-22 12:28:25 -08:00
merge-index.c standardize usage info string format 2015-01-14 09:32:04 -08:00
merge-ours.c
merge-recursive.c replace {pre,suf}fixcmp() with {starts,ends}_with() 2013-12-05 14:13:21 -08:00
merge-tree.c merge-tree: remove unused df_conflict arguments 2014-09-02 11:02:58 -07:00
merge.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
mktag.c
mktree.c builtin/mktree.c: use ALLOC_GROW() in append_to_tree() 2014-03-03 14:54:45 -08:00
mv.c standardize usage info string format 2015-01-14 09:32:04 -08:00
name-rev.c name_ref(): rewrite to take an object_id argument 2015-05-25 12:19:29 -07:00
notes.c standardize usage info string format 2015-01-14 09:32:04 -08:00
pack-objects.c parse-options: move unsigned long option parsing out of pack-objects.c 2015-06-22 15:07:21 -07:00
pack-redundant.c standardize usage info string format 2015-01-14 09:32:04 -08:00
pack-refs.c standardize usage info string format 2015-01-14 09:32:04 -08:00
patch-id.c patch-id: convert to use struct object_id 2015-03-13 22:43:14 -07:00
prune-packed.c standardize usage info string format 2015-01-14 09:32:04 -08:00
prune.c Merge branch 'nd/multiple-work-trees' 2015-07-13 14:02:02 -07:00
pull.c pull: remove redirection to git-pull.sh 2015-06-18 13:18:59 -07:00
push.c push: allow --follow-tags to be set by config push.followTags 2015-03-14 15:08:35 -07:00
read-tree.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
receive-pack.c Merge branch 'jx/do-not-crash-receive-pack-wo-head' 2015-08-03 11:01:31 -07:00
reflog.c git-reflog: add exists command 2015-07-21 14:08:14 -07:00
remote-ext.c use skip_prefix() to avoid more magic numbers 2014-10-07 11:09:16 -07:00
remote-fd.c
remote.c remote.c: drop extraneous local variable from migrate_file 2015-08-10 15:37:12 -07:00
repack.c prefer mkpathdup to mkpath in assignments 2015-08-10 15:37:12 -07:00
replace.c Merge branch 'mh/replace-refs' 2015-08-03 11:01:10 -07:00
rerere.c standardize usage info string format 2015-01-14 09:32:04 -08:00
reset.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
rev-list.c Merge branch 'ls/hint-rev-list-count' 2015-07-10 14:26:13 -07:00
rev-parse.c rev-parse --parseopt: allow [*=?!] in argument hints 2015-07-15 10:30:54 -07:00
revert.c standardize usage info string format 2015-01-14 09:32:04 -08:00
rm.c use file_exists() to check if a file exists in the worktree 2015-05-20 13:49:10 -07:00
send-pack.c builtin/send-pack.c: respect user.signingkey 2015-07-21 15:24:27 -07:00
shortlog.c convert "enum date_mode" into a struct 2015-06-29 11:39:07 -07:00
show-branch.c convert "enum date_mode" into a struct 2015-06-29 11:39:07 -07:00
show-ref.c show_ref(): convert local variable peeled to object_id 2015-05-25 12:19:32 -07:00
stripspace.c builtin/stripspace.c: fix broken indentation 2013-09-06 13:33:17 -07:00
symbolic-ref.c standardize usage info string format 2015-01-14 09:32:04 -08:00
tag.c update-ref and tag: add --create-reflog arg 2015-07-21 14:08:35 -07:00
unpack-file.c
unpack-objects.c fsck (receive-pack): allow demoting errors to warnings 2015-06-23 14:27:34 -07:00
update-index.c Merge branch 'nd/untracked-cache' 2015-05-26 13:24:46 -07:00
update-ref.c Merge branch 'dt/refs-backend-preamble' 2015-08-03 11:01:29 -07:00
update-server-info.c i18n: update-server-info: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00
upload-archive.c replace {pre,suf}fixcmp() with {starts,ends}_with() 2013-12-05 14:13:21 -08:00
var.c
verify-commit.c verify-commit: add option to print raw gpg status information 2015-06-22 14:20:47 -07:00
verify-pack.c standardize usage info string format 2015-01-14 09:32:04 -08:00
verify-tag.c verify-tag: add option to print raw gpg status information 2015-06-22 14:20:47 -07:00
worktree.c Merge branch 'es/worktree-add' 2015-07-13 14:02:19 -07:00
write-tree.c i18n: write-tree: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00