]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/am.c
builtin/am: introduce write_state_*() helper functions
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Aug 2015 16:12:53 +0000 (09:12 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Aug 2015 18:18:59 +0000 (11:18 -0700)
commit25b763ba7a544d05fc46ad601f3f9c50a4cea8b0
treeaf6b22fc2b3422382f38173ac7f4538553398d6f
parentb5e823594cff190bc18361207a89b08d57b038d7
builtin/am: introduce write_state_*() helper functions

There are many calls to write_file() that repeat the same pattern in
the implementation of the builtin version of "am".  They all share
the same traits, i.e they

 - produce a text file with a single string in it;

 - have enough information to produce the entire contents of that
   file;

 - generate the pathname of the file by making a call to am_path(); and

 - they ask write_file() to die() upon failure.

The slight differences among the call sites throw them into roughly
three categories:

 - many write either "t" or "f" based on a boolean value to a file;

 - some write the integer value in decimal text;

 - some others write more general string, e.g. an object name in
   hex, an empty string (i.e. the presense of the file itself serves
   as a flag), etc.

Introduce three helpers, write_state_bool(), write_state_count() and
write_state_text(), to reduce direct calls to write_file().

This is a preparatory step for the next step to ensure that no
"state" file this command leaves in $GIT_DIR is with an incomplete
line at the end.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c