[PATCH 04/15] git-note: (Plumbing) Add plumbing-level support for git notes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch declares and implements two functions:

1. for_each_note_ref() - for iterating over note references in refs/notes.
   This is analogous to for_each_tag_ref(), for_each_branch_ref() and
   for_each_remote_ref(), which is already present.

2. cleanup_notes_subdirs() - a convenience function for removing empty
   subdirectories from refs/notes. These subdirectories would otherwise be
   left behind after removing notes, or after packing note refs.

The above functions will be used by subsequent git-note patches.

Signed-off-by: Johan Herland <johan@xxxxxxxxxxx>
---
 refs.c |   20 ++++++++++++++++++++
 refs.h |    4 ++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/refs.c b/refs.c
index 2ae3235..f0abfcd 100644
--- a/refs.c
+++ b/refs.c
@@ -569,6 +569,11 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data)
 	return do_for_each_ref("refs/tags/", fn, 10, cb_data);
 }
 
+int for_each_note_ref(each_ref_fn fn, void *cb_data)
+{
+	return do_for_each_ref("refs/notes/", fn, 11, cb_data);
+}
+
 int for_each_branch_ref(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref("refs/heads/", fn, 11, cb_data);
@@ -1433,3 +1438,18 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_reflog("", fn, cb_data);
 }
+
+void cleanup_notes_subdirs ()
+{
+	DIR *dir = opendir(git_path("refs/notes/"));
+
+	if (dir) {
+		struct dirent *de;
+		while ((de = readdir(dir)) != NULL) {
+			if (de->d_name[0] == '.')
+				continue;
+			rmdir(git_path("refs/notes/%s", de->d_name));
+		}
+		closedir(dir);
+	}
+}
diff --git a/refs.h b/refs.h
index f234eb7..6175bfb 100644
--- a/refs.h
+++ b/refs.h
@@ -21,6 +21,7 @@ typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flag
 extern int head_ref(each_ref_fn, void *);
 extern int for_each_ref(each_ref_fn, void *);
 extern int for_each_tag_ref(each_ref_fn, void *);
+extern int for_each_note_ref(each_ref_fn, void *);
 extern int for_each_branch_ref(each_ref_fn, void *);
 extern int for_each_remote_ref(each_ref_fn, void *);
 
@@ -64,4 +65,7 @@ extern int rename_ref(const char *oldref, const char *newref, const char *logmsg
 /** resolve ref in nested "gitlink" repository */
 extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *result);
 
+/** clean up empty subdirs below "refs/notes/" */
+extern void cleanup_notes_subdirs();
+
 #endif /* REFS_H */
-- 
1.5.2.101.gee49f


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux