Skip to content

Commit 27d5756

Browse files
jherlandgitster
authored andcommitted
Teach notes code to free its internal data structures on request
There's no need to be rude to memory-concious callers... This patch has been improved by the following contributions: - Junio C Hamano: avoid old-style declaration Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b208f0 commit 27d5756

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

notes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ static unsigned char *lookup_notes(const unsigned char *commit_sha1)
105105
return hash_map.entries[index].notes_sha1;
106106
}
107107

108+
void free_notes(void)
109+
{
110+
free(hash_map.entries);
111+
memset(&hash_map, 0, sizeof(struct hash_map));
112+
initialized = 0;
113+
}
114+
108115
void get_commit_notes(const struct commit *commit, struct strbuf *sb,
109116
const char *output_encoding, int flags)
110117
{

notes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef NOTES_H
22
#define NOTES_H
33

4+
/* Free (and de-initialize) the internal notes tree structure */
5+
void free_notes(void);
6+
47
#define NOTES_SHOW_HEADER 1
58
#define NOTES_INDENT 2
69

0 commit comments

Comments
 (0)