Re: [PATCH v14 01/11] trailer: add data structures and basic functions

4 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v14 01/11] trailer: add data structures and basic functions

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:02:31

Christian Couder [off-list ref] writes:
+/* Get the length of buf from its beginning until its last alphanumeric character */
That makes it sound as if feeding "abc%de#f@" to the function returns
3 for "abc", but
+static size_t alnum_len(const char *buf, size_t len)
+{
+	while (len > 0 && !isalnum(buf[len - 1]))
+		len--;
+	return len;
+}
doesn't it look at '@', be unhappy and decrement, look at 'f' and
break out to return the length of "abc%de#f"?

Perhaps that behaviour _is_ what you want, but then the comment is
lying, no?

Re: [PATCH v14 01/11] trailer: add data structures and basic functions

From: Christian Couder <hidden>
Date: 2016-06-15 23:02:32

On Mon, Sep 15, 2014 at 10:39 PM, Junio C Hamano [off-list ref] wrote:
Christian Couder [off-list ref] writes:
quoted
+/* Get the length of buf from its beginning until its last alphanumeric character */
That makes it sound as if feeding "abc%de#f@" to the function returns
3 for "abc", but
For me the last alphanumeric character in "abc%de#f@" is "f", so it is
the length from the beginning to "f" so it should return 8.
quoted
+static size_t alnum_len(const char *buf, size_t len)
+{
+     while (len > 0 && !isalnum(buf[len - 1]))
+             len--;
+     return len;
+}
doesn't it look at '@', be unhappy and decrement, look at 'f' and
break out to return the length of "abc%de#f"?
Yeah, that's the expected behavior.
Perhaps that behaviour _is_ what you want, but then the comment is
lying, no?
I don't think so, but maybe you are parsing the comment in a different
way than I am.
What would you suggest instead?

Thanks,
Christian.

Re: [PATCH v14 01/11] trailer: add data structures and basic functions

From: Jeff King <hidden>
Date: 2016-06-15 23:02:32

On Tue, Sep 16, 2014 at 10:01:11AM +0200, Christian Couder wrote:
On Mon, Sep 15, 2014 at 10:39 PM, Junio C Hamano [off-list ref] wrote:
quoted
Christian Couder [off-list ref] writes:
quoted
+/* Get the length of buf from its beginning until its last alphanumeric character */
That makes it sound as if feeding "abc%de#f@" to the function returns
3 for "abc", but
For me the last alphanumeric character in "abc%de#f@" is "f", so it is
the length from the beginning to "f" so it should return 8.
FWIW, I parsed the comment as you intended, but I do think it is a bit
unclear (especially given the name, as it is skipping over more than
just alnums). From reading the calling code, it looks like the intent is
to take a token string like "Signed-off-by:" and find that the ":" is
part of the ending punctuation, but that the "-" are retained as
internal punctuation.

Would it make sense as:

  /*
   * Return the length of the string not including any final
   * punctuation. E.g., the input "Signed-off-by:" would return
   * 13, stripping the trailing punctuation but retaining
   * internal punctuation.
   */
  int token_len_without_separator(const char *token)
  ...

The name is a bit clunky, but hopefully it is more clear what the point
is.

-Peff

Re: [PATCH v14 01/11] trailer: add data structures and basic functions

From: Christian Couder <hidden>
Date: 2016-06-15 23:02:32

On Wed, Sep 17, 2014 at 9:58 AM, Jeff King [off-list ref] wrote:
On Tue, Sep 16, 2014 at 10:01:11AM +0200, Christian Couder wrote:
quoted
On Mon, Sep 15, 2014 at 10:39 PM, Junio C Hamano [off-list ref] wrote:
quoted
Christian Couder [off-list ref] writes:
quoted
+/* Get the length of buf from its beginning until its last alphanumeric character */
That makes it sound as if feeding "abc%de#f@" to the function returns
3 for "abc", but
For me the last alphanumeric character in "abc%de#f@" is "f", so it is
the length from the beginning to "f" so it should return 8.
FWIW, I parsed the comment as you intended, but I do think it is a bit
unclear (especially given the name, as it is skipping over more than
just alnums). From reading the calling code, it looks like the intent is
to take a token string like "Signed-off-by:" and find that the ":" is
part of the ending punctuation, but that the "-" are retained as
internal punctuation.

Would it make sense as:

  /*
   * Return the length of the string not including any final
   * punctuation. E.g., the input "Signed-off-by:" would return
   * 13, stripping the trailing punctuation but retaining
   * internal punctuation.
   */
  int token_len_without_separator(const char *token)
  ...

The name is a bit clunky, but hopefully it is more clear what the point
is.
Ok, I will use that in the next version.

Thanks,
Christian.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help