Skip to contentSkip to conversation

commit.c:record_author_date() use skip_prefix() instead of starts_with()

PATCH Superseded Tanay Abhra 4 participants 4 messages Jun 15, 2016

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commit.c:record_author_date() use skip_prefix() instead of starts_with()

---
 commit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commit.c +1 -1
index 6bf4fe0..c954ecb 100644
@@ -566,7 +566,7 @@ static void record_author_date(struct author_date_slab *author_date,
 	     buf;
 	     buf = line_end + 1) {
 		line_end = strchrnul(buf, '\n');
-		if (!starts_with(buf, "author ")) {
+		if (!skip_prefix(buf, "author ")) {
 			if (!line_end[0] || line_end[1] == '\n')
 				return; /* end of header */
 			continue;
Signature · 25 lines
1.7.9.5

Hello,

This is my patch for the GSoC microproject #10:

Rewrite commit.c:record_author_date() to use skip_prefix(). 
Are there other places in this file where skip_prefix() would be more 
readable than starts_with()?

Since skip_prefix() and starts_with() implement the same functionality with different
return values, they can be interchanged easily.

Other usage of starts_with() in the same file can be found with

$ grep -n starts_with commit.c

1116:		else if (starts_with(line, gpg_sig_header) &&
1196:		if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {

I have a query,should I tackle a bug from the mailing lists or research about the proposal 
and present a rough draft?

Cheers,
Tanay Abhra.
#1 lore raw

The format of this email is wrong. The non-commit-message notes should come between the "---" line (<- note, there are three minus signs here) and the patch itself.

Quoted 10 lines · Tanay Abhra
---
 commit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commit.c +0 -0
index 6bf4fe0..c954ecb 100644

commit.c static void record_author_date(struct author_date_slab *author_date, · line 569

Quoted 5 lines
commit.c +1 -1
@@ -566,7 +566,7 @@ static void record_author_date(struct author_date_slab *author_date,
 	     buf;
 	     buf = line_end + 1) {
 		line_end = strchrnul(buf, '\n');
-		if (!starts_with(buf, "author ")) {
+		if (!skip_prefix(buf, "author ")) {

If this is the only change, there is not much point, is there? How does this help? Perhaps there is some way to take advantage of the difference between starts_with() and skip_prefix() to simplify the rest of the function?

Quoted 23 lines
commit.c +0 -0
 			if (!line_end[0] || line_end[1] == '\n')
 				return; /* end of header */
 			continue;
Signature · 19 lines
1.7.9.5

Hello,

This is my patch for the GSoC microproject #10:

Rewrite commit.c:record_author_date() to use skip_prefix(). 
Are there other places in this file where skip_prefix() would be more 
readable than starts_with()?

Since skip_prefix() and starts_with() implement the same functionality with different
return values, they can be interchanged easily.

Other usage of starts_with() in the same file can be found with

$ grep -n starts_with commit.c

1116:		else if (starts_with(line, gpg_sig_header) &&
1196:		if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {

The rhetorical question that was part of this microproject was meant to inspire you to actually *FIX* the other spots, at least if the change makes sense.

Quoted 2 lines

I have a query,should I tackle a bug from the mailing lists or research about the proposal and present a rough draft?

My suggestion is that you follow up on this microproject until it is perfect before worrying too much about the next step.

Michael

Signature · 3 lines
Michael Haggerty
[email protected]
http://softwareswirl.blogspot.com/
#2 lore raw
Quoted 7 lines · Michael Haggerty

commit.c static void record_author_date(struct author_date_slab *author_date, · line 569

Quoted 2 lines
commit.c +1 -1
-		if (!starts_with(buf, "author ")) {
+		if (!skip_prefix(buf, "author ")) {

If this is the only change, there is not much point, is there? How does this help? Perhaps there is some way to take advantage of the difference between starts_with() and skip_prefix() to simplify the rest of the function?

I admit I lost track, but wasn't there a discussion to use starts_with/ends_with when appropriate (namely, the caller is absolutely not interested in what the remainder of the string is after skipping the prefix), moving away from skip_prefix()? Isn't this change going in the wrong direction?

#3 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Michael Haggerty

commit.c static void record_author_date(struct author_date_slab *author_date, · line 569

Quoted 2 lines
commit.c +1 -1
-            if (!starts_with(buf, "author ")) {
+            if (!skip_prefix(buf, "author ")) {

If this is the only change, there is not much point, is there? How does this help? Perhaps there is some way to take advantage of the difference between starts_with() and skip_prefix() to simplify the rest of the function?

Quoted 5 lines

I admit I lost track, but wasn't there a discussion to use starts_with/ends_with when appropriate (namely, the caller is absolutely not interested in what the remainder of the string is after skipping the prefix), moving away from skip_prefix()? Isn't this change going in the wrong direction?

Yes, it would be going in the wrong direction if this was all there was to it, but the particular GSoC microproject [1] which inspired this (incomplete) submission expects that the potential student will dig deeper and discover how skip_prefix() can be used to achieve greater simplification in record_author_date() and in other places in the same file.

[1]: https://github.com/git/git.github.io/blob/master/SoC-2014-Microprojects.md