Thread (57 messages) 57 messages, 4 authors, 2017-05-25

Re: [PATCH 3/7] dir: add method to check if a dir_entry lexically contains another

From: Stefan Beller <hidden>
Date: 2017-05-03 18:09:06

On Tue, May 2, 2017 at 8:29 PM, Samuel Lijin [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Introduce a method that allows us to check if one dir_entry corresponds
to a path which contains the path corresponding to another dir_entry.
---
 dir.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/dir.c b/dir.c
index 6bd0350e9..25cb9eadf 100644
--- a/dir.c
+++ b/dir.c
@@ -1852,6 +1852,14 @@ static int cmp_name(const void *p1, const void *p2)
        return name_compare(e1->name, e1->len, e2->name, e2->len);
 }

+// check if *out lexically contains *in
Thanks for adding a comment to describe what the function ought to do.

However our Coding style prefers

/* comments this way */

/*
 * or in case of multi-
 * line comments,
 * this way.
 */

I think one of the ancient compilers just dislikes // as comment style.
+static int check_contains(const struct dir_entry *out, const struct dir_entry *in)
+{
+       return (out->len < in->len) &&
+                       (out->name[out->len - 1] == '/') &&
+                       !memcmp(out->name, in->name, out->len);
+}
+
 static int treat_leading_path(struct dir_struct *dir,
                              const char *path, int len,
                              const struct pathspec *pathspec)
--
2.12.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help