]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chdir-notify: add function to unregister listeners
authorPatrick Steinhardt <ps@pks.im>
Wed, 19 Nov 2025 07:50:59 +0000 (08:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Nov 2025 20:16:00 +0000 (12:16 -0800)
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>
chdir-notify.c
chdir-notify.h

index 0d7bc0460747b2973f913b746c4b9ef0ba6b9028..f8bfe3cbef9aba4ec66d14c60a363fc58aff0874 100644 (file)
@@ -25,6 +25,24 @@ void chdir_notify_register(const char *name,
        list_add_tail(&e->list, &chdir_notify_entries);
 }
 
+void chdir_notify_unregister(const char *name, chdir_notify_callback cb,
+                            void *data)
+{
+       struct list_head *pos, *p;
+
+       list_for_each_safe(pos, p, &chdir_notify_entries) {
+               struct chdir_notify_entry *e =
+                       list_entry(pos, struct chdir_notify_entry, list);
+
+               if (e->cb != cb || e->data != data || !e->name != !name ||
+                   (e->name && strcmp(e->name, name)))
+                       continue;
+
+               list_del(pos);
+               free(e);
+       }
+}
+
 static void reparent_cb(const char *name,
                        const char *old_cwd,
                        const char *new_cwd,
index 366e4c1ee9908c46ac59bcf6fe9668ea44066aef..81eb69d846e45d18b23484c98c292ed5d996552f 100644 (file)
@@ -41,6 +41,8 @@ typedef void (*chdir_notify_callback)(const char *name,
                                      const char *new_cwd,
                                      void *data);
 void chdir_notify_register(const char *name, chdir_notify_callback cb, void *data);
+void chdir_notify_unregister(const char *name, chdir_notify_callback cb,
+                            void *data);
 void chdir_notify_reparent(const char *name, char **path);
 
 /*