<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/dir.c, branch v2.30.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.30.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.30.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2020-11-21T23:14:38Z</updated>
<entry>
<title>Merge branch 'en/strmap'</title>
<updated>2020-11-21T23:14:38Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-11-21T23:14:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bf0a430f70b53f94454692c9ae8ddadd18891aaa'/>
<id>urn:sha1:bf0a430f70b53f94454692c9ae8ddadd18891aaa</id>
<content type='text'>
A specialization of hashmap that uses a string as key has been
introduced.  Hopefully it will see wider use over time.

* en/strmap:
  shortlog: use strset from strmap.h
  Use new HASHMAP_INIT macro to simplify hashmap initialization
  strmap: take advantage of FLEXPTR_ALLOC_STR when relevant
  strmap: enable allocations to come from a mem_pool
  strmap: add a strset sub-type
  strmap: split create_entry() out of strmap_put()
  strmap: add functions facilitating use as a string-&gt;int map
  strmap: enable faster clearing and reusing of strmaps
  strmap: add more utility functions
  strmap: new utility functions
  hashmap: provide deallocation function names
  hashmap: introduce a new hashmap_partial_clear()
  hashmap: allow re-use after hashmap_free()
  hashmap: adjust spacing to fix argument alignment
  hashmap: add usage documentation explaining hashmap_free[_entries]()
</content>
</entry>
<entry>
<title>Merge branch 'nk/dir-c-comment-update'</title>
<updated>2020-11-02T21:17:42Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-11-02T21:17:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=03cd25ecbdaea419c7d07163c8930a658a4f44d2'/>
<id>urn:sha1:03cd25ecbdaea419c7d07163c8930a658a4f44d2</id>
<content type='text'>
Update stale in-code comment.

* nk/dir-c-comment-update:
  dir.c: fix comments to agree with argument name
</content>
</entry>
<entry>
<title>hashmap: provide deallocation function names</title>
<updated>2020-11-02T20:15:50Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2020-11-02T18:55:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6da1a258142ac2422c8c57c54b92eaed3c86226e'/>
<id>urn:sha1:6da1a258142ac2422c8c57c54b92eaed3c86226e</id>
<content type='text'>
hashmap_free(), hashmap_free_entries(), and hashmap_free_() have existed
for a while, but aren't necessarily the clearest names, especially with
hashmap_partial_clear() being added to the mix and lazy-initialization
now being supported.  Peff suggested we adopt the following names[1]:

  - hashmap_clear() - remove all entries and de-allocate any
    hashmap-specific data, but be ready for reuse

  - hashmap_clear_and_free() - ditto, but free the entries themselves

  - hashmap_partial_clear() - remove all entries but don't deallocate
    table

  - hashmap_partial_clear_and_free() - ditto, but free the entries

This patch provides the new names and converts all existing callers over
to the new naming scheme.

[1] https://lore.kernel.org/git/20201030125059.GA3277724@coredump.intra.peff.net/

Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>dir.c: fix comments to agree with argument name</title>
<updated>2020-10-16T15:40:27Z</updated>
<author>
<name>Alex Vandiver</name>
<email>alexmv@dropbox.com</email>
</author>
<published>2020-10-15T16:28:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e5cf6d3df4020748719312dcfde1412c6ff968a5'/>
<id>urn:sha1:e5cf6d3df4020748719312dcfde1412c6ff968a5</id>
<content type='text'>
Signed-off-by: Alex Vandiver &lt;alexmv@dropbox.com&gt;
Signed-off-by: Nipunn Koorapati &lt;nipunn@dropbox.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>dir.c: drop unused "untracked" from treat_path_fast()</title>
<updated>2020-09-30T19:53:48Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2020-09-30T12:35:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=842385b8a4fa56678f13cda599ee96463004e7bf'/>
<id>urn:sha1:842385b8a4fa56678f13cda599ee96463004e7bf</id>
<content type='text'>
We don't use the untracked_cache_dir parameter that is passed in, but
instead look at the untracked_cache_dir inside the cached_dir struct we
are passed. It's been this way since the introduction of
treat_path_fast() in 91a2288b5f (untracked cache: record/validate dir
mtime and reuse cached output, 2015-03-08).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/leakfix'</title>
<updated>2020-08-27T21:04:49Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-08-27T21:04:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0d9a8e33f9fd07efa10072576df01a9cae5d89e6'/>
<id>urn:sha1:0d9a8e33f9fd07efa10072576df01a9cae5d89e6</id>
<content type='text'>
Code clean-up.

* jk/leakfix:
  submodule--helper: fix leak of core.worktree value
  config: fix leak in git_config_get_expiry_in_days()
  config: drop git_config_get_string_const()
  config: fix leaks from git_config_get_string_const()
  checkout: fix leak of non-existent branch names
  submodule--helper: use strbuf_release() to free strbufs
  clear_pattern_list(): clear embedded hashmaps
</content>
</entry>
<entry>
<title>Merge branch 'en/dir-clear'</title>
<updated>2020-08-24T21:54:34Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-08-24T21:54:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ad00f44f5479441da59bd55261ae717fcb357938'/>
<id>urn:sha1:ad00f44f5479441da59bd55261ae717fcb357938</id>
<content type='text'>
Leakfix with code clean-up.

* en/dir-clear:
  dir: fix problematic API to avoid memory leaks
  dir: make clear_directory() free all relevant memory
</content>
</entry>
<entry>
<title>Merge branch 'en/dir-nonbare-embedded'</title>
<updated>2020-08-24T21:54:29Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-08-24T21:54:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=11f433f79c790bcb5feae71b0320161d7ab7dea7'/>
<id>urn:sha1:11f433f79c790bcb5feae71b0320161d7ab7dea7</id>
<content type='text'>
"ls-files -o" mishandled the top-level directory of another git
working tree that hangs in the current git working tree.

* en/dir-nonbare-embedded:
  dir: avoid prematurely marking nonbare repositories as matches
  t3000: fix some test description typos
</content>
</entry>
<entry>
<title>dir: fix problematic API to avoid memory leaks</title>
<updated>2020-08-19T00:17:31Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2020-08-18T22:58:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=eceba5321410bbcc9e0b11e6aa479832f574eca8'/>
<id>urn:sha1:eceba5321410bbcc9e0b11e6aa479832f574eca8</id>
<content type='text'>
The dir structure seemed to have a number of leaks and problems around
it.  First I noticed that parent_hashmap and recursive_hashmap were
being leaked (though Peff noticed and submitted fixes before me).  Then
I noticed in the previous commit that clear_directory() was only taking
responsibility for a subset of fields within dir_struct, despite the
fact that entries[] and ignored[] we allocated internally to dir.c.
That, of course, resulted in many callers either leaking or haphazardly
trying to free these arrays and their contents.

Digging further, I found that despite the pretty clear documentation
near the top of dir.h that folks were supposed to call clear_directory()
when the user no longer needed the dir_struct, there were four callers
that didn't bother doing that at all.  However, two of them clearly
thought about leaks since they had an UNLEAK(dir) directive, which to me
suggests that the method to free the data was too unclear.  I suspect
the non-obviousness of the API and its holes led folks to avoid it,
which then snowballed into further problems with the entries[],
ignored[], parent_hashmap, and recursive_hashmap problems.

Rename clear_directory() to dir_clear() to be more in line with other
data structures in git, and introduce a dir_init() to handle the
suggested memsetting of dir_struct to all zeroes.  I hope that a name
like "dir_clear()" is more clear, and that the presence of dir_init()
will provide a hint to those looking at the code that they need to look
for either a dir_clear() or a dir_free() and lead them to find
dir_clear().

Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>dir: make clear_directory() free all relevant memory</title>
<updated>2020-08-19T00:17:29Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2020-08-18T22:58:25Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dad4f23ce59339bb32ad9e1cc1682c696f7a724f'/>
<id>urn:sha1:dad4f23ce59339bb32ad9e1cc1682c696f7a724f</id>
<content type='text'>
The calling convention for the dir API is supposed to end with a call to
clear_directory() to free up no longer needed memory.  However,
clear_directory() didn't free dir-&gt;entries or dir-&gt;ignored.  I believe
this was an oversight, but a number of callers noticed memory leaks and
started free'ing these.  Unfortunately, they did so somewhat haphazardly
(sometimes freeing the entries in the arrays, and sometimes only
free'ing the arrays themselves).  This suggests the callers weren't
trying to make sure any possible memory used might be free'd, but just
the memory they noticed their usecase definitely had allocated.

Fix this mess by moving all the duplicated free'ing logic into
clear_directory().  End by resetting dir to a pristine state so it could
be reused if desired.

Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
