git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/14] Introduce a tempfile module
@ 2015-06-08  9:07 Michael Haggerty
  2015-06-08  9:07 ` [PATCH 01/14] Move lockfile API documentation to lockfile.h Michael Haggerty
                   ` (14 more replies)
  0 siblings, 15 replies; 26+ messages in thread
From: Michael Haggerty @ 2015-06-08  9:07 UTC (permalink / raw)
  To: Junio C Hamano, Jeff King; +Cc: git, Michael Haggerty

We have spent a lot of effort defining the state diagram for lockfiles
and ensuring correct, race-resistant cleanup in all circumstances. Now
let's abstract out part of the lockfile module so that it can be used
to clean up arbitrary temporary files.

This patch series

* implements a new "tempfile" module

* re-implements the "lockfile" module on top of tempfile

* changes a number of places in the code that manage temporary files
  to use the new module.

This project was suggested by Peff as a 2014 GSoC project [1], but
nobody took it up. It was not suggested again as a project for GSoC
2015.

There are still a number of other call sites that could be rewritten
to use the new module. But I think it's better to get the new module
out there and rewrite the other call sites as time allows rather than
for me to keep sitting on these patches in the naive hope that I will
get around to rewriting all possible users.

Patch 06/14 adds a number of mkstemp()-like functions that work with
tempfile objects rather than just returning paths. Since wrapper.c
already contains many variants of mkstemp()-like functions, the new
module does as well. These functions basically have four switches that
can be turned on/off independently:

* Can the caller specify the file mode of the new file?

* Does the filename template include a suffix?

* Does the filename template include the full path to the file, or is
  the file created in a temporary directory?

* Does the function die on failure?

Hopefully the new module will be easier to use, not only because it
takes care of cleaning the temporary file up automatically, but also
because its functions are named more systematically. The following
table might help people trying to make sense of things:

| wrapper function  | die? | location | suffix? | mode? | tempfile function |
| ----------------- | ---- | -------- | ------- | ----- | ----------------- |
| mkstemp           |      |          |         |       | mks_tempfile      |
| git_mkstemp_mode  |      |          |         | yes   | mks_tempfile_m    |
| mkstemps          |      |          | yes     |       | mks_tempfile_s    |
| gitmkstemps (†)   |      |          | yes     |       | mks_tempfile_s    |
| git_mkstemps_mode |      |          | yes     | yes   | mks_tempfile_sm   |
| git_mkstemp       |      | $TMPDIR  |         |       | mks_tempfile_t    |
| N/A               |      | $TMPDIR  |         | yes   | mks_tempfile_tm   |
| git_mkstemps      |      | $TMPDIR  | yes     |       | mks_tempfile_ts   |
| N/A               |      | $TMPDIR  | yes     | yes   | mks_tempfile_tsm  |
| xmkstemp          | yes  |          |         |       | xmks_tempfile     |
| xmkstemp_mode     | yes  |          |         | yes   | xmks_tempfile_m   |

If the large number of new functions is too intimidating (even though
most of the functions are inline), it would be possible to decrease
the number. For example, we could add a "flags" argument that covers
"location" and "die?". We could also get rid of the no-suffix
variants, requiring all callers to use the suffix variant, setting
suffixlen to 0 if no suffix is desired.

These patches are also available from my GitHub repo [2], branch
"tempfile".

[1] http://git.github.io/SoC-2014-Ideas.html
[2] https://github.com/mhagger/git

Michael Haggerty (14):
  Move lockfile API documentation to lockfile.h
  tempfile: a new module for handling temporary files
  lockfile: remove some redundant functions
  commit_lock_file(): use get_locked_file_path()
  register_tempfile_object(): new function, extracted from
    create_tempfile()
  tempfile: add several functions for creating temporary files
  register_tempfile(): new function to handle an existing temporary file
  write_shared_index(): use tempfile module
  setup_temporary_shallow(): use tempfile module
  diff: use tempfile module
  lock_repo_for_gc(): compute the path to "gc.pid" only once
  gc: use tempfile module to handle gc.pid file
  credential-cache--daemon: delete socket from main()
  credential-cache--daemon: use tempfile module

 Documentation/technical/api-lockfile.txt | 220 ----------------------
 Makefile                                 |   1 +
 builtin/add.c                            |   1 +
 builtin/apply.c                          |   1 +
 builtin/checkout-index.c                 |   1 +
 builtin/checkout.c                       |   1 +
 builtin/clone.c                          |   1 +
 builtin/commit.c                         |  15 +-
 builtin/describe.c                       |   1 +
 builtin/diff.c                           |   1 +
 builtin/gc.c                             |  32 +---
 builtin/merge.c                          |   1 +
 builtin/mv.c                             |   1 +
 builtin/read-tree.c                      |   1 +
 builtin/receive-pack.c                   |   1 +
 builtin/reflog.c                         |   1 +
 builtin/reset.c                          |   1 +
 builtin/rm.c                             |   1 +
 builtin/update-index.c                   |   1 +
 bundle.c                                 |   3 +-
 cache-tree.c                             |   1 +
 config.c                                 |  15 +-
 credential-cache--daemon.c               |  25 +--
 credential-store.c                       |   3 +-
 diff.c                                   |  29 +--
 fast-import.c                            |   3 +-
 fetch-pack.c                             |   1 +
 lockfile.c                               | 198 +++-----------------
 lockfile.h                               | 260 +++++++++++++++++++-------
 merge-recursive.c                        |   1 +
 merge.c                                  |   1 +
 read-cache.c                             |  42 +----
 refs.c                                   |  23 +--
 rerere.c                                 |   1 +
 sequencer.c                              |   1 +
 sha1_file.c                              |   1 +
 shallow.c                                |  41 +---
 tempfile.c                               | 231 +++++++++++++++++++++++
 tempfile.h                               | 310 +++++++++++++++++++++++++++++++
 test-scrap-cache-tree.c                  |   1 +
 40 files changed, 857 insertions(+), 617 deletions(-)
 delete mode 100644 Documentation/technical/api-lockfile.txt
 create mode 100644 tempfile.c
 create mode 100644 tempfile.h

-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-08-10  3:40 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-08  9:07 [PATCH 00/14] Introduce a tempfile module Michael Haggerty
2015-06-08  9:07 ` [PATCH 01/14] Move lockfile API documentation to lockfile.h Michael Haggerty
2015-06-08  9:07 ` [PATCH 02/14] tempfile: a new module for handling temporary files Michael Haggerty
2015-06-10 17:36   ` Junio C Hamano
2015-06-10 20:56     ` Michael Haggerty
2015-06-10 21:35       ` Junio C Hamano
2015-06-08  9:07 ` [PATCH 03/14] lockfile: remove some redundant functions Michael Haggerty
2015-06-10 17:40   ` Junio C Hamano
2015-06-10 18:27     ` Johannes Sixt
2015-06-08  9:07 ` [PATCH 04/14] commit_lock_file(): use get_locked_file_path() Michael Haggerty
2015-06-08  9:07 ` [PATCH 05/14] register_tempfile_object(): new function, extracted from create_tempfile() Michael Haggerty
2015-06-08  9:07 ` [PATCH 06/14] tempfile: add several functions for creating temporary files Michael Haggerty
2015-06-10 17:48   ` Junio C Hamano
2015-08-10  3:08     ` Michael Haggerty
2015-06-08  9:07 ` [PATCH 07/14] register_tempfile(): new function to handle an existing temporary file Michael Haggerty
2015-06-10 17:55   ` Junio C Hamano
2015-08-10  3:40     ` Michael Haggerty
2015-06-08  9:07 ` [PATCH 08/14] write_shared_index(): use tempfile module Michael Haggerty
2015-06-10 17:56   ` Junio C Hamano
2015-06-08  9:07 ` [PATCH 09/14] setup_temporary_shallow(): " Michael Haggerty
2015-06-08  9:07 ` [PATCH 10/14] diff: " Michael Haggerty
2015-06-08  9:07 ` [PATCH 11/14] lock_repo_for_gc(): compute the path to "gc.pid" only once Michael Haggerty
2015-06-08  9:07 ` [PATCH 12/14] gc: use tempfile module to handle gc.pid file Michael Haggerty
2015-06-08  9:07 ` [PATCH 13/14] credential-cache--daemon: delete socket from main() Michael Haggerty
2015-06-08  9:07 ` [PATCH 14/14] credential-cache--daemon: use tempfile module Michael Haggerty
2015-06-10 18:34 ` [PATCH 00/14] Introduce a " Junio C Hamano

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 NNTP newsgroup(s).