Thread (24 messages) flat view 24 messages, 2 authors, 2016-06-15
STALE3729d

Revision v1 of 3 in this series.

Revisions (3)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]

[PATCH 07/19] Provide access to the name attribute of git_attr

From: Michael Haggerty <hidden>
Date: 2016-06-15 22:51:39
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

It will be present in any likely future reimplementation, and its
availability simplifies other code.

Signed-off-by: Michael Haggerty <redacted>
---

struct git_attr is an opaque structure containing, among other things,
the name of the attribute that it represents.  This patch adds a
function git_attr_name(struct git_attr *) that allows the name to be
read from the structure.  This functionality will be convenient for
later patches.

This seems harmless to me.  It is hardly conceivable that the
implementation will change so dramatically that it becomes impossible
to derive the attribute name from the git_attr.

Please check that the name that I chose for this function conforms to
git conventions.

 Documentation/technical/api-gitattributes.txt |    3 ++-
 attr.c                                        |    4 ++++
 attr.h                                        |    7 +++++++
 3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/Documentation/technical/api-gitattributes.txt b/Documentation/technical/api-gitattributes.txt
index 916720f..ab3a84d 100644
--- a/Documentation/technical/api-gitattributes.txt
+++ b/Documentation/technical/api-gitattributes.txt
@@ -13,7 +13,8 @@ Data Structure
 	An attribute is an opaque object that is identified by its name.
 	Pass the name to `git_attr()` function to obtain the object of
 	this type.  The internal representation of this structure is
-	of no interest to the calling programs.
+	of no interest to the calling programs.  The name of the
+	attribute can be retrieved by calling `git_attr_name()`.
 
 `struct git_attr_check`::
 
diff --git a/attr.c b/attr.c
index b1d1d6d..a261550 100644
--- a/attr.c
+++ b/attr.c
@@ -36,6 +36,10 @@ static int attr_nr;
 static struct git_attr_check *check_all_attr;
 static struct git_attr *(git_attr_hash[HASHSIZE]);
 
+char *git_attr_name(struct git_attr *attr) {
+	return attr->name;
+}
+
 static unsigned hash_name(const char *name, int namelen)
 {
 	unsigned val = 0, c;
diff --git a/attr.h b/attr.h
index 8b3f19b..d4f875a 100644
--- a/attr.h
+++ b/attr.h
@@ -29,6 +29,13 @@ struct git_attr_check {
 	const char *value;
 };
 
+/*
+ * Return the name of the attribute represented by the argument.  The
+ * return value is a pointer to a null-delimited string that is part
+ * of the internal data structure; it should not be modified or freed.
+ */
+char *git_attr_name(struct git_attr *);
+
 int git_checkattr(const char *path, int, struct git_attr_check *);
 
 enum git_attr_direction {
-- 
1.7.6.8.gd2879
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help