git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Store EXC_FLAG_* values in unsigned integers
@ 2016-03-01 17:02 Saurav Sachidanand
  2016-03-01 18:26 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Saurav Sachidanand @ 2016-03-01 17:02 UTC (permalink / raw
  To: git; +Cc: Saurav Sachidanand

The values defined by the macro EXC_FLAG_* (1, 4, 8, 16) are
stored in fields of the structs "pattern" and “exclude”, some
functions arguments and a local variable.

No variable that holds these values uses its most significant
bit in any special way, as it’s value is either checked for a
variant of EXC_FLAG_* using the & operator
(flags & EXC_FLAG_NODIR), or assigned a value of 0 first
and then any one of {1, 4, 8, 16} using the | operator
(flags |= EXC_FLAG_NODIR). Hence, change the types of such
variables and fields to unsigned.

And while we’re at it, document "flags" of "exclude" to explicitly
state the values it’s supposed to take on.

Signed-off-by: Saurav Sachidanand <sauravsachidanand@gmail.com>
---

This is a patch for the suggested microproject for GSoC 2016, titled
"Use unsigned integral type for collection of bits." It’s the fourth
iteration of this patch that incorporates changes to the commit
message suggested by Moritz Neeb, Eric Sunshine and Junio C Hamano,
and to some function signatures suggested by Duy Nguyen. Thanks to
them for their feedback.

Previous versions of this patch:
1) http://thread.gmane.org/gmane.comp.version-control.git/286821
2) http://thread.gmane.org/gmane.comp.version-control.git/287387
3) http://thread.gmane.org/gmane.comp.version-control.git/287838

 attr.c | 2 +-
 dir.c  | 8 ++++----
 dir.h  | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/attr.c b/attr.c
index 086c08d..679e13c 100644
--- a/attr.c
+++ b/attr.c
@@ -124,7 +124,7 @@ struct pattern {
 	const char *pattern;
 	int patternlen;
 	int nowildcardlen;
-	int flags;		/* EXC_FLAG_* */
+	unsigned flags;		/* EXC_FLAG_* */
 };

 /*
diff --git a/dir.c b/dir.c
index 552af23..82cec7d 100644
--- a/dir.c
+++ b/dir.c
@@ -459,7 +459,7 @@ int no_wildcard(const char *string)

 void parse_exclude_pattern(const char **pattern,
 			   int *patternlen,
-			   int *flags,
+			   unsigned *flags,
 			   int *nowildcardlen)
 {
 	const char *p = *pattern;
@@ -500,7 +500,7 @@ void add_exclude(const char *string, const char *base,
 {
 	struct exclude *x;
 	int patternlen;
-	int flags;
+	unsigned flags;
 	int nowildcardlen;

 	parse_exclude_pattern(&string, &patternlen, &flags, &nowildcardlen);
@@ -811,7 +811,7 @@ void add_excludes_from_file(struct dir_struct *dir, const char *fname)

 int match_basename(const char *basename, int basenamelen,
 		   const char *pattern, int prefix, int patternlen,
-		   int flags)
+		   unsigned flags)
 {
 	if (prefix == patternlen) {
 		if (patternlen == basenamelen &&
@@ -836,7 +836,7 @@ int match_basename(const char *basename, int basenamelen,
 int match_pathname(const char *pathname, int pathlen,
 		   const char *base, int baselen,
 		   const char *pattern, int prefix, int patternlen,
-		   int flags)
+		   unsigned flags)
 {
 	const char *name;
 	int namelen;
diff --git a/dir.h b/dir.h
index 3ec3fb0..e942b50 100644
--- a/dir.h
+++ b/dir.h
@@ -28,7 +28,7 @@ struct exclude {
 	int nowildcardlen;
 	const char *base;
 	int baselen;
-	int flags;
+	unsigned flags;		/* EXC_FLAG_* */

 	/*
 	 * Counting starts from 1 for line numbers in ignore files,
@@ -229,10 +229,10 @@ struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname,
  * attr.c:path_matches()
  */
 extern int match_basename(const char *, int,
-			  const char *, int, int, int);
+			  const char *, int, int, unsigned);
 extern int match_pathname(const char *, int,
 			  const char *, int,
-			  const char *, int, int, int);
+			  const char *, int, int, unsigned);

 extern struct exclude *last_exclude_matching(struct dir_struct *dir,
 					     const char *name, int *dtype);
@@ -244,7 +244,7 @@ extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
 extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
 					  struct exclude_list *el, int check_index);
 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
-extern void parse_exclude_pattern(const char **string, int *patternlen, int *flags, int *nowildcardlen);
+extern void parse_exclude_pattern(const char **string, int *patternlen, unsigned *flags, int *nowildcardlen);
 extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
--
2.7.1.339.g0233b80

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Store EXC_FLAG_* values in unsigned integers
  2016-03-01 17:02 [PATCH] Store EXC_FLAG_* values in unsigned integers Saurav Sachidanand
@ 2016-03-01 18:26 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2016-03-01 18:26 UTC (permalink / raw
  To: Saurav Sachidanand; +Cc: git

Saurav Sachidanand <sauravsachidanand@gmail.com> writes:

> The values defined by the macro EXC_FLAG_* (1, 4, 8, 16) are
> stored in fields of the structs "pattern" and “exclude”, some
> functions arguments and a local variable.

It's a minor point, but it is somewhat irritating that "pattern" is
enclosed in a regular dq pair while "exclude" is in a fancy dq pair.
I think our log messages tend to prefer the regular ones.

No need to resend; thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-01 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 17:02 [PATCH] Store EXC_FLAG_* values in unsigned integers Saurav Sachidanand
2016-03-01 18:26 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).