Fossil SCM

Fix user's email being swapped with name in git export committer record.

ashepilko 2017-01-06 04:09 trunk
Commit 76d9a4555b56405d7d98b2e34fc12389dfe30899
1 file changed +90 -40
+90 -40
--- src/export.c
+++ src/export.c
@@ -39,78 +39,128 @@
3939
};
4040
#endif
4141
4242
/*
4343
** Output a "committer" record for the given user.
44
+** NOTE: the given user name may be an email itself.
4445
*/
4546
static void print_person(const char *zUser){
4647
static Stmt q;
4748
const char *zContact;
4849
char *zName;
4950
char *zEmail;
5051
int i, j;
52
+ int isBracketed, atEmailFirst, atEmailLast;
5153
5254
if( zUser==0 ){
5355
printf(" <unknown>");
5456
return;
5557
}
5658
db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
5759
db_bind_text(&q, ":user", zUser);
5860
if( db_step(&q)!=SQLITE_ROW ){
5961
db_reset(&q);
60
- for(i=0; zUser[i] && zUser[i]!='>' && zUser[i]!='<'; i++){}
61
- if( zUser[i]==0 ){
62
- printf(" %s <%s>", zUser, zUser);
63
- return;
64
- }
6562
zName = mprintf("%s", zUser);
6663
for(i=j=0; zName[i]; i++){
67
- if( zName[i]!='<' && zName[i]!='>' ){
64
+ if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
65
+ zName[j++] = zName[i];
66
+ }
67
+ }
68
+ zName[j] = 0;
69
+ printf(" %s <%s>", zName, zName);
70
+ free(zName);
71
+ return;
72
+ }
73
+
74
+ /*
75
+ ** We have contact information.
76
+ ** It may or may not contain an email address.
77
+ **
78
+ ** ASSUME:
79
+ ** - General case:"Name Unicoded" <[email protected]> other info
80
+ ** - If contact information contains more than an email address,
81
+ ** then the email address is enclosed between <>
82
+ ** - When only email address is specified, then it's stored verbatim
83
+ ** - When name part is absent or all-blanks, use zUser instead
84
+ */
85
+ zName = NULL;
86
+ zEmail = NULL;
87
+ zContact = db_column_text(&q, 0);
88
+ atEmailFirst = -1;
89
+ atEmailLast = -1;
90
+ isBracketed = 0;
91
+ for(i=0; zContact[i] && zContact[i]!='@'; i++){
92
+ if( zContact[i]=='<' ){
93
+ isBracketed = 1;
94
+ atEmailFirst = i+1;
95
+ }
96
+ else if( zContact[i]=='>' ){
97
+ isBracketed = 0;
98
+ atEmailFirst = i+1;
99
+ }
100
+ else if( zContact[i]==' ' && !isBracketed ){
101
+ atEmailFirst = i+1;
102
+ }
103
+ }
104
+ if( zContact[i]==0 ){
105
+ /* No email address found. Take as user info if not empty */
106
+ zName = mprintf("%s", zContact[0] ? zContact : zUser);
107
+ for(i=j=0; zName[i]; i++){
108
+ if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
68109
zName[j++] = zName[i];
69110
}
70111
}
71112
zName[j] = 0;
72
- printf(" %s <%s>", zName, zUser);
113
+
114
+ printf(" %s <%s>", zName, zName);
73115
free(zName);
74
- return;
75
- }
76
- /*
77
- ** We have contact information.
78
- ** It may or may not contain an email address.
79
- */
80
- zContact = db_column_text(&q, 0);
81
- for(i=0; zContact[i] && zContact[i]!='>' && zContact[i]!='<'; i++){}
82
- if( zContact[i]==0 ){
83
- /* No email address found. Take as user info if not empty */
84
- printf(" %s <%s>", zContact[0] ? zContact : zUser, zUser);
85116
db_reset(&q);
86117
return;
87118
}
88
- if( zContact[i]=='<' ){
89
- /*
90
- ** Found beginning of email address. Look for the end and extract
91
- ** the part.
92
- */
93
- zEmail = mprintf("%s", &zContact[i]);
94
- for(j=0; zEmail[j] && zEmail[j]!='>'; j++){}
95
- if( zEmail[j]=='>' ) zEmail[j+1] = 0;
96
- }else{
97
- /*
98
- ** Found an end marker for email, but nothing else.
99
- */
100
- zEmail = mprintf("<%s>", zUser);
101
- }
102
- /*
103
- ** Here zContact[i] either '<' or '>'. Extract the string _before_
104
- ** either as user name.
105
- */
106
- zName = mprintf("%.*s", i-1, zContact);
107
- for(i=j=0; zName[i]; i++){
108
- if( zName[i]!='"' ) zName[j++] = zName[i];
119
+ for(j=i+1; zContact[j] && zContact[j]!=' '; j++){
120
+ if( zContact[j]=='>' )
121
+ atEmailLast = j-1;
122
+ }
123
+ if ( atEmailLast==-1 ) atEmailLast = j-1;
124
+ if ( atEmailFirst==-1 ) atEmailFirst = 0; /* Found only email */
125
+
126
+ /*
127
+ ** Found beginning and end of email address.
128
+ ** Extract the address (trimmed and sanitized).
129
+ */
130
+ for(j=atEmailFirst; zContact[j] && zContact[j]==' '; j++){}
131
+ zEmail = mprintf("%.*s", atEmailLast-j+1, &zContact[j]);
132
+
133
+ for(i=j=0; zEmail[i]; i++){
134
+ if( zEmail[i]!='<' && zEmail[i]!='>' ){
135
+ zEmail[j++] = zEmail[i];
136
+ }
137
+ }
138
+ zEmail[j] = 0;
139
+
140
+ /*
141
+ ** When bracketed email, extract the string _before_
142
+ ** email as user name (may be enquoted).
143
+ ** If missing or all-blank name, use zUser.
144
+ */
145
+ if( isBracketed && (atEmailFirst-1) > 0){
146
+ for(i=atEmailFirst-2; i>=0 && zContact[i] && zContact[i]==' '; i--){}
147
+ if( i>=0 ){
148
+ for(j=0; j<i && zContact[j] && zContact[j]==' '; j++){}
149
+ zName = mprintf("%.*s", i-j+1, &zContact[j]);
150
+ }
151
+ }
152
+
153
+ if( zName==NULL ) zName = mprintf("%s", zUser);
154
+ for(i=j=0; zName[i]; i++){
155
+ if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
156
+ zName[j++] = zName[i];
157
+ }
109158
}
110159
zName[j] = 0;
111
- printf(" %s %s", zName, zEmail);
160
+
161
+ printf(" %s <%s>", zName, zEmail);
112162
free(zName);
113163
free(zEmail);
114164
db_reset(&q);
115165
}
116166
117167
--- src/export.c
+++ src/export.c
@@ -39,78 +39,128 @@
39 };
40 #endif
41
42 /*
43 ** Output a "committer" record for the given user.
 
44 */
45 static void print_person(const char *zUser){
46 static Stmt q;
47 const char *zContact;
48 char *zName;
49 char *zEmail;
50 int i, j;
 
51
52 if( zUser==0 ){
53 printf(" <unknown>");
54 return;
55 }
56 db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
57 db_bind_text(&q, ":user", zUser);
58 if( db_step(&q)!=SQLITE_ROW ){
59 db_reset(&q);
60 for(i=0; zUser[i] && zUser[i]!='>' && zUser[i]!='<'; i++){}
61 if( zUser[i]==0 ){
62 printf(" %s <%s>", zUser, zUser);
63 return;
64 }
65 zName = mprintf("%s", zUser);
66 for(i=j=0; zName[i]; i++){
67 if( zName[i]!='<' && zName[i]!='>' ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68 zName[j++] = zName[i];
69 }
70 }
71 zName[j] = 0;
72 printf(" %s <%s>", zName, zUser);
 
73 free(zName);
74 return;
75 }
76 /*
77 ** We have contact information.
78 ** It may or may not contain an email address.
79 */
80 zContact = db_column_text(&q, 0);
81 for(i=0; zContact[i] && zContact[i]!='>' && zContact[i]!='<'; i++){}
82 if( zContact[i]==0 ){
83 /* No email address found. Take as user info if not empty */
84 printf(" %s <%s>", zContact[0] ? zContact : zUser, zUser);
85 db_reset(&q);
86 return;
87 }
88 if( zContact[i]=='<' ){
89 /*
90 ** Found beginning of email address. Look for the end and extract
91 ** the part.
92 */
93 zEmail = mprintf("%s", &zContact[i]);
94 for(j=0; zEmail[j] && zEmail[j]!='>'; j++){}
95 if( zEmail[j]=='>' ) zEmail[j+1] = 0;
96 }else{
97 /*
98 ** Found an end marker for email, but nothing else.
99 */
100 zEmail = mprintf("<%s>", zUser);
101 }
102 /*
103 ** Here zContact[i] either '<' or '>'. Extract the string _before_
104 ** either as user name.
105 */
106 zName = mprintf("%.*s", i-1, zContact);
107 for(i=j=0; zName[i]; i++){
108 if( zName[i]!='"' ) zName[j++] = zName[i];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109 }
110 zName[j] = 0;
111 printf(" %s %s", zName, zEmail);
 
112 free(zName);
113 free(zEmail);
114 db_reset(&q);
115 }
116
117
--- src/export.c
+++ src/export.c
@@ -39,78 +39,128 @@
39 };
40 #endif
41
42 /*
43 ** Output a "committer" record for the given user.
44 ** NOTE: the given user name may be an email itself.
45 */
46 static void print_person(const char *zUser){
47 static Stmt q;
48 const char *zContact;
49 char *zName;
50 char *zEmail;
51 int i, j;
52 int isBracketed, atEmailFirst, atEmailLast;
53
54 if( zUser==0 ){
55 printf(" <unknown>");
56 return;
57 }
58 db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
59 db_bind_text(&q, ":user", zUser);
60 if( db_step(&q)!=SQLITE_ROW ){
61 db_reset(&q);
 
 
 
 
 
62 zName = mprintf("%s", zUser);
63 for(i=j=0; zName[i]; i++){
64 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
65 zName[j++] = zName[i];
66 }
67 }
68 zName[j] = 0;
69 printf(" %s <%s>", zName, zName);
70 free(zName);
71 return;
72 }
73
74 /*
75 ** We have contact information.
76 ** It may or may not contain an email address.
77 **
78 ** ASSUME:
79 ** - General case:"Name Unicoded" <[email protected]> other info
80 ** - If contact information contains more than an email address,
81 ** then the email address is enclosed between <>
82 ** - When only email address is specified, then it's stored verbatim
83 ** - When name part is absent or all-blanks, use zUser instead
84 */
85 zName = NULL;
86 zEmail = NULL;
87 zContact = db_column_text(&q, 0);
88 atEmailFirst = -1;
89 atEmailLast = -1;
90 isBracketed = 0;
91 for(i=0; zContact[i] && zContact[i]!='@'; i++){
92 if( zContact[i]=='<' ){
93 isBracketed = 1;
94 atEmailFirst = i+1;
95 }
96 else if( zContact[i]=='>' ){
97 isBracketed = 0;
98 atEmailFirst = i+1;
99 }
100 else if( zContact[i]==' ' && !isBracketed ){
101 atEmailFirst = i+1;
102 }
103 }
104 if( zContact[i]==0 ){
105 /* No email address found. Take as user info if not empty */
106 zName = mprintf("%s", zContact[0] ? zContact : zUser);
107 for(i=j=0; zName[i]; i++){
108 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
109 zName[j++] = zName[i];
110 }
111 }
112 zName[j] = 0;
113
114 printf(" %s <%s>", zName, zName);
115 free(zName);
 
 
 
 
 
 
 
 
 
 
 
116 db_reset(&q);
117 return;
118 }
119 for(j=i+1; zContact[j] && zContact[j]!=' '; j++){
120 if( zContact[j]=='>' )
121 atEmailLast = j-1;
122 }
123 if ( atEmailLast==-1 ) atEmailLast = j-1;
124 if ( atEmailFirst==-1 ) atEmailFirst = 0; /* Found only email */
125
126 /*
127 ** Found beginning and end of email address.
128 ** Extract the address (trimmed and sanitized).
129 */
130 for(j=atEmailFirst; zContact[j] && zContact[j]==' '; j++){}
131 zEmail = mprintf("%.*s", atEmailLast-j+1, &zContact[j]);
132
133 for(i=j=0; zEmail[i]; i++){
134 if( zEmail[i]!='<' && zEmail[i]!='>' ){
135 zEmail[j++] = zEmail[i];
136 }
137 }
138 zEmail[j] = 0;
139
140 /*
141 ** When bracketed email, extract the string _before_
142 ** email as user name (may be enquoted).
143 ** If missing or all-blank name, use zUser.
144 */
145 if( isBracketed && (atEmailFirst-1) > 0){
146 for(i=atEmailFirst-2; i>=0 && zContact[i] && zContact[i]==' '; i--){}
147 if( i>=0 ){
148 for(j=0; j<i && zContact[j] && zContact[j]==' '; j++){}
149 zName = mprintf("%.*s", i-j+1, &zContact[j]);
150 }
151 }
152
153 if( zName==NULL ) zName = mprintf("%s", zUser);
154 for(i=j=0; zName[i]; i++){
155 if( zName[i]!='<' && zName[i]!='>' && zName[i]!='"' ){
156 zName[j++] = zName[i];
157 }
158 }
159 zName[j] = 0;
160
161 printf(" %s <%s>", zName, zEmail);
162 free(zName);
163 free(zEmail);
164 db_reset(&q);
165 }
166
167

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button