git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 0/8] Remove various dependencies from wrapper.o

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 6, 2010, 11:39 UTC
Message-ID
<20101106113905.GA27405@burratino>
Hi,

Ram noticed that using any function from strbuf.c results in a larger binary that requires -lz to link, which is pretty far from ideal. This patch series moves code around to make that no longer the case.

Vaguely inspired by [1].
After applying these patches, you can write:
	#define SHA1_HEADER "block-sha1/sha1.h"
	#include "cache.h"
	int main(void)
	{
		volatile char *p = xmalloc(5);
		return 0;
	}
and build it with
	cc -Wall -W test.c wrapper.o usage.o
-- no libz needed, no sha1 library, no environment.c, small binary.

Of course, making the linker happy tends to make the code clearer, too.

Patch 1 moves xmmap to sha1_file.c, where release_pack_memory() is defined. If xmmap were used by tiny programs, maybe it would make sense to replace release_pack_memory() with a callback, but this is simpler.

Patch 2 moves odb_mkstemp and odb_pack_keep to environment.c, were they have access to the cached value of $GIT_OBJECT_DIRECTORY.

Patch 3 moves git_mkstemps_mode et al from path.c to wrapper.c, so xmkstemp_mode does not have to depend on path.c.

Patch 4 moves some refname-related functions from strbuf.c to sha1_name.c.

Patch 5 moves git_inflate et al to a new zlib.c, so wrapper.o does not have to depend directly on libz.

Patch 6 is a missing "static" keyword. It probably doesn't belong in this series, but it fits okay.

Patch 7 moves try_to_free_builtin to sha1_file.c and adds a declaration for it to git-compat-util.h.

Patch 8 stops referring to try_to_free_builtin from wrapper.c, completing the project.

Thoughts?  Improvements?  Benchmarks?
[1] http://thread.gmane.org/gmane.comp.version-control.git/137686/focus=137737
Jonathan Nieder (8):
  wrapper: move xmmap() to sha1_file.c
  wrapper: move odb_* to environment.c
  path helpers: move git_mkstemp* to wrapper.c
  strbuf: move strbuf_branchname to sha1_name.c
  wrapper: give zlib wrappers their own translation unit
  pack-objects: mark file-local variable static
  wrapper: expose try_to_free_pack_memory()
  Remove pack file handling dependency from wrapper.o
 Makefile                                  |    1 +
 builtin/pack-objects.c                    |    2 +-
 check-racy.c                              |    1 +
 contrib/convert-objects/convert-objects.c |    1 +
 daemon.c                                  |    1 +
 environment.c                             |   37 ++++++
 fast-import.c                             |    1 +
 git-compat-util.h                         |    2 +
 git.c                                     |    2 +
 http-backend.c                            |    1 +
 http-fetch.c                              |    1 +
 http-push.c                               |    1 +
 imap-send.c                               |    1 +
 path.c                                    |  113 ----------------
 remote-curl.c                             |    1 +
 sha1_file.c                               |   20 +++
 sha1_name.c                               |   16 +++
 strbuf.c                                  |   16 ---
 test-dump-cache-tree.c                    |    4 +-
 test-match-trees.c                        |    1 +
 upload-pack.c                             |    1 +
 wrapper.c                                 |  198 ++++++++++++++--------------
 zlib.c                                    |   61 +++++++++
 23 files changed, 253 insertions(+), 230 deletions(-)
 create mode 100644 zlib.c
-- 
1.7.2.3.557.gab647.dirty
Next: Jonathan Nieder
Message 1 of 14 in “Remove various dependencies from wrapper.o”
  1. 0/8 Remove various dependencies from wrapper.oJonathan Nieder, Nov 6, 2010
  2. 1/8 wrapper: move xmmap() to sha1_file.cJonathan Nieder, Nov 6, 2010
  3. 2/8 wrapper: move odb_* to environment.cJonathan Nieder, Nov 6, 2010
  4. 3/8 path helpers: move git_mkstemp* to wrapper.cJonathan Nieder, Nov 6, 2010
  5. 4/8 strbuf: move strbuf_branchname to sha1_name.cJonathan Nieder, Nov 6, 2010
  6. 5/8 wrapper: give zlib wrappers their own translation unitJonathan Nieder, Nov 6, 2010
  7. 6/8 pack-objects: mark file-local variable staticJonathan Nieder, Nov 6, 2010
  8. 7/8 wrapper: expose try_to_free_pack_memory()Jonathan Nieder, Nov 6, 2010
  9. 8/8 Remove pack file handling dependency from wrapper.oJonathan Nieder, Nov 6, 2010
  10. René ScharfeNov 6, 2010
  11. Jonathan NiederNov 6, 2010
  12. René ScharfeNov 7, 2010
  13. Jonathan NiederNov 7, 2010
  14. Jonathan NiederNov 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.