git/contrib/examples
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
..
builtin-fetch--tool.c memoize common git-path "constant" files 2015-08-10 15:37:14 -07:00
git-checkout.sh Merge branch 'ep/shell-command-substitution' 2014-04-21 10:42:42 -07:00
git-clean.sh Make git-clean a builtin 2007-11-18 19:11:42 -08:00
git-clone.sh contrib/examples/git-clone.sh: avoid "test <cond> -a/-o <cond>" 2014-06-09 14:47:06 -07:00
git-commit.sh contrib/examples/git-commit.sh: avoid "test <cond> -a/-o <cond>" 2014-06-09 14:47:06 -07:00
git-fetch.sh git-fetch.sh: use the $( ... ) construct for command substitution 2014-04-17 11:14:59 -07:00
git-gc.sh Supplant the "while case ... break ;; esac" idiom 2007-09-23 16:12:00 -07:00
git-log.sh core-tutorial: trim the section on Inspecting Changes 2013-08-13 09:01:52 -07:00
git-ls-remote.sh git-ls-remote.sh: use the $( ... ) construct for command substitution 2014-04-17 11:14:59 -07:00
git-merge-ours.sh Merge branch 'maint' 2007-11-28 17:06:57 -08:00
git-merge.sh contrib/examples/git-merge.sh: avoid "test <cond> -a/-o <cond>" 2014-06-09 14:47:06 -07:00
git-notes.sh Builtin-ify git-notes 2010-02-13 19:36:13 -08:00
git-pull.sh Merge branch 'pt/pull-builtin' 2015-08-03 11:01:17 -07:00
git-remote.perl contrib/examples/git-remote.perl: use a lowercase "usage:" string 2013-02-24 21:30:15 -08:00
git-repack.sh contrib/examples/git-repack.sh: avoid "test <cond> -a/-o <cond>" 2014-06-09 14:47:06 -07:00
git-rerere.perl Resurrect git-rerere to contrib/examples 2008-03-16 01:11:07 -07:00
git-reset.sh comments: fix misuses of "nor" 2014-03-31 15:29:27 -07:00
git-resolve.sh contrib/examples/git-resolve.sh: avoid "test <cond> -a/-o <cond>" 2014-06-09 14:47:06 -07:00
git-revert.sh git-revert.sh: use the $( ... ) construct for command substitution 2014-04-17 11:15:00 -07:00
git-svnimport.perl contrib/examples: use a lowercase "usage:" string 2013-02-24 13:31:09 -08:00
git-svnimport.txt various contrib: Fix links in man pages 2014-08-07 09:43:21 -07:00
git-tag.sh git-tag.sh: use the $( ... ) construct for command substitution 2014-04-17 11:15:00 -07:00
git-verify-tag.sh Supplant the "while case ... break ;; esac" idiom 2007-09-23 16:12:00 -07:00
git-whatchanged.sh repo-config: remove deprecated alias for "git config" 2013-11-12 14:10:17 -08:00
README contrib/examples/README: give an explanation of the status of these files 2009-01-12 17:47:36 -08:00

These are original scripted implementations, kept primarily for their
reference value to any aspiring plumbing users who want to learn how
pieces can be fit together.