| 1165 | } |
| 1166 | |
| 1167 | static int ident_to_worktree(const char *src, size_t len, |
| 1168 | struct strbuf *buf, int ident) |
| 1169 | { |
| 1170 | struct object_id oid; |
| 1171 | char *to_free = NULL; |
| 1172 | const char *dollar, *spc; |
| 1173 | int cnt; |
| 1174 | |
| 1175 | if (!ident) |
| 1176 | return 0; |
| 1177 | |
| 1178 | cnt = count_ident(src, len); |
| 1179 | if (!cnt) |
| 1180 | return 0; |
| 1181 | |
| 1182 | /* are we "faking" in place editing ? */ |
| 1183 | if (src == buf->buf) |
| 1184 | to_free = strbuf_detach(buf, NULL); |
| 1185 | hash_object_file(the_hash_algo, src, len, OBJ_BLOB, &oid); |
| 1186 | |
| 1187 | strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3)); |
| 1188 | for (;;) { |
| 1189 | /* step 1: run to the next '$' */ |
| 1190 | dollar = memchr(src, '$', len); |
| 1191 | if (!dollar) |
| 1192 | break; |
| 1193 | strbuf_add(buf, src, dollar + 1 - src); |
| 1194 | len -= dollar + 1 - src; |
| 1195 | src = dollar + 1; |
| 1196 | |
| 1197 | /* step 2: does it looks like a bit like Id:xxx$ or Id$ ? */ |
| 1198 | if (len < 3 || memcmp("Id", src, 2)) |
| 1199 | continue; |
| 1200 | |
| 1201 | /* step 3: skip over Id$ or Id:xxxxx$ */ |
| 1202 | if (src[2] == '$') { |
| 1203 | src += 3; |
| 1204 | len -= 3; |
| 1205 | } else if (src[2] == ':') { |
| 1206 | /* |
| 1207 | * It's possible that an expanded Id has crept its way into the |
| 1208 | * repository, we cope with that by stripping the expansion out. |
| 1209 | * This is probably not a good idea, since it will cause changes |
| 1210 | * on checkout, which won't go away by stash, but let's keep it |
| 1211 | * for git-style ids. |
| 1212 | */ |
| 1213 | dollar = memchr(src + 3, '$', len - 3); |
| 1214 | if (!dollar) { |
| 1215 | /* incomplete keyword, no more '$', so just quit the loop */ |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | if (memchr(src + 3, '\n', dollar - src - 3)) { |
| 1220 | /* Line break before the next dollar. */ |
| 1221 | continue; |
| 1222 | } |
| 1223 | |
| 1224 | spc = memchr(src + 4, ' ', dollar - src - 4); |
no test coverage detected