Skip to content

Commit 2574c61

Browse files
pks-tgitster
authored andcommitted
chdir-notify: add function to unregister listeners
While we (obviously) have a way to register new listeners that get called whenever we chdir(3p), we don't have an equivalent that can be used to unregister such a listener again. Add one, as it will be required in a subsequent commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 35d9fc6 commit 2574c61

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

chdir-notify.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ void chdir_notify_register(const char *name,
2525
list_add_tail(&e->list, &chdir_notify_entries);
2626
}
2727

28+
void chdir_notify_unregister(const char *name, chdir_notify_callback cb,
29+
void *data)
30+
{
31+
struct list_head *pos, *p;
32+
33+
list_for_each_safe(pos, p, &chdir_notify_entries) {
34+
struct chdir_notify_entry *e =
35+
list_entry(pos, struct chdir_notify_entry, list);
36+
37+
if (e->cb != cb || e->data != data || !e->name != !name ||
38+
(e->name && strcmp(e->name, name)))
39+
continue;
40+
41+
list_del(pos);
42+
free(e);
43+
}
44+
}
45+
2846
static void reparent_cb(const char *name,
2947
const char *old_cwd,
3048
const char *new_cwd,

chdir-notify.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef void (*chdir_notify_callback)(const char *name,
4141
const char *new_cwd,
4242
void *data);
4343
void chdir_notify_register(const char *name, chdir_notify_callback cb, void *data);
44+
void chdir_notify_unregister(const char *name, chdir_notify_callback cb,
45+
void *data);
4446
void chdir_notify_reparent(const char *name, char **path);
4547

4648
/*

0 commit comments

Comments
 (0)