[PATCH 21/86] imap-send: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- imap-send.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/imap-send.c b/imap-send.c index 6f5cc4f..670de9f 100644 --- a/imap-send.c +++ b/imap-send.c @@ -1263,7 +1263,7 @@ static int count_messages(struct strbuf *all_msgs) char *p = all_msgs-buf; while (1) { - if (!prefixcmp(p, From )) { + if (has_prefix(p, From )) { p = strstr(p+5, \nFrom: ); if (!p) break; p = strstr(p+7, \nDate: ); @@ -1297,7 +1297,7 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs) data = all_msgs-buf[*ofs]; len = all_msgs-len - *ofs; - if (len 5 || prefixcmp(data, From )) + if (len 5 || !has_prefix(data, From )) return 0; p = strchr(data, '\n'); @@ -1339,13 +1339,13 @@ static int git_imap_config(const char *key, const char *val, void *cb) if (!strcmp(folder, key)) { imap_folder = xstrdup(val); } else if (!strcmp(host, key)) { - if (!prefixcmp(val, imap:)) + if (has_prefix(val, imap:)) val += 5; - else if (!prefixcmp(val, imaps:)) { + else if (has_prefix(val, imaps:)) { val += 6; server.use_ssl = 1; } - if (!prefixcmp(val, //)) + if (has_prefix(val, //)) val += 2; server.host = xstrdup(val); } else if (!strcmp(user, key)) -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 08/86] transport*: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- transport-helper.c | 16 transport.c| 28 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index b32e2d6..bf8d7a0 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport) data-export = 1; else if (!strcmp(capname, check-connectivity)) data-check_connectivity = 1; - else if (!data-refspecs !prefixcmp(capname, refspec )) { + else if (!data-refspecs has_prefix(capname, refspec )) { ALLOC_GROW(refspecs, refspec_nr + 1, refspec_alloc); @@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport) data-connect = 1; } else if (!strcmp(capname, signed-tags)) { data-signed_tags = 1; - } else if (!prefixcmp(capname, export-marks )) { + } else if (has_prefix(capname, export-marks )) { struct strbuf arg = STRBUF_INIT; strbuf_addstr(arg, --export-marks=); strbuf_addstr(arg, capname + strlen(export-marks )); data-export_marks = strbuf_detach(arg, NULL); - } else if (!prefixcmp(capname, import-marks)) { + } else if (has_prefix(capname, import-marks)) { struct strbuf arg = STRBUF_INIT; strbuf_addstr(arg, --import-marks=); strbuf_addstr(arg, capname + strlen(import-marks )); data-import_marks = strbuf_detach(arg, NULL); - } else if (!prefixcmp(capname, no-private-update)) { + } else if (has_prefix(capname, no-private-update)) { data-no_private_update = 1; } else if (mandatory) { die(Unknown mandatory capability %s. This remote @@ -310,7 +310,7 @@ static int set_helper_option(struct transport *transport, if (!strcmp(buf.buf, ok)) ret = 0; - else if (!prefixcmp(buf.buf, error)) { + else if (has_prefix(buf.buf, error)) { ret = -1; } else if (!strcmp(buf.buf, unsupported)) ret = 1; @@ -374,7 +374,7 @@ static int fetch_with_fetch(struct transport *transport, while (1) { recvline(data, buf); - if (!prefixcmp(buf.buf, lock )) { + if (has_prefix(buf.buf, lock )) { const char *name = buf.buf + 5; if (transport-pack_lockfile) warning(%s also locked %s, data-name, name); @@ -645,10 +645,10 @@ static int push_update_ref_status(struct strbuf *buf, char *refname, *msg; int status; - if (!prefixcmp(buf-buf, ok )) { + if (has_prefix(buf-buf, ok )) { status = REF_STATUS_OK; refname = buf-buf + 3; - } else if (!prefixcmp(buf-buf, error )) { + } else if (has_prefix(buf-buf, error )) { status = REF_STATUS_REMOTE_REJECT; refname = buf-buf + 6; } else diff --git a/transport.c b/transport.c index 7202b77..24b781c 100644 --- a/transport.c +++ b/transport.c @@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs, remotename = ref-name; tmp = resolve_ref_unsafe(localname, sha, 1, flag); if (tmp flag REF_ISSYMREF - !prefixcmp(tmp, refs/heads/)) + has_prefix(tmp, refs/heads/)) localname = tmp; /* Both source and destination must be local branches. */ - if (!localname || prefixcmp(localname, refs/heads/)) + if (!localname || !has_prefix(localname, refs/heads/)) continue; - if (!remotename || prefixcmp(remotename, refs/heads/)) + if (!remotename || !has_prefix(remotename, refs/heads/)) continue; if (!pretend) @@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, static const char *rsync_url(const char *url) { - return prefixcmp(url, rsync://) ? skip_prefix(url, rsync:) : url; + return !has_prefix(url, rsync://) ? skip_prefix(url, rsync:) : url; } static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) @@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1, FILE *f; /* when called via for_each_ref(), flags is non-zero
[PATCH 38/86] pager: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- pager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pager.c b/pager.c index fa19765..cd7bc43 100644 --- a/pager.c +++ b/pager.c @@ -151,7 +151,7 @@ int decimal_width(int number) static int pager_command_config(const char *var, const char *value, void *data) { struct pager_config *c = data; - if (!prefixcmp(var, pager.) !strcmp(var + 6, c-cmd)) { + if (has_prefix(var, pager.) !strcmp(var + 6, c-cmd)) { int b = git_config_maybe_bool(var, value); if (b = 0) c-want = b; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 42/86] pathspec: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- pathspec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pathspec.c b/pathspec.c index ad1a9f5..182b162 100644 --- a/pathspec.c +++ b/pathspec.c @@ -150,7 +150,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item, magic |= pathspec_magic[i].bit; break; } - if (!prefixcmp(copyfrom, prefix:)) { + if (has_prefix(copyfrom, prefix:)) { char *endptr; pathspec_prefix = strtol(copyfrom + 7, endptr, 10); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 15/86] fetch-pack: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- fetch-pack.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index a0e0350..1526ed1 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -176,9 +176,9 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd) */ char *line; while ((line = packet_read_line(fd, NULL))) { - if (!prefixcmp(line, shallow )) + if (has_prefix(line, shallow )) continue; - if (!prefixcmp(line, unshallow )) + if (has_prefix(line, unshallow )) continue; die(git fetch-pack: expected shallow list); } @@ -194,7 +194,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1) die(git fetch-pack: expected ACK/NAK, got EOF); if (!strcmp(line, NAK)) return NAK; - if (!prefixcmp(line, ACK )) { + if (has_prefix(line, ACK )) { if (!get_sha1_hex(line+4, result_sha1)) { if (len 45) return ACK; @@ -323,13 +323,13 @@ static int find_common(struct fetch_pack_args *args, send_request(args, fd[1], req_buf); while ((line = packet_read_line(fd[0], NULL))) { - if (!prefixcmp(line, shallow )) { + if (has_prefix(line, shallow )) { if (get_sha1_hex(line + 8, sha1)) die(invalid shallow line: %s, line); register_shallow(sha1); continue; } - if (!prefixcmp(line, unshallow )) { + if (has_prefix(line, unshallow )) { if (get_sha1_hex(line + 10, sha1)) die(invalid unshallow line: %s, line); if (!lookup_object(sha1)) @@ -523,7 +523,7 @@ static void filter_refs(struct fetch_pack_args *args, } if (!keep args-fetch_all - (!args-depth || prefixcmp(ref-name, refs/tags/))) + (!args-depth || !has_prefix(ref-name, refs/tags/))) keep = 1; if (keep) { -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 03/86] fast-import: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- fast-import.c | 80 +-- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/fast-import.c b/fast-import.c index f4d9969..14f69a1 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1877,8 +1877,8 @@ static int read_next_command(void) return EOF; if (!seen_data_command -prefixcmp(command_buf.buf, feature ) -prefixcmp(command_buf.buf, option )) { +!has_prefix(command_buf.buf, feature ) +!has_prefix(command_buf.buf, option )) { parse_argv(); } @@ -1898,7 +1898,7 @@ static int read_next_command(void) rc-prev-next = rc; cmd_tail = rc; } - if (!prefixcmp(command_buf.buf, cat-blob )) { + if (has_prefix(command_buf.buf, cat-blob )) { parse_cat_blob(); continue; } @@ -1917,7 +1917,7 @@ static void skip_optional_lf(void) static void parse_mark(void) { - if (!prefixcmp(command_buf.buf, mark :)) { + if (has_prefix(command_buf.buf, mark :)) { next_mark = strtoumax(command_buf.buf + 6, NULL, 10); read_next_command(); } @@ -1929,10 +1929,10 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res) { strbuf_reset(sb); - if (prefixcmp(command_buf.buf, data )) + if (!has_prefix(command_buf.buf, data )) die(Expected 'data n' command, found: %s, command_buf.buf); - if (!prefixcmp(command_buf.buf + 5, )) { + if (has_prefix(command_buf.buf + 5, )) { char *term = xstrdup(command_buf.buf + 5 + 2); size_t term_len = command_buf.len - 5 - 2; @@ -2306,7 +2306,7 @@ static void file_change_m(struct branch *b) if (*p == ':') { oe = find_mark(parse_mark_ref_space(p)); hashcpy(sha1, oe-idx.sha1); - } else if (!prefixcmp(p, inline )) { + } else if (has_prefix(p, inline )) { inline_data = 1; oe = NULL; /* not used with inline_data, but makes gcc happy */ p += strlen(inline); /* advance to space */ @@ -2479,7 +2479,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout) if (*p == ':') { oe = find_mark(parse_mark_ref_space(p)); hashcpy(sha1, oe-idx.sha1); - } else if (!prefixcmp(p, inline )) { + } else if (has_prefix(p, inline )) { inline_data = 1; oe = NULL; /* not used with inline_data, but makes gcc happy */ p += strlen(inline); /* advance to space */ @@ -2590,7 +2590,7 @@ static int parse_from(struct branch *b) const char *from; struct branch *s; - if (prefixcmp(command_buf.buf, from )) + if (!has_prefix(command_buf.buf, from )) return 0; if (b-branch_tree.tree) { @@ -2636,7 +2636,7 @@ static struct hash_list *parse_merge(unsigned int *count) struct branch *s; *count = 0; - while (!prefixcmp(command_buf.buf, merge )) { + while (has_prefix(command_buf.buf, merge )) { from = strchr(command_buf.buf, ' ') + 1; n = xmalloc(sizeof(*n)); s = lookup_branch(from); @@ -2687,11 +2687,11 @@ static void parse_new_commit(void) read_next_command(); parse_mark(); - if (!prefixcmp(command_buf.buf, author )) { + if (has_prefix(command_buf.buf, author )) { author = parse_ident(command_buf.buf + 7); read_next_command(); } - if (!prefixcmp(command_buf.buf, committer )) { + if (has_prefix(command_buf.buf, committer )) { committer = parse_ident(command_buf.buf + 10); read_next_command(); } @@ -2712,19 +2712,19 @@ static void parse_new_commit(void) /* file_change* */ while (command_buf.len 0) { - if (!prefixcmp(command_buf.buf, M )) + if (has_prefix(command_buf.buf, M )) file_change_m(b); - else if (!prefixcmp(command_buf.buf, D )) + else if (has_prefix(command_buf.buf, D )) file_change_d(b); - else if (!prefixcmp(command_buf.buf, R )) + else if (has_prefix(command_buf.buf, R )) file_change_cr(b, 1); - else if (!prefixcmp(command_buf.buf, C )) + else if (has_prefix(command_buf.buf, C )) file_change_cr(b, 0); - else if (!prefixcmp(command_buf.buf, N )) + else
[PATCH 68/86] builtin/name-rev: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/name-rev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 20fcf8c..2b74220 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -101,9 +101,9 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous) { if (shorten_unambiguous) refname = shorten_unambiguous_ref(refname, 0); - else if (!prefixcmp(refname, refs/heads/)) + else if (has_prefix(refname, refs/heads/)) refname = refname + 11; - else if (!prefixcmp(refname, refs/)) + else if (has_prefix(refname, refs/)) refname = refname + 5; return refname; } @@ -149,7 +149,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void int can_abbreviate_output = data-tags_only data-name_only; int deref = 0; - if (data-tags_only prefixcmp(path, refs/tags/)) + if (data-tags_only !has_prefix(path, refs/tags/)) return 0; if (data-ref_filter) { -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 62/86] builtin/init-db: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/init-db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/init-db.c b/builtin/init-db.c index 78aa387..7fe9d8c 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -266,7 +266,7 @@ static int create_default_files(const char *template_path) /* allow template config file to override the default */ if (log_all_ref_updates == -1) git_config_set(core.logallrefupdates, true); - if (prefixcmp(git_dir, work_tree) || + if (!has_prefix(git_dir, work_tree) || strcmp(git_dir + strlen(work_tree), /.git)) { git_config_set(core.worktree, work_tree); } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 75/86] builtin/rev-parse: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/rev-parse.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index c76b89d..b6c92e0 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -508,7 +508,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) } continue; } - if (!prefixcmp(arg, -n)) { + if (has_prefix(arg, -n)) { if ((filter DO_FLAGS) (filter DO_REVS)) show(arg); continue; @@ -560,7 +560,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, --short) || - !prefixcmp(arg, --short=)) { + has_prefix(arg, --short=)) { filter = ~(DO_FLAGS|DO_NOREV); verify = 1; abbrev = DEFAULT_ABBREV; @@ -588,7 +588,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) symbolic = SHOW_SYMBOLIC_FULL; continue; } - if (!prefixcmp(arg, --abbrev-ref) + if (has_prefix(arg, --abbrev-ref) (!arg[12] || arg[12] == '=')) { abbrev_ref = 1; abbrev_ref_strict = warn_ambiguous_refs; @@ -606,7 +606,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) for_each_ref(show_reference, NULL); continue; } - if (!prefixcmp(arg, --disambiguate=)) { + if (has_prefix(arg, --disambiguate=)) { for_each_abbrev(arg + 15, show_abbrev, NULL); continue; } @@ -615,7 +615,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) for_each_ref_in(refs/bisect/good, anti_reference, NULL); continue; } - if (!prefixcmp(arg, --branches=)) { + if (has_prefix(arg, --branches=)) { for_each_glob_ref_in(show_reference, arg + 11, refs/heads/, NULL); continue; @@ -624,7 +624,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) for_each_branch_ref(show_reference, NULL); continue; } - if (!prefixcmp(arg, --tags=)) { + if (has_prefix(arg, --tags=)) { for_each_glob_ref_in(show_reference, arg + 7, refs/tags/, NULL); continue; @@ -633,11 +633,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) for_each_tag_ref(show_reference, NULL); continue; } - if (!prefixcmp(arg, --glob=)) { + if (has_prefix(arg, --glob=)) { for_each_glob_ref(show_reference, arg + 7, NULL); continue; } - if (!prefixcmp(arg, --remotes=)) { + if (has_prefix(arg, --remotes=)) { for_each_glob_ref_in(show_reference, arg + 10, refs/remotes/, NULL); continue; @@ -724,19 +724,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) : false); continue; } - if (!prefixcmp(arg, --since=)) { + if (has_prefix(arg, --since=)) { show_datestring(--max-age=, arg+8); continue; } - if (!prefixcmp(arg, --after=)) { + if (has_prefix(arg, --after=)) { show_datestring(--max-age=, arg+8); continue; } - if (!prefixcmp(arg, --before=)) { + if (has_prefix(arg, --before=)) { show_datestring(--min-age=, arg+9
[PATCH 80/86] builtin/symbolic-ref: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/symbolic-ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index f481959..868fab4 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -65,7 +65,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) break; case 2: if (!strcmp(argv[0], HEAD) - prefixcmp(argv[1], refs/)) + !has_prefix(argv[1], refs/)) die(Refusing to point HEAD outside of refs/); create_symref(argv[0], argv[1], msg); break; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 82/86] builtin/tar-tree: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/tar-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/tar-tree.c b/builtin/tar-tree.c index ba3ffe6..7f225cc 100644 --- a/builtin/tar-tree.c +++ b/builtin/tar-tree.c @@ -34,7 +34,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix) nargv[nargc++] = archive; nargv[nargc++] = --format=tar; - if (2 = argc !prefixcmp(argv[1], --remote=)) { + if (2 = argc has_prefix(argv[1], --remote=)) { nargv[nargc++] = argv[1]; argv++; argc--; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 85/86] builtin/upload-archive: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/upload-archive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index af2da35..298bc76 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -37,7 +37,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) if (sent_argv.argc MAX_ARGS) die(Too many options (%d), MAX_ARGS - 1); - if (prefixcmp(buf, arg_cmd)) + if (!has_prefix(buf, arg_cmd)) die('argument' token or flush expected); argv_array_push(sent_argv, buf + strlen(arg_cmd)); } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 84/86] builtin/update-ref: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/update-ref.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 702e90d..d81d959 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -229,15 +229,15 @@ static void update_refs_stdin(void) die(empty command in input); else if (isspace(*cmd.buf)) die(whitespace before command: %s, cmd.buf); - else if (!prefixcmp(cmd.buf, update )) + else if (has_prefix(cmd.buf, update )) parse_cmd_update(cmd.buf + 7); - else if (!prefixcmp(cmd.buf, create )) + else if (has_prefix(cmd.buf, create )) parse_cmd_create(cmd.buf + 7); - else if (!prefixcmp(cmd.buf, delete )) + else if (has_prefix(cmd.buf, delete )) parse_cmd_delete(cmd.buf + 7); - else if (!prefixcmp(cmd.buf, verify )) + else if (has_prefix(cmd.buf, verify )) parse_cmd_verify(cmd.buf + 7); - else if (!prefixcmp(cmd.buf, option )) + else if (has_prefix(cmd.buf, option )) parse_cmd_option(cmd.buf + 7); else die(unknown command: %s, cmd.buf); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 86/86] strbuf: remove prefixcmp() as it has been replaced with has_prefix()
prefixcmp() is now useless as the previous commit replaced it everywhere with has_prefix(). So let's now remove it. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git-compat-util.h | 1 - strbuf.c | 9 - 2 files changed, 10 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index 7930f49..c5505e6 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -350,7 +350,6 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); -extern int prefixcmp(const char *str, const char *prefix); extern int has_prefix(const char *str, const char *prefix); extern int has_suffix(const char *str, const char *suffix); diff --git a/strbuf.c b/strbuf.c index 748be6d..199533c 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,15 +1,6 @@ #include cache.h #include refs.h -int prefixcmp(const char *str, const char *prefix) -{ - for (; ; str++, prefix++) - if (!*prefix) - return 0; - else if (*str != *prefix) - return (unsigned char)*prefix - (unsigned char)*str; -} - int has_prefix(const char *str, const char *prefix) { for (; ; str++, prefix++) -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 77/86] builtin/shortlog: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/shortlog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index c226f76..3f35682 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -65,7 +65,7 @@ static void insert_one_record(struct shortlog *log, eol = strchr(oneline, '\n'); if (!eol) eol = oneline + strlen(oneline); - if (!prefixcmp(oneline, [PATCH)) { + if (has_prefix(oneline, [PATCH)) { char *eob = strchr(oneline, ']'); if (eob (!eol || eob eol)) oneline = eob + 1; @@ -95,7 +95,7 @@ static void read_from_stdin(struct shortlog *log) while (fgets(author, sizeof(author), stdin) != NULL) { if (!(author[0] == 'A' || author[0] == 'a') || - prefixcmp(author + 1, uthor: )) + !has_prefix(author + 1, uthor: )) continue; while (fgets(oneline, sizeof(oneline), stdin) oneline[0] != '\n') @@ -123,7 +123,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) else eol++; - if (!prefixcmp(buffer, author )) + if (has_prefix(buffer, author )) author = buffer + 7; buffer = eol; } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 83/86] builtin/unpack-objects: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/unpack-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 2217d7b..dc2dd77 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -523,7 +523,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict = 1; continue; } - if (!prefixcmp(arg, --pack_header=)) { + if (has_prefix(arg, --pack_header=)) { struct pack_header *hdr; char *c; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 67/86] builtin/merge: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/merge.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 02a69c1..5c70cec 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -453,17 +453,17 @@ static void merge_name(const char *remote, struct strbuf *msg) die(_('%s' does not point to a commit), remote); if (dwim_ref(remote, strlen(remote), branch_head, found_ref) 0) { - if (!prefixcmp(found_ref, refs/heads/)) { + if (has_prefix(found_ref, refs/heads/)) { strbuf_addf(msg, %s\t\tbranch '%s' of .\n, sha1_to_hex(branch_head), remote); goto cleanup; } - if (!prefixcmp(found_ref, refs/tags/)) { + if (has_prefix(found_ref, refs/tags/)) { strbuf_addf(msg, %s\t\ttag '%s' of .\n, sha1_to_hex(branch_head), remote); goto cleanup; } - if (!prefixcmp(found_ref, refs/remotes/)) { + if (has_prefix(found_ref, refs/remotes/)) { strbuf_addf(msg, %s\t\tremote-tracking branch '%s' of .\n, sha1_to_hex(branch_head), remote); goto cleanup; @@ -577,8 +577,8 @@ static int git_merge_config(const char *k, const char *v, void *cb) { int status; - if (branch !prefixcmp(k, branch.) - !prefixcmp(k + 7, branch) + if (branch has_prefix(k, branch.) + has_prefix(k + 7, branch) !strcmp(k + 7 + strlen(branch), .mergeoptions)) { free(branch_mergeoptions); branch_mergeoptions = xstrdup(v); @@ -1113,7 +1113,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * current branch. */ branch = branch_to_free = resolve_refdup(HEAD, head_sha1, 0, flag); - if (branch !prefixcmp(branch, refs/heads/)) + if (branch has_prefix(branch, refs/heads/)) branch += 11; if (!branch || is_null_sha1(head_sha1)) head_commit = NULL; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 72/86] builtin/receive-pack: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/receive-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 67ce1ef..a4de530 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -428,7 +428,7 @@ static const char *update(struct command *cmd) struct ref_lock *lock; /* only refs/... are allowed */ - if (prefixcmp(name, refs/) || check_refname_format(name + 5, 0)) { + if (!has_prefix(name, refs/) || check_refname_format(name + 5, 0)) { rp_error(refusing to create funny ref '%s' remotely, name); return funny refname; } @@ -459,7 +459,7 @@ static const char *update(struct command *cmd) } if (!is_null_sha1(old_sha1) is_null_sha1(new_sha1)) { - if (deny_deletes !prefixcmp(name, refs/heads/)) { + if (deny_deletes has_prefix(name, refs/heads/)) { rp_error(denying ref deletion for %s, name); return deletion prohibited; } @@ -483,7 +483,7 @@ static const char *update(struct command *cmd) if (deny_non_fast_forwards !is_null_sha1(new_sha1) !is_null_sha1(old_sha1) - !prefixcmp(name, refs/heads/)) { + has_prefix(name, refs/heads/)) { struct object *old_object, *new_object; struct commit *old_commit, *new_commit; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 79/86] builtin/show-ref: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/show-ref.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 9f3f5e3..5e978aa 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -37,8 +37,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo if (tags_only || heads_only) { int match; - match = heads_only !prefixcmp(refname, refs/heads/); - match |= tags_only !prefixcmp(refname, refs/tags/); + match = heads_only has_prefix(refname, refs/heads/); + match |= tags_only has_prefix(refname, refs/tags/); if (!match) return 0; } @@ -210,7 +210,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) while (*pattern) { unsigned char sha1[20]; - if (!prefixcmp(*pattern, refs/) + if (has_prefix(*pattern, refs/) !read_ref(*pattern, sha1)) { if (!quiet) show_one(*pattern, sha1); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 69/86] builtin/notes: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/notes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/notes.c b/builtin/notes.c index d459e23..4bc7385 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -347,7 +347,7 @@ static struct notes_tree *init_notes_check(const char *subcommand) init_notes(NULL, NULL, NULL, 0); t = default_notes_tree; - if (prefixcmp(t-ref, refs/notes/)) + if (!has_prefix(t-ref, refs/notes/)) die(Refusing to %s notes in %s (outside of refs/notes/), subcommand, t-ref); return t; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 60/86] builtin/help: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/help.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index f1e236b..2478e9a 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -100,7 +100,7 @@ static int check_emacsclient_version(void) */ finish_command(ec_process); - if (prefixcmp(buffer.buf, emacsclient)) { + if (!has_prefix(buffer.buf, emacsclient)) { strbuf_release(buffer); return error(_(Failed to parse emacsclient version.)); } @@ -258,7 +258,7 @@ static int add_man_viewer_info(const char *var, const char *value) static int git_help_config(const char *var, const char *value, void *cb) { - if (!prefixcmp(var, column.)) + if (has_prefix(var, column.)) return git_column_config(var, value, help, colopts); if (!strcmp(var, help.format)) { if (!value) @@ -278,7 +278,7 @@ static int git_help_config(const char *var, const char *value, void *cb) add_man_viewer(value); return 0; } - if (!prefixcmp(var, man.)) + if (has_prefix(var, man.)) return add_man_viewer_info(var, value); return git_default_config(var, value, cb); @@ -306,7 +306,7 @@ static const char *cmd_to_page(const char *git_cmd) { if (!git_cmd) return git; - else if (!prefixcmp(git_cmd, git)) + else if (has_prefix(git_cmd, git)) return git_cmd; else if (is_git_command(git_cmd)) return prepend(git-, git_cmd); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 61/86] builtin/index-pack: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/index-pack.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9e9eb4b..183cf1f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1534,9 +1534,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) stat_only = 1; } else if (!strcmp(arg, --keep)) { keep_msg = ; - } else if (!prefixcmp(arg, --keep=)) { + } else if (has_prefix(arg, --keep=)) { keep_msg = arg + 7; - } else if (!prefixcmp(arg, --threads=)) { + } else if (has_prefix(arg, --threads=)) { char *end; nr_threads = strtoul(arg+10, end, 0); if (!arg[10] || *end || nr_threads 0) @@ -1547,7 +1547,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) ignoring %s), arg); nr_threads = 1; #endif - } else if (!prefixcmp(arg, --pack_header=)) { + } else if (has_prefix(arg, --pack_header=)) { struct pack_header *hdr; char *c; @@ -1566,7 +1566,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) if (index_name || (i+1) = argc) usage(index_pack_usage); index_name = argv[++i]; - } else if (!prefixcmp(arg, --index-version=)) { + } else if (has_prefix(arg, --index-version=)) { char *c; opts.version = strtoul(arg + 16, c, 10); if (opts.version 2) -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 81/86] builtin/tag: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/tag.c b/builtin/tag.c index ea55f1d..e72 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -259,7 +259,7 @@ static int git_tag_config(const char *var, const char *value, void *cb) int status = git_gpg_config(var, value, cb); if (status) return status; - if (!prefixcmp(var, column.)) + if (has_prefix(var, column.)) return git_column_config(var, value, tag, colopts); return git_default_config(var, value, cb); } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 74/86] builtin/remote: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/remote.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index b9a1024..e45358c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -261,7 +261,7 @@ static const char *abbrev_ref(const char *name, const char *prefix) static int config_read_branches(const char *key, const char *value, void *cb) { - if (!prefixcmp(key, branch.)) { + if (has_prefix(key, branch.)) { const char *orig_key = key; char *name; struct string_list_item *item; @@ -526,9 +526,9 @@ static int add_branch_for_removal(const char *refname, } /* don't delete non-remote-tracking refs */ - if (prefixcmp(refname, refs/remotes/)) { + if (!has_prefix(refname, refs/remotes/)) { /* advise user how to delete local branches */ - if (!prefixcmp(refname, refs/heads/)) + if (has_prefix(refname, refs/heads/)) string_list_append(branches-skipped, abbrev_branch(refname)); /* silently skip over other non-remote refs */ @@ -563,7 +563,7 @@ static int read_remote_branches(const char *refname, const char *symref; strbuf_addf(buf, refs/remotes/%s/, rename-old); - if (!prefixcmp(refname, buf.buf)) { + if (has_prefix(refname, buf.buf)) { item = string_list_append(rename-remote_branches, xstrdup(refname)); symref = resolve_ref_unsafe(refname, orig_sha1, 1, flag); if (flag REF_ISSYMREF) -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 66/86] builtin/merge-recursive: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/merge-recursive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index e7f1a39..73896dc 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -38,7 +38,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) for (i = 1; i argc; ++i) { const char *arg = argv[i]; - if (!prefixcmp(arg, --)) { + if (has_prefix(arg, --)) { if (!arg[2]) break; if (parse_merge_opt(o, arg + 2)) -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 73/86] builtin/reflog: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/reflog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 6eb24c8..f1a2578 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -610,12 +610,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; if (!strcmp(arg, --dry-run) || !strcmp(arg, -n)) cb.dry_run = 1; - else if (!prefixcmp(arg, --expire=)) { + else if (has_prefix(arg, --expire=)) { if (parse_expiry_date(arg + 9, cb.expire_total)) die(_('%s' is not a valid timestamp), arg); explicit_expiry |= EXPIRE_TOTAL; } - else if (!prefixcmp(arg, --expire-unreachable=)) { + else if (has_prefix(arg, --expire-unreachable=)) { if (parse_expiry_date(arg + 21, cb.expire_unreachable)) die(_('%s' is not a valid timestamp), arg); explicit_expiry |= EXPIRE_UNREACH; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 63/86] builtin/log: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/log.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 77d0f5f..054e663 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -390,7 +390,7 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_root = git_config_bool(var, value); return 0; } - if (!prefixcmp(var, color.decorate.)) + if (has_prefix(var, color.decorate.)) return parse_decorate_color_config(var, 15, value); if (!strcmp(var, log.mailmap)) { use_mailmap_config = git_config_bool(var, value); @@ -457,7 +457,7 @@ static int show_tag_object(const unsigned char *sha1, struct rev_info *rev) int new_offset = offset + 1; while (new_offset size buf[new_offset++] != '\n') ; /* do nothing */ - if (!prefixcmp(buf + offset, tagger )) + if (has_prefix(buf + offset, tagger )) show_tagger(buf + offset + 7, new_offset - offset - 7, rev); offset = new_offset; @@ -862,7 +862,7 @@ static char *find_branch_name(struct rev_info *rev) ref = rev-cmdline.rev[positive].name; tip_sha1 = rev-cmdline.rev[positive].item-sha1; if (dwim_ref(ref, strlen(ref), branch_sha1, full_ref) - !prefixcmp(full_ref, refs/heads/) + has_prefix(full_ref, refs/heads/) !hashcmp(tip_sha1, branch_sha1)) branch = xstrdup(full_ref + strlen(refs/heads/)); free(full_ref); @@ -1368,7 +1368,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) unsigned char sha1[20]; const char *ref; ref = resolve_ref_unsafe(HEAD, sha1, 1, NULL); - if (ref !prefixcmp(ref, refs/heads/)) + if (ref has_prefix(ref, refs/heads/)) branch_name = xstrdup(ref + strlen(refs/heads/)); else branch_name = xstrdup(); /* no branch */ -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 70/86] builtin/pack-objects: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/pack-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index e86cd57..45ee54a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2031,7 +2031,7 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo { unsigned char peeled[20]; - if (!prefixcmp(path, refs/tags/) /* is a tag? */ + if (has_prefix(path, refs/tags/) /* is a tag? */ !peel_ref(path, peeled) /* peelable? */ locate_object_entry(peeled)) /* object packed? */ add_object_entry(sha1, OBJ_TAG, NULL, 0); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 65/86] builtin/mailinfo: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/mailinfo.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 24a772d..c5da04c 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -328,11 +328,11 @@ static int check_header(const struct strbuf *line, } /* for inbody stuff */ - if (!prefixcmp(line-buf, From) isspace(line-buf[5])) { + if (has_prefix(line-buf, From) isspace(line-buf[5])) { ret = 1; /* Should this return 0? */ goto check_header_out; } - if (!prefixcmp(line-buf, [PATCH]) isspace(line-buf[7])) { + if (has_prefix(line-buf, [PATCH]) isspace(line-buf[7])) { for (i = 0; header[i]; i++) { if (!memcmp(Subject, header[i], 7)) { handle_header(hdr_data[i], line); @@ -361,7 +361,7 @@ static int is_rfc2822_header(const struct strbuf *line) char *cp = line-buf; /* Count mbox From headers as headers */ - if (!prefixcmp(cp, From ) || !prefixcmp(cp, From )) + if (has_prefix(cp, From ) || has_prefix(cp, From )) return 1; while ((ch = *cp++)) { @@ -671,11 +671,11 @@ static inline int patchbreak(const struct strbuf *line) size_t i; /* Beginning of a diff - header? */ - if (!prefixcmp(line-buf, diff -)) + if (has_prefix(line-buf, diff -)) return 1; /* CVS Index: line? */ - if (!prefixcmp(line-buf, Index: )) + if (has_prefix(line-buf, Index: )) return 1; /* @@ -685,7 +685,7 @@ static inline int patchbreak(const struct strbuf *line) if (line-len 4) return 0; - if (!prefixcmp(line-buf, ---)) { + if (has_prefix(line-buf, ---)) { /* space followed by a filename? */ if (line-buf[3] == ' ' !isspace(line-buf[4])) return 1; @@ -986,7 +986,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch) static int git_mailinfo_config(const char *var, const char *value, void *unused) { - if (prefixcmp(var, mailinfo.)) + if (!has_prefix(var, mailinfo.)) return git_default_config(var, value, unused); if (!strcmp(var, mailinfo.scissors)) { use_scissors = git_config_bool(var, value); @@ -1020,7 +1020,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) metainfo_charset = def_charset; else if (!strcmp(argv[1], -n)) metainfo_charset = NULL; - else if (!prefixcmp(argv[1], --encoding=)) + else if (has_prefix(argv[1], --encoding=)) metainfo_charset = argv[1] + 11; else if (!strcmp(argv[1], --scissors)) use_scissors = 1; -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 76/86] builtin/send-pack: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/send-pack.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 4482f16..0c29e69 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -115,15 +115,15 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) const char *arg = *argv; if (*arg == '-') { - if (!prefixcmp(arg, --receive-pack=)) { + if (has_prefix(arg, --receive-pack=)) { receivepack = arg + 15; continue; } - if (!prefixcmp(arg, --exec=)) { + if (has_prefix(arg, --exec=)) { receivepack = arg + 7; continue; } - if (!prefixcmp(arg, --remote=)) { + if (has_prefix(arg, --remote=)) { remote_name = arg + 9; continue; } @@ -181,7 +181,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) exit(1); continue; } - if (!prefixcmp(arg, -- CAS_OPT_NAME =)) { + if (has_prefix(arg, -- CAS_OPT_NAME =)) { if (parse_push_cas_option(cas, strchr(arg, '=') + 1, 0) 0) exit(1); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 64/86] builtin/ls-remote: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/ls-remote.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 25e83cf..9050072 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -50,11 +50,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; if (*arg == '-') { - if (!prefixcmp(arg, --upload-pack=)) { + if (has_prefix(arg, --upload-pack=)) { uploadpack = arg + 14; continue; } - if (!prefixcmp(arg, --exec=)) { + if (has_prefix(arg, --exec=)) { uploadpack = arg + 7; continue; } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 78/86] builtin/show-branch: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/show-branch.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 001f29c..dc0b406 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -285,7 +285,7 @@ static void show_one_commit(struct commit *commit, int no_name) pp_commit_easy(CMIT_FMT_ONELINE, commit, pretty); pretty_str = pretty.buf; } - if (!prefixcmp(pretty_str, [PATCH] )) + if (has_prefix(pretty_str, [PATCH] )) pretty_str += 8; if (!no_name) { @@ -396,7 +396,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f { unsigned char tmp[20]; int ofs = 11; - if (prefixcmp(refname, refs/heads/)) + if (!has_prefix(refname, refs/heads/)) return 0; /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. @@ -410,7 +410,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int { unsigned char tmp[20]; int ofs = 13; - if (prefixcmp(refname, refs/remotes/)) + if (!has_prefix(refname, refs/remotes/)) return 0; /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. @@ -422,7 +422,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { - if (prefixcmp(refname, refs/tags/)) + if (!has_prefix(refname, refs/tags/)) return 0; return append_ref(refname + 5, sha1, 0); } @@ -453,9 +453,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i return 0; if (fnmatch(match_ref_pattern, tail, 0)) return 0; - if (!prefixcmp(refname, refs/heads/)) + if (has_prefix(refname, refs/heads/)) return append_head_ref(refname, sha1, flag, cb_data); - if (!prefixcmp(refname, refs/tags/)) + if (has_prefix(refname, refs/tags/)) return append_tag_ref(refname, sha1, flag, cb_data); return append_ref(refname, sha1, 0); } @@ -480,11 +480,11 @@ static int rev_is_head(char *head, int headlen, char *name, if ((!head[0]) || (head_sha1 sha1 hashcmp(head_sha1, sha1))) return 0; - if (!prefixcmp(head, refs/heads/)) + if (has_prefix(head, refs/heads/)) head += 11; - if (!prefixcmp(name, refs/heads/)) + if (has_prefix(name, refs/heads/)) name += 11; - else if (!prefixcmp(name, heads/)) + else if (has_prefix(name, heads/)) name += 6; return !strcmp(head, name); } @@ -813,7 +813,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) has_head++; } if (!has_head) { - int offset = !prefixcmp(head, refs/heads/) ? 11 : 0; + int offset = has_prefix(head, refs/heads/) ? 11 : 0; append_one_rev(head + offset); } } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 71/86] builtin/prune: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/prune.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/prune.c b/builtin/prune.c index 6366917..59682ff 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -80,7 +80,7 @@ static int prune_dir(int i, char *path) prune_object(path, de-d_name, sha1); continue; } - if (!prefixcmp(de-d_name, tmp_obj_)) { + if (has_prefix(de-d_name, tmp_obj_)) { prune_tmp_object(path, de-d_name); continue; } @@ -119,7 +119,7 @@ static void remove_temporary_files(const char *path) return; } while ((de = readdir(dir)) != NULL) - if (!prefixcmp(de-d_name, tmp_)) + if (has_prefix(de-d_name, tmp_)) prune_tmp_object(path, de-d_name); closedir(dir); } -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 16/86] git: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index cb5208d..f077f49 100644 --- a/git.c +++ b/git.c @@ -54,7 +54,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) /* * Check remaining flags. */ - if (!prefixcmp(cmd, --exec-path)) { + if (has_prefix(cmd, --exec-path)) { cmd += 11; if (*cmd == '=') git_set_argv_exec_path(cmd + 1); @@ -92,7 +92,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged = 1; (*argv)++; (*argc)--; - } else if (!prefixcmp(cmd, --git-dir=)) { + } else if (has_prefix(cmd, --git-dir=)) { setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1); if (envchanged) *envchanged = 1; @@ -106,7 +106,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged = 1; (*argv)++; (*argc)--; - } else if (!prefixcmp(cmd, --namespace=)) { + } else if (has_prefix(cmd, --namespace=)) { setenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1); if (envchanged) *envchanged = 1; @@ -120,7 +120,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged = 1; (*argv)++; (*argc)--; - } else if (!prefixcmp(cmd, --work-tree=)) { + } else if (has_prefix(cmd, --work-tree=)) { setenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1); if (envchanged) *envchanged = 1; @@ -569,7 +569,7 @@ int main(int argc, char **av) * So we just directly call the internal command handler, and * die if that one cannot handle it. */ - if (!prefixcmp(cmd, git-)) { + if (has_prefix(cmd, git-)) { cmd += 4; argv[0] = cmd; handle_internal_command(argc, argv); @@ -581,7 +581,7 @@ int main(int argc, char **av) argc--; handle_options(argv, argc, NULL); if (argc 0) { - if (!prefixcmp(argv[0], --)) + if (has_prefix(argv[0], --)) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 22/86] help: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- help.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/help.c b/help.c index f068925..b41d2d5 100644 --- a/help.c +++ b/help.c @@ -148,7 +148,7 @@ static void list_commands_in_dir(struct cmdnames *cmds, while ((de = readdir(dir)) != NULL) { int entlen; - if (prefixcmp(de-d_name, prefix)) + if (!has_prefix(de-d_name, prefix)) continue; strbuf_setlen(buf, len); @@ -255,7 +255,7 @@ static int git_unknown_cmd_config(const char *var, const char *value, void *cb) if (!strcmp(var, help.autocorrect)) autocorrect = git_config_int(var,value); /* Also use aliases for command lookup */ - if (!prefixcmp(var, alias.)) + if (has_prefix(var, alias.)) add_cmdname(aliases, var + 6, strlen(var + 6)); return git_default_config(var, value, cb); @@ -329,7 +329,7 @@ const char *help_unknown_cmd(const char *cmd) if ((n ARRAY_SIZE(common_cmds)) !cmp) { /* Yes, this is one of the common commands */ n++; /* use the entry from common_cmds[] */ - if (!prefixcmp(candidate, cmd)) { + if (has_prefix(candidate, cmd)) { /* Give prefix match a very good score */ main_cmds.names[i]-len = 0; continue; @@ -414,7 +414,7 @@ static int append_similar_ref(const char *refname, const unsigned char *sha1, struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data); char *branch = strrchr(refname, '/') + 1; /* A remote branch of the same name is deemed similar */ - if (!prefixcmp(refname, refs/remotes/) + if (has_prefix(refname, refs/remotes/) !strcmp(branch, cb-base_ref)) string_list_append(cb-similar_refs, refname + strlen(refs/remotes/)); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 30/86] http-push: replace prefixcmd() with has_prefix()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- http-push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http-push.c b/http-push.c index 69200ba..0994344 100644 --- a/http-push.c +++ b/http-push.c @@ -771,7 +771,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) lock-owner = xmalloc(strlen(ctx-cdata) + 1); strcpy(lock-owner, ctx-cdata); } else if (!strcmp(ctx-name, DAV_ACTIVELOCK_TIMEOUT)) { - if (!prefixcmp(ctx-cdata, Second-)) + if (has_prefix(ctx-cdata, Second-)) lock-timeout = strtol(ctx-cdata + 7, NULL, 10); } else if (!strcmp(ctx-name, DAV_ACTIVELOCK_TOKEN)) { @@ -1579,7 +1579,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) return; /* If it's a symref, set the refname; otherwise try for a sha1 */ - if (!prefixcmp((char *)buffer.buf, ref: )) { + if (has_prefix((char *)buffer.buf, ref: )) { *symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6); } else { get_sha1_hex(buffer.buf, sha1); -- 1.8.4.1.566.geca833c -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
On Sat, Nov 9, 2013 at 3:24 PM, Thomas Rast t...@thomasrast.ch wrote: Christian Couder chrisc...@tuxfamily.org writes: Christian Couder (86): strbuf: add has_prefix() to be used instead of prefixcmp() diff: replace prefixcmd() with has_prefix() fast-import: replace prefixcmd() with has_prefix() [...] builtin/update-ref: replace prefixcmd() with has_prefix() builtin/upload-archive: replace prefixcmd() with has_prefix() strbuf: remove prefixcmp() as it has been replaced with has_prefix() All of your subjects except for the first and last say prefixcm*d*. :-) Yeah, sorry about that. Junio already sent me, with some others in cc, an email about this and I replied to all asking Junio if he wants me to resend with a fixed subject, but unfortunately the mailing list was not among the recipient of his email and my reply. Thanks and sorry again, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
From: Junio C Hamano gits...@pobox.com Even though we already added has_suffix() for tail matches, it is not too late to rethink, as it is not in 'master' yet. One thing I noticed is that it is probably misnamed, or at least in a way that invites confusion. Can people tell which one of these is correct without looking at existing callsites? has_suffix(filename, txt); has_suffix(filename, .txt); The semantics of the function we have is the latter and is better called endswith(), I suspect. And the corresponding function to check for head matches should probably be called beginswith(). I don't know if has_suffix() is confusing for a native speaker. After a look at some languages, Python has startwith() and endswith(), and Java has startWith() and endsWith(). So I agree that it is a good name. But while we are at it, why not ends_with() and begins_with()? To me using an underscore seems more consistent with what we are doing in Git. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
From: Junio C Hamano gits...@pobox.com Christian Couder chrisc...@tuxfamily.org writes: After a look at some languages, Python has startwith() and endswith(), and Java has startWith() and endsWith(). But while we are at it, why not ends_with() and begins_with()? To me using an underscore seems more consistent with what we are doing in Git. Sure. I do not think Peff and I were discussing at that level yet to debate between camelCase and words_with_underscore. We were mainly talking about what words to be used, which needs to come before the final appearance. Ok. By the way Ruby has start_with? and end_with?. So the thing we can discuss, if we go this way are: 1) with an s after the verb or not? 2) should we use start or begin? 3) with an underscore, nothing or camelCase My preference is: 1) with an s 2) start 3) underscore so that gives: starts_with() and ends_with() Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
From: Jeff King p...@peff.net On Wed, Nov 13, 2013 at 07:47:03AM +0100, Christian Couder wrote: My preference is: 1) with an s 2) start 3) underscore so that gives: starts_with() and ends_with() FWIW, that looks good to me, too. Whether there is confusion over the meaning of suffix or not, it makes sense, all other things being equal, to use the same terms as other popular languages. Like you, I prefer with an s, but we are deep in bikeshedding territory now. I can live with anything. :) When I prepared a new version of my patch series, this time to rename suffixcmp() to ends_with(), it appeared that we already have a static ends_with() function in vcs-svn/fast_export.c with another slightly different implementation :-) I will send a new version that will remove this redundant implementation. Cheers, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 2/2] Rename suffixcmp() to ends_with() and invert its result
Now ends_with() returns 1 when the suffix is present and 0 otherwise. The old name followed the pattern anything-cmp(), which suggests a general comparison function suitable for e.g. sorting objects. But this was not the case for suffixcmp(). Some popular programming languages have functions or methods called using end and with that are doing what we want. Therefore it makes sense to use ends_with() as a function name to replace suffixcmp(). And in vcs-svn/fast_export.c there was already an ends_with() function that did the same thing. Let's used the renamed one while at it. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/clone.c | 2 +- builtin/fetch.c | 2 +- builtin/merge-recursive.c | 2 +- builtin/remote.c | 6 +++--- builtin/repack.c | 2 +- connected.c | 2 +- git-compat-util.h | 2 +- strbuf.c | 6 +++--- vcs-svn/fast_export.c | 11 +-- 9 files changed, 13 insertions(+), 22 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 874e0fd..7c0c5cf 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -510,7 +510,7 @@ static void write_followtags(const struct ref *refs, const char *msg) for (ref = refs; ref; ref = ref-next) { if (prefixcmp(ref-name, refs/tags/)) continue; - if (!suffixcmp(ref-name, ^{})) + if (ends_with(ref-name, ^{})) continue; if (!has_sha1_file(ref-old_sha1)) continue; diff --git a/builtin/fetch.c b/builtin/fetch.c index bd7a101..0db2631 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -653,7 +653,7 @@ static void find_non_local_tags(struct transport *transport, * to fetch then we can mark the ref entry in the list * as one to ignore by setting util to NULL. */ - if (!suffixcmp(ref-name, ^{})) { + if (ends_with(ref-name, ^{})) { if (item !has_sha1_file(ref-old_sha1) !will_fetch(head, ref-old_sha1) !has_sha1_file(item-util) diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 3a64f5d..4111b98 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -29,7 +29,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) struct commit *result; init_merge_options(o); - if (argv[0] !suffixcmp(argv[0], -subtree)) + if (argv[0] ends_with(argv[0], -subtree)) o.subtree_shift = ; if (argc 4) diff --git a/builtin/remote.c b/builtin/remote.c index 9b3a98e..cd56542 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -269,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb) enum { REMOTE, MERGE, REBASE } type; key += 7; - if (!suffixcmp(key, .remote)) { + if (ends_with(key, .remote)) { name = xstrndup(key, strlen(key) - 7); type = REMOTE; - } else if (!suffixcmp(key, .merge)) { + } else if (ends_with(key, .merge)) { name = xstrndup(key, strlen(key) - 6); type = MERGE; - } else if (!suffixcmp(key, .rebase)) { + } else if (ends_with(key, .rebase)) { name = xstrndup(key, strlen(key) - 7); type = REBASE; } else diff --git a/builtin/repack.c b/builtin/repack.c index a0ff5c7..938bc75 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -78,7 +78,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list) return; while ((e = readdir(dir)) != NULL) { - if (suffixcmp(e-d_name, .pack)) + if (!ends_with(e-d_name, .pack)) continue; len = strlen(e-d_name) - strlen(.pack); diff --git a/connected.c b/connected.c index fae8d64..51d8ba4 100644 --- a/connected.c +++ b/connected.c @@ -38,7 +38,7 @@ int check_everything_connected_with_transport(sha1_iterate_fn fn, if (transport transport-smart_options transport-smart_options-self_contained_and_connected transport-pack_lockfile - !suffixcmp(transport-pack_lockfile, .keep)) { + ends_with(transport-pack_lockfile, .keep)) { struct strbuf idx_file = STRBUF_INIT; strbuf_addstr(idx_file, transport-pack_lockfile); strbuf_setlen(idx_file, idx_file.len - 5); /* .keep */ diff --git a/git-compat-util.h b/git-compat-util.h index 7776f12..37f0ba0 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -351,7 +351,7 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params
[PATCH v4 1/2] builtin/remote: remove postfixcmp() and use suffixcmp() instead
Commit 8cc5b290 (git merge -Xoption, 25 Nov 2009) introduced suffixcmp() with nearly the same implementation as postfixcmp() that already existed since commit 211c8968 (Make git-remote a builtin, 29 Feb 2008). The only difference between the two implementations is that, when the string is smaller than the suffix, one implementation returns 1 while the other one returns -1. But, as postfixcmp() is only used to compare for equality, the distinction does not matter and does not affect the correctness of this patch. As postfixcmp() has always been static in builtin/remote.c and is used nowhere else, it makes more sense to remove it and use suffixcmp() instead in builtin/remote.c, rather than to remove suffixcmp(). Reviewed-by: Jonathan Nieder jrnie...@gmail.com Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/remote.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 4e14891..9b3a98e 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -80,14 +80,6 @@ static int verbose; static int show_all(void); static int prune_remote(const char *remote, int dry_run); -static inline int postfixcmp(const char *string, const char *postfix) -{ - int len1 = strlen(string), len2 = strlen(postfix); - if (len1 len2) - return 1; - return strcmp(string + len1 - len2, postfix); -} - static int fetch_remote(const char *name) { const char *argv[] = { fetch, name, NULL, NULL }; @@ -277,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb) enum { REMOTE, MERGE, REBASE } type; key += 7; - if (!postfixcmp(key, .remote)) { + if (!suffixcmp(key, .remote)) { name = xstrndup(key, strlen(key) - 7); type = REMOTE; - } else if (!postfixcmp(key, .merge)) { + } else if (!suffixcmp(key, .merge)) { name = xstrndup(key, strlen(key) - 6); type = MERGE; - } else if (!postfixcmp(key, .rebase)) { + } else if (!suffixcmp(key, .rebase)) { name = xstrndup(key, strlen(key) - 7); type = REBASE; } else -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
On Sun, Nov 17, 2013 at 9:52 AM, Christian Couder chrisc...@tuxfamily.org wrote: From: Jeff King p...@peff.net On Wed, Nov 13, 2013 at 07:47:03AM +0100, Christian Couder wrote: My preference is: 1) with an s 2) start 3) underscore so that gives: starts_with() and ends_with() FWIW, that looks good to me, too. Whether there is confusion over the meaning of suffix or not, it makes sense, all other things being equal, to use the same terms as other popular languages. Like you, I prefer with an s, but we are deep in bikeshedding territory now. I can live with anything. :) When I prepared a new version of my patch series, this time to rename suffixcmp() to ends_with(), it appeared that we already have a static ends_with() function in vcs-svn/fast_export.c with another slightly different implementation :-) I will send a new version that will remove this redundant implementation. There is also a new version of my 86 patch long series to replace prefixcmp() with starts_with() that I am ready to send, but I hesitate to spam the whole list :-) I can put it somewhere like GitHub where people can see everything and perhaps send only a few patches to the list, including the first and the last. @Junio, how would you like me to proceed? Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 2/2] Rename suffixcmp() to ends_with() and invert its result
From: Jonathan Nieder jrnie...@gmail.com Christian Couder wrote: And in vcs-svn/fast_export.c there was already an ends_with() function that did the same thing. Let's used the renamed one while at it. Yes, despite the change in signature this shouldn't slow anything down. Thanks. For what it's worth, Reviewed-by: Jonathan Nieder jrnie...@gmail.com Thanks. To avoid spamming the list again, I am going to send the following patches from the 86 patch long series to replace prefixcmp() with starts_with(): [PATCH v2 00/86] replace prefixcmp() with starts_with() [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp() [PATCH v2 02/86] diff: replace prefixcmp() with starts_with() [PATCH v2 08/86] transport*: replace prefixcmp() with starts_with() [PATCH v2 40/86] environment: replace prefixcmp() with starts_with() [PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced with starts_with() If there are no problems with them, then I will suppose that most of the patches are ok and probably send them all unless I am asked not to. Cheers, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 02/86] diff: replace prefixcmp() with starts_with()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- diff.c | 56 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/diff.c b/diff.c index a04a34d..4b42997 100644 --- a/diff.c +++ b/diff.c @@ -235,7 +235,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) if (userdiff_config(var, value) 0) return -1; - if (!prefixcmp(var, diff.color.) || !prefixcmp(var, color.diff.)) { + if (starts_with(var, diff.color.) || starts_with(var, color.diff.)) { int slot = parse_diff_color_slot(var, 11); if (slot 0) return 0; @@ -264,7 +264,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) return 0; } - if (!prefixcmp(var, submodule.)) + if (starts_with(var, submodule.)) return parse_submodule_config_option(var, value); return git_default_config(var, value, cb); @@ -1215,7 +1215,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) diff_words_append(line, len, ecbdata-diff_words-plus); return; - } else if (!prefixcmp(line, \\ )) { + } else if (starts_with(line, \\ )) { /* * Eat the no newline at eof marker as if we * saw a + or - line with nothing on it, @@ -2387,9 +2387,9 @@ static void builtin_diff(const char *name_a, xdiff_set_find_func(xecfg, pe-pattern, pe-cflags); if (!diffopts) ; - else if (!prefixcmp(diffopts, --unified=)) + else if (starts_with(diffopts, --unified=)) xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10); - else if (!prefixcmp(diffopts, -u)) + else if (starts_with(diffopts, -u)) xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10); if (o-word_diff) init_diff_words_data(ecbdata, o, one, two); @@ -3388,7 +3388,7 @@ int parse_long_opt(const char *opt, const char **argv, if (arg[0] != '-' || arg[1] != '-') return 0; arg += strlen(--); - if (prefixcmp(arg, opt)) + if (!starts_with(arg, opt)) return 0; arg += strlen(opt); if (*arg == '=') { /* sticked form: --option=value */ @@ -3419,7 +3419,7 @@ static int stat_opt(struct diff_options *options, const char **av) switch (*arg) { case '-': - if (!prefixcmp(arg, -width)) { + if (starts_with(arg, -width)) { arg += strlen(-width); if (*arg == '=') width = strtoul(arg + 1, end, 10); @@ -3429,7 +3429,7 @@ static int stat_opt(struct diff_options *options, const char **av) width = strtoul(av[1], end, 10); argcount = 2; } - } else if (!prefixcmp(arg, -name-width)) { + } else if (starts_with(arg, -name-width)) { arg += strlen(-name-width); if (*arg == '=') name_width = strtoul(arg + 1, end, 10); @@ -3439,7 +3439,7 @@ static int stat_opt(struct diff_options *options, const char **av) name_width = strtoul(av[1], end, 10); argcount = 2; } - } else if (!prefixcmp(arg, -graph-width)) { + } else if (starts_with(arg, -graph-width)) { arg += strlen(-graph-width); if (*arg == '=') graph_width = strtoul(arg + 1, end, 10); @@ -3449,7 +3449,7 @@ static int stat_opt(struct diff_options *options, const char **av) graph_width = strtoul(av[1], end, 10); argcount = 2; } - } else if (!prefixcmp(arg, -count)) { + } else if (starts_with(arg, -count)) { arg += strlen(-count); if (*arg == '=') count = strtoul(arg + 1, end, 10); @@ -3611,15 +3611,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options-output_format |= DIFF_FORMAT_SHORTSTAT; else if (!strcmp(arg, -X) || !strcmp(arg, --dirstat)) return parse_dirstat_opt(options, ); - else if (!prefixcmp(arg, -X)) + else if (starts_with(arg, -X)) return parse_dirstat_opt(options, arg + 2); - else if (!prefixcmp(arg, --dirstat=)) + else if (starts_with(arg, --dirstat
[PATCH v2 00/86] replace prefixcmp() with starts_with()
Here is a resend of a big patch series to replace prefixcmp() with a new starts_with() function. The changes since the previous version are the following - the function to replace prefixcmp() is now starts_with() - the mispelling of prefixcmp() in the titles of the patches and emails is fixed The first patch of this series introduces starts_with() and the last patch removes prefixcmp(). Except a few patches, it's possible to generate the patches in between using a script like the following: === #!/bin/bash perl -pi -e 's/!prefixcmp\(/starts_with\(/g' $1 perl -pi -e 's/prefixcmp\(/!starts_with\(/g' $1 git commit -m $1: replace prefixcmp() with starts_with() $1 === The few special cases are the following ones: - remote*: replace prefixcmp() with starts_with() - transport*: replace prefixcmp() with starts_with() - environment: replace prefixcmp() with starts_with() In first 2 cases above, I processed a few files at the same time instead of just one. In the case of environment, I removed != 0 after !starts_with(...) as it is not necessary and makes it more difficult to understand the logic. Of course it's possible to squash many of the commits together if it is prefered. Christian Couder (86): strbuf: add starts_with() to be used instead of prefixcmp() diff: replace prefixcmp() with starts_with() fast-import: replace prefixcmp() with starts_with() remote*: replace prefixcmp() with starts_with() daemon: replace prefixcmp() with starts_with() pretty: replace prefixcmp() with starts_with() revision: replace prefixcmp() with starts_with() transport*: replace prefixcmp() with starts_with() config: replace prefixcmp() with starts_with() sha1_name: replace prefixcmp() with starts_with() wt-status: replace prefixcmp() with starts_with() upload-pack: replace prefixcmp() with starts_with() test-line-buffer: replace prefixcmp() with starts_with() parse-options: replace prefixcmp() with starts_with() fetch-pack: replace prefixcmp() with starts_with() git: replace prefixcmp() with starts_with() tag: replace prefixcmp() with starts_with() sequencer: replace prefixcmp() with starts_with() commit: replace prefixcmp() with starts_with() http: replace prefixcmp() with starts_with() imap-send: replace prefixcmp() with starts_with() help: replace prefixcmp() with starts_with() log-tree: replace prefixcmp() with starts_with() merge-recursive: replace prefixcmp() with starts_with() notes: replace prefixcmp() with starts_with() refs: replace prefixcmp() with starts_with() setup: replace prefixcmp() with starts_with() bisect: replace prefixcmp() with starts_with() branch: replace prefixcmp() with starts_with() http-push: replace prefixcmp() with starts_with() send-pack: replace prefixcmp() with starts_with() http-backend: replace prefixcmp() with starts_with() notes-utils: replace prefixcmp() with starts_with() pkt-line: replace prefixcmp() with starts_with() alias: replace prefixcmp() with starts_with() attr: replace prefixcmp() with starts_with() connect: replace prefixcmp() with starts_with() pager: replace prefixcmp() with starts_with() convert: replace prefixcmp() with starts_with() environment: replace prefixcmp() with starts_with() shell: replace prefixcmp() with starts_with() pathspec: replace prefixcmp() with starts_with() submodule: replace prefixcmp() with starts_with() test-string-list: replace prefixcmp() with starts_with() builtin/apply: replace prefixcmp() with starts_with() builtin/archive: replace prefixcmp() with starts_with() builtin/branch: replace prefixcmp() with starts_with() builtin/checkout: replace prefixcmp() with starts_with() builtin/clean: replace prefixcmp() with starts_with() builtin/clone: replace prefixcmp() with starts_with() builtin/column: replace prefixcmp() with starts_with() builtin/commit: replace prefixcmp() with starts_with() builtin/describe: replace prefixcmp() with starts_with() builtin/fast-export: replace prefixcmp() with starts_with() builtin/fetch-pack: replace prefixcmp() with starts_with() builtin/fetch: replace prefixcmp() with starts_with() builtin/fmt-merge-msg: replace prefixcmp() with starts_with() builtin/for-each-ref: replace prefixcmp() with starts_with() builtin/fsck: replace prefixcmp() with starts_with() builtin/help: replace prefixcmp() with starts_with() builtin/index-pack: replace prefixcmp() with starts_with() builtin/init-db: replace prefixcmp() with starts_with() builtin/log: replace prefixcmp() with starts_with() builtin/ls-remote: replace prefixcmp() with starts_with() builtin/mailinfo: replace prefixcmp() with starts_with() builtin/merge-recursive: replace prefixcmp() with starts_with() builtin/merge: replace prefixcmp() with starts_with() builtin/name-rev: replace prefixcmp() with starts_with() builtin/notes: replace prefixcmp() with starts_with
[PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp()
prefixcmp() cannot be really used as a comparison function as it is not antisymmetric: prefixcmp(foo, foobar) 0 prefixcmp(foobar, foo) == 0 So it is not suitable as a function for passing to qsort. And in fact it is used nowhere as a comparison function. So we should replace it with a function that just checks for equality. As a first step toward this goal, this patch introduces starts_with(). Some popular programming languages have functions or methods called using start and with that are doing what we want. Therefore it makes sense to use starts_with() as a function name to replace prefixcmp(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git-compat-util.h | 1 + strbuf.c | 9 + 2 files changed, 10 insertions(+) diff --git a/git-compat-util.h b/git-compat-util.h index 37f0ba0..e441a6b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -351,6 +351,7 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); extern int prefixcmp(const char *str, const char *prefix); +extern int starts_with(const char *str, const char *prefix); extern int ends_with(const char *str, const char *suffix); static inline const char *skip_prefix(const char *str, const char *prefix) diff --git a/strbuf.c b/strbuf.c index 2a14fdb..933d998 100644 --- a/strbuf.c +++ b/strbuf.c @@ -10,6 +10,15 @@ int prefixcmp(const char *str, const char *prefix) return (unsigned char)*prefix - (unsigned char)*str; } +int starts_with(const char *str, const char *prefix) +{ + for (; ; str++, prefix++) + if (!*prefix) + return 1; + else if (*str != *prefix) + return 0; +} + int ends_with(const char *str, const char *suffix) { int len = strlen(str), suflen = strlen(suffix); -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced with starts_with()
prefixcmp() is now useless as the previous commit replaced it everywhere with starts_with(). So let's now remove it. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git-compat-util.h | 1 - strbuf.c | 9 - 2 files changed, 10 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index e441a6b..c4c01e7 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -350,7 +350,6 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); -extern int prefixcmp(const char *str, const char *prefix); extern int starts_with(const char *str, const char *prefix); extern int ends_with(const char *str, const char *suffix); diff --git a/strbuf.c b/strbuf.c index 933d998..ee96dcf 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,15 +1,6 @@ #include cache.h #include refs.h -int prefixcmp(const char *str, const char *prefix) -{ - for (; ; str++, prefix++) - if (!*prefix) - return 0; - else if (*str != *prefix) - return (unsigned char)*prefix - (unsigned char)*str; -} - int starts_with(const char *str, const char *prefix) { for (; ; str++, prefix++) -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 08/86] transport*: replace prefixcmp() with starts_with()
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- transport-helper.c | 16 transport.c| 28 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index b32e2d6..96de26d 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport) data-export = 1; else if (!strcmp(capname, check-connectivity)) data-check_connectivity = 1; - else if (!data-refspecs !prefixcmp(capname, refspec )) { + else if (!data-refspecs starts_with(capname, refspec )) { ALLOC_GROW(refspecs, refspec_nr + 1, refspec_alloc); @@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport) data-connect = 1; } else if (!strcmp(capname, signed-tags)) { data-signed_tags = 1; - } else if (!prefixcmp(capname, export-marks )) { + } else if (starts_with(capname, export-marks )) { struct strbuf arg = STRBUF_INIT; strbuf_addstr(arg, --export-marks=); strbuf_addstr(arg, capname + strlen(export-marks )); data-export_marks = strbuf_detach(arg, NULL); - } else if (!prefixcmp(capname, import-marks)) { + } else if (starts_with(capname, import-marks)) { struct strbuf arg = STRBUF_INIT; strbuf_addstr(arg, --import-marks=); strbuf_addstr(arg, capname + strlen(import-marks )); data-import_marks = strbuf_detach(arg, NULL); - } else if (!prefixcmp(capname, no-private-update)) { + } else if (starts_with(capname, no-private-update)) { data-no_private_update = 1; } else if (mandatory) { die(Unknown mandatory capability %s. This remote @@ -310,7 +310,7 @@ static int set_helper_option(struct transport *transport, if (!strcmp(buf.buf, ok)) ret = 0; - else if (!prefixcmp(buf.buf, error)) { + else if (starts_with(buf.buf, error)) { ret = -1; } else if (!strcmp(buf.buf, unsupported)) ret = 1; @@ -374,7 +374,7 @@ static int fetch_with_fetch(struct transport *transport, while (1) { recvline(data, buf); - if (!prefixcmp(buf.buf, lock )) { + if (starts_with(buf.buf, lock )) { const char *name = buf.buf + 5; if (transport-pack_lockfile) warning(%s also locked %s, data-name, name); @@ -645,10 +645,10 @@ static int push_update_ref_status(struct strbuf *buf, char *refname, *msg; int status; - if (!prefixcmp(buf-buf, ok )) { + if (starts_with(buf-buf, ok )) { status = REF_STATUS_OK; refname = buf-buf + 3; - } else if (!prefixcmp(buf-buf, error )) { + } else if (starts_with(buf-buf, error )) { status = REF_STATUS_REMOTE_REJECT; refname = buf-buf + 6; } else diff --git a/transport.c b/transport.c index 7202b77..8023956 100644 --- a/transport.c +++ b/transport.c @@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs, remotename = ref-name; tmp = resolve_ref_unsafe(localname, sha, 1, flag); if (tmp flag REF_ISSYMREF - !prefixcmp(tmp, refs/heads/)) + starts_with(tmp, refs/heads/)) localname = tmp; /* Both source and destination must be local branches. */ - if (!localname || prefixcmp(localname, refs/heads/)) + if (!localname || !starts_with(localname, refs/heads/)) continue; - if (!remotename || prefixcmp(remotename, refs/heads/)) + if (!remotename || !starts_with(remotename, refs/heads/)) continue; if (!pretend) @@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, static const char *rsync_url(const char *url) { - return prefixcmp(url, rsync://) ? skip_prefix(url, rsync:) : url; + return !starts_with(url, rsync://) ? skip_prefix(url, rsync:) : url; } static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) @@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1, FILE *f; /* when called via for_each_ref(), flags is non-zero
Re: [PATCH v4 2/2] Rename suffixcmp() to ends_with() and invert its result
From: Junio C Hamano gits...@pobox.com Antoine Pelisse apeli...@gmail.com writes: I'm not exactly sure I understand the point of not squashing all those patches together ? It's not like one is going without the others, or that the commit message provides some new information (except for the name of the file, but that is not very relevant either). The downside is that it's _many_ messages to bypass when reading mails from small-screen devices :-) The only plausible reason I could think of is to avoid clashing with topics in-flight, but then the approach to produce per-file patch is not perfect for that purpose, either, when more than one topic in flight touch the same file at different places. I'd say probably the best organization would be something like: * A set of clean-up patches to normalize oddball usages of existing functions (e.g. normalize 'prefixcmp(a,b) != 0' in some file(s) to 'prefixcmp(a,b)'); * A single patch to introduce the new function(s), to be applied on top of 1.8.5; * A large patch to convert all uses of prefixcmp to starts_with and suffixcmp to ends_with in the 1.8.5 codebase; * A patch for each topic in flight to convert newly introduced prefixcmp/suffixcmp to starts_with/ends_with, to be applied after the topic graduates to 'master' after 1.8.5; and then finally * A separate patch to remove prefixcmp and suffixcmp, to be applied after _all_ in-flight topic has graduated to 'master'. Ok, I will wait for 1.8.5 and then send a patch series like what you suggest. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: GSoC 2014: Summary so far, discussion starter: how to improve?
On Thu, Nov 21, 2013 at 9:36 AM, Thomas Rast t...@thomasrast.ch wrote: Thomas Rast t...@thomasrast.ch writes: * Find an org admin and backup. In previous years Shawn and Peff did this. Would you do it again? If Shawn and Peff don't answer, it probably means that you should volunteer :-) Any opinions on these points? I would actually favor a move to a wiki of the style that Peff proposed, hosted by github and backed by git with either a very mild ACL or none (bots don't know git push). k.org wiki had a grand total of three edits in the last 30 days (plus some bot edits for user creation). If we are provided a wiki of the style Peff proposed, then I am ok using it. But until we have it, let's use the k.org wiki. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] drop support for experimental loose objects
On Thu, Nov 21, 2013 at 5:04 PM, Joey Hess j...@kitenet.net wrote: BTW, I've also seen git cat-file --batch report wrong sizes for objects, sometimes without crashing. This is particularly problimatic because if the object size is wrong, it's very hard to detect the actual end of the object output in the batch mode stream. Yeah, I think it might report wrong size in case of replaced objects for example. I looked at that following Junio's comment about the sha1_object_info() API, which, unlike read_sha1_file() API, does not interact with the replace mechanism: http://thread.gmane.org/gmane.comp.version-control.git/234023/ I started to work on a patch about this but didn't take the time to finish and post it. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] drop support for experimental loose objects
On Fri, Nov 22, 2013 at 10:58 AM, Jeff King p...@peff.net wrote: On Thu, Nov 21, 2013 at 09:19:25PM +0100, Christian Couder wrote: Yeah, I think it might report wrong size in case of replaced objects for example. I looked at that following Junio's comment about the sha1_object_info() API, which, unlike read_sha1_file() API, does not interact with the replace mechanism: http://thread.gmane.org/gmane.comp.version-control.git/234023/ I started to work on a patch about this but didn't take the time to finish and post it. That seems kind of crazy. Would the fix be as simple as this: diff --git a/sha1_file.c b/sha1_file.c index 10676ba..a051d6c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2529,6 +2529,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) struct pack_entry e; int rtype; + sha1 = lookup_replace_object(sha1); + co = find_cached_object(sha1); if (co) { if (oi-typep) or do we need some way for callers to turn off replacement? I notice that read_sha1_file has such a feature, but it is only used in one place. Yeah, indeed, I asked myself such a question and that's why it is not so simple unfortunately. In sha1_file.c, there is: void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag) { void *data; char *path; const struct packed_git *p; const unsigned char *repl = (flag READ_SHA1_FILE_REPLACE) ? lookup_replace_object(sha1) : sha1; errno = 0; data = read_object(repl, type, size); ... And in cache.h, there is: #define READ_SHA1_FILE_REPLACE 1 static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) { return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE); } So the READ_SHA1_FILE_REPLACE is a way to disable replacement at compile time. But in my opinion if we want such a knob, we should use it when we set the read_replace_refs global variable. For example with something like this: diff --git a/environment.c b/environment.c index 0a15349..7c99af8 100644 --- a/environment.c +++ b/environment.c @@ -44,7 +44,7 @@ const char *editor_program; const char *askpass_program; const char *excludes_file; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; -int read_replace_refs = 1; /* NEEDSWORK: rename to use_replace_refs */ +int read_replace_refs = READ_SHA1_FILE_REPLACE; /* NEEDSWORK: rename to use_replace_refs */ enum eol core_eol = EOL_UNSET; enum safe_crlf safe_crlf = SAFE_CRLF_WARN; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; @Junio what would you think about such a change? I guess we would need to audit all the sha1_object_info callers. Yeah but when I looked at them, there were not many that looked dangerous. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] drop support for experimental loose objects
On Fri, Nov 22, 2013 at 12:24 PM, Jeff King p...@peff.net wrote: On Fri, Nov 22, 2013 at 12:04:01PM +0100, Christian Couder wrote: In sha1_file.c, there is: void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag) { void *data; char *path; const struct packed_git *p; const unsigned char *repl = (flag READ_SHA1_FILE_REPLACE) ? lookup_replace_object(sha1) : sha1; errno = 0; data = read_object(repl, type, size); ... And in cache.h, there is: #define READ_SHA1_FILE_REPLACE 1 static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) { return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE); } So the READ_SHA1_FILE_REPLACE is a way to disable replacement at compile time. Is it? I did not have the impression anyone would ever redefine READ_SHA1_FILE_REPLACE at compile time, but that it was a flag that individual callsites would pass to read_sha1_file_extended to tell them whether they were interested in replacements. And the obvious reasons to not be are: 1. You are doing some operation which needs real objects, like fsck or generating a packfile. 2. You have already resolved any replacements, and want to make sure you are getting the same object used elsewhere (e.g., because you already printed its size :) ). The only site which calls read_sha1_file_extended directly and does not pass the REPLACE flag is in streaming.c. And that looks to be a case of (2), since we resolve the replacement at the start in open_istream(). Yeah, you are right. Sorry for overlooking this. But anyway it looks redundant to me to have both this REPLACE flag and the read_replace_refs global variable, so I think a proper solution would involve some significant refactoring. And if we decide to keep a REPLACE flag we might need to add one to sha1_object_info_extended() too. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/5] replace_object: don't check read_replace_refs twice
Since ecef (inline lookup_replace_object() calls, May 15 2011) the read_replace_refs global variable is checked twice, once in lookup_replace_object() and once again in do_lookup_replace_object(). As do_lookup_replace_object() is called only from lookup_replace_object(), we can remove the check in do_lookup_replace_object(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- replace_object.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/replace_object.c b/replace_object.c index d0b1548..cdcaf8c 100644 --- a/replace_object.c +++ b/replace_object.c @@ -97,9 +97,6 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1) int pos, depth = MAXREPLACEDEPTH; const unsigned char *cur = sha1; - if (!read_replace_refs) - return sha1; - prepare_replace_object(); /* Try to recursively replace the object */ -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/5] teach replace objects to sha1_object_info_extended()
Here is a patch series to improve the way sha1_object_info_extended() behaves when it is passed a replaced object. This patch series was inspired by a sub thread in this discussion: http://thread.gmane.org/gmane.comp.version-control.git/238118 Patches 1/5 and 2/5 are cleanups. Patch 4/5 adds a test that fails. Patch 5/5 adds a call to lookup_replace_object_extended() in sha1_object_info_extended() and makes the previous test pass. Christian Couder (5): replace_object: don't check read_replace_refs twice introduce lookup_replace_object_extended() to pass flags Add an unsigned flags parameter to sha1_object_info_extended() t6050: show that git cat-file --batch fails with replace objects sha1_file: perform object replacement in sha1_object_info_extended() builtin/cat-file.c | 2 +- cache.h| 8 +++- replace_object.c | 3 --- sha1_file.c| 20 ++-- streaming.c| 2 +- t/t6050-replace.sh | 5 + 6 files changed, 24 insertions(+), 16 deletions(-) -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/5] introduce lookup_replace_object_extended() to pass flags
Currently, there is only one caller to lookup_replace_object() that can benefit from passing it some flags, but we expect that there could be more. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- cache.h | 6 ++ sha1_file.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cache.h b/cache.h index ce377e1..b845485 100644 --- a/cache.h +++ b/cache.h @@ -773,6 +773,12 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh return sha1; return do_lookup_replace_object(sha1); } +static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag) +{ + if (! (flag READ_SHA1_FILE_REPLACE)) + return sha1; + return lookup_replace_object(sha1); +} /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); diff --git a/sha1_file.c b/sha1_file.c index 7dadd04..b0a3964 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2662,8 +2662,7 @@ void *read_sha1_file_extended(const unsigned char *sha1, void *data; char *path; const struct packed_git *p; - const unsigned char *repl = (flag READ_SHA1_FILE_REPLACE) - ? lookup_replace_object(sha1) : sha1; + const unsigned char *repl = lookup_replace_object_extended(sha1, flag); errno = 0; data = read_object(repl, type, size); -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/5] sha1_file: perform object replacement in sha1_object_info_extended()
sha1_object_info_extended() should perform object replacement if it is needed. The simplest way to do that is to make it call lookup_replace_object_extended(). And now its unsigned flags parameter is used as it is passed to lookup_replace_object_extended(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- sha1_file.c| 13 +++-- t/t6050-replace.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 09e56ef..d715553 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2519,8 +2519,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, struct cached_object *co; struct pack_entry e; int rtype; + const unsigned char *real = lookup_replace_object_extended(sha1, flags); - co = find_cached_object(sha1); + co = find_cached_object(real); if (co) { if (oi-typep) *(oi-typep) = co-type; @@ -2532,23 +2533,23 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, return 0; } - if (!find_pack_entry(sha1, e)) { + if (!find_pack_entry(real, e)) { /* Most likely it's a loose object. */ - if (!sha1_loose_object_info(sha1, oi)) { + if (!sha1_loose_object_info(real, oi)) { oi-whence = OI_LOOSE; return 0; } /* Not a loose object; someone else may have just packed it. */ reprepare_packed_git(); - if (!find_pack_entry(sha1, e)) + if (!find_pack_entry(real, e)) return -1; } rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { - mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi, 0); + mark_bad_packed_object(e.p, real); + return sha1_object_info_extended(real, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index b90dbdc..bb785ec 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -276,7 +276,7 @@ test_expect_success '-f option bypasses the type check' ' git replace -f HEAD^ $BLOB ' -test_expect_failure 'git cat-file --batch works on replace objects' ' +test_expect_success 'git cat-file --batch works on replace objects' ' git replace | grep $PARA3 echo $PARA3 | git cat-file --batch ' -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/5] t6050: show that git cat-file --batch fails with replace objects
When --batch is passed to git cat-file, the sha1_object_info_extended() function is used to get information about the objects passed to git cat-file. Unfortunately sha1_object_info_extended() doesn't take care of object replacement properly, so it will often fail with a message like this: $ echo a3fb2e1845a1aaf129b7975048973414dc172173 | git cat-file --batch a3fb2e1845a1aaf129b7975048973414dc172173 commit 231 fatal: object a3fb2e1845a1aaf129b7975048973414dc172173 change size!? The goal of this patch is to show this breakage. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- t/t6050-replace.sh | 5 + 1 file changed, 5 insertions(+) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 7d47984..b90dbdc 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -276,6 +276,11 @@ test_expect_success '-f option bypasses the type check' ' git replace -f HEAD^ $BLOB ' +test_expect_failure 'git cat-file --batch works on replace objects' ' + git replace | grep $PARA3 + echo $PARA3 | git cat-file --batch +' + test_expect_success 'replace ref cleanup' ' test -n $(git replace) git replace -d $(git replace) -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/5] Add an unsigned flags parameter to sha1_object_info_extended()
This parameter is not used yet, but it will be used to tell sha1_object_info_extended() if it should perform object replacement or not. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/cat-file.c | 2 +- cache.h| 2 +- sha1_file.c| 6 +++--- streaming.c| 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b2ca775..a2d3a9b 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -238,7 +238,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt, return 0; } - if (sha1_object_info_extended(data-sha1, data-info) 0) { + if (sha1_object_info_extended(data-sha1, data-info, READ_SHA1_FILE_REPLACE) 0) { printf(%s missing\n, obj_name); fflush(stdout); return 0; diff --git a/cache.h b/cache.h index b845485..3be03dc 100644 --- a/cache.h +++ b/cache.h @@ -1104,7 +1104,7 @@ struct object_info { } packed; } u; }; -extern int sha1_object_info_extended(const unsigned char *, struct object_info *); +extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags); /* Dumb servers support */ extern int update_server_info(int); diff --git a/sha1_file.c b/sha1_file.c index b0a3964..09e56ef 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2514,7 +2514,7 @@ static int sha1_loose_object_info(const unsigned char *sha1, return 0; } -int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) +int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags) { struct cached_object *co; struct pack_entry e; @@ -2548,7 +2548,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi); + return sha1_object_info_extended(sha1, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { @@ -2570,7 +2570,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep) oi.typep = type; oi.sizep = sizep; - if (sha1_object_info_extended(sha1, oi) 0) + if (sha1_object_info_extended(sha1, oi, READ_SHA1_FILE_REPLACE) 0) return -1; return type; } diff --git a/streaming.c b/streaming.c index debe904..9659f18 100644 --- a/streaming.c +++ b/streaming.c @@ -113,7 +113,7 @@ static enum input_source istream_source(const unsigned char *sha1, oi-typep = type; oi-sizep = size; - status = sha1_object_info_extended(sha1, oi); + status = sha1_object_info_extended(sha1, oi, 0); if (status 0) return stream_error; -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/5] builtin/remote: remove postfixcmp() and use suffixcmp() instead
Commit 8cc5b290 (git merge -Xoption, 25 Nov 2009) introduced suffixcmp() with nearly the same implementation as postfixcmp() that already existed since commit 211c8968 (Make git-remote a builtin, 29 Feb 2008). The only difference between the two implementations is that, when the string is smaller than the suffix, one implementation returns 1 while the other one returns -1. But, as postfixcmp() is only used to compare for equality, the distinction does not matter and does not affect the correctness of this patch. As postfixcmp() has always been static in builtin/remote.c and is used nowhere else, it makes more sense to remove it and use suffixcmp() instead in builtin/remote.c, rather than to remove suffixcmp(). Reviewed-by: Jonathan Nieder jrnie...@gmail.com Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/remote.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 4e14891..9b3a98e 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -80,14 +80,6 @@ static int verbose; static int show_all(void); static int prune_remote(const char *remote, int dry_run); -static inline int postfixcmp(const char *string, const char *postfix) -{ - int len1 = strlen(string), len2 = strlen(postfix); - if (len1 len2) - return 1; - return strcmp(string + len1 - len2, postfix); -} - static int fetch_remote(const char *name) { const char *argv[] = { fetch, name, NULL, NULL }; @@ -277,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb) enum { REMOTE, MERGE, REBASE } type; key += 7; - if (!postfixcmp(key, .remote)) { + if (!suffixcmp(key, .remote)) { name = xstrndup(key, strlen(key) - 7); type = REMOTE; - } else if (!postfixcmp(key, .merge)) { + } else if (!suffixcmp(key, .merge)) { name = xstrndup(key, strlen(key) - 6); type = MERGE; - } else if (!postfixcmp(key, .rebase)) { + } else if (!suffixcmp(key, .rebase)) { name = xstrndup(key, strlen(key) - 7); type = REBASE; } else -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/5] strbuf: introduce starts_with() and ends_with()
prefixcmp() and suffixcmp() cannot be really used as comparison functions as they are not antisymmetric: prefixcmp(foo, foobar) 0 prefixcmp(foobar, foo) == 0 So they are not suitable as functions for passing to qsort. And in fact they are used nowhere as comparison functions. Therefore we should replace them with functions that just check for equality. As a first step toward this goal, this patch introduces starts_with() and end_with() that will be used to replace respectively prefixcmp() and suffixcmp(). Some popular programming languages, like Java, Python and Ruby have functions or methods called like starts_with() and ends_with() that are doing what we want. Therefore it makes sense to use such names. In vcs-svn/fast_export.c, there was already an ends_with() function that did the same thing. Let's use the new one instead while at it. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git-compat-util.h | 2 ++ strbuf.c | 18 ++ vcs-svn/fast_export.c | 11 +-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index 7776f12..b73916b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -350,7 +350,9 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); +extern int starts_with(const char *str, const char *prefix); extern int prefixcmp(const char *str, const char *prefix); +extern int ends_with(const char *str, const char *suffix); extern int suffixcmp(const char *str, const char *suffix); static inline const char *skip_prefix(const char *str, const char *prefix) diff --git a/strbuf.c b/strbuf.c index 1170d01..83caf4a 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,6 +1,15 @@ #include cache.h #include refs.h +int starts_with(const char *str, const char *prefix) +{ + for (; ; str++, prefix++) + if (!*prefix) + return 1; + else if (*str != *prefix) + return 0; +} + int prefixcmp(const char *str, const char *prefix) { for (; ; str++, prefix++) @@ -10,6 +19,15 @@ int prefixcmp(const char *str, const char *prefix) return (unsigned char)*prefix - (unsigned char)*str; } +int ends_with(const char *str, const char *suffix) +{ + int len = strlen(str), suflen = strlen(suffix); + if (len suflen) + return 0; + else + return !strcmp(str + len - suflen, suffix); +} + int suffixcmp(const char *str, const char *suffix) { int len = strlen(str), suflen = strlen(suffix); diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c index f2b23c8..bd0f2c2 100644 --- a/vcs-svn/fast_export.c +++ b/vcs-svn/fast_export.c @@ -162,22 +162,13 @@ static void die_short_read(struct line_buffer *input) die(invalid dump: unexpected end of file); } -static int ends_with(const char *s, size_t len, const char *suffix) -{ - const size_t suffixlen = strlen(suffix); - if (len suffixlen) - return 0; - return !memcmp(s + len - suffixlen, suffix, suffixlen); -} - static int parse_cat_response_line(const char *header, off_t *len) { - size_t headerlen = strlen(header); uintmax_t n; const char *type; const char *end; - if (ends_with(header, headerlen, missing)) + if (ends_with(header, missing)) return error(cat-blob reports missing blob: %s, header); type = strstr(header, blob ); if (!type) -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/5] strbuf: remove prefixcmp() and suffixcmp()
As starts_with() and ends_with() have been used to replace prefixcmp() and suffixcmp() respectively, we can now remove them. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- git-compat-util.h | 2 -- strbuf.c | 18 -- 2 files changed, 20 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index b73916b..c4c01e7 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -351,9 +351,7 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); extern int starts_with(const char *str, const char *prefix); -extern int prefixcmp(const char *str, const char *prefix); extern int ends_with(const char *str, const char *suffix); -extern int suffixcmp(const char *str, const char *suffix); static inline const char *skip_prefix(const char *str, const char *prefix) { diff --git a/strbuf.c b/strbuf.c index 83caf4a..ee96dcf 100644 --- a/strbuf.c +++ b/strbuf.c @@ -10,15 +10,6 @@ int starts_with(const char *str, const char *prefix) return 0; } -int prefixcmp(const char *str, const char *prefix) -{ - for (; ; str++, prefix++) - if (!*prefix) - return 0; - else if (*str != *prefix) - return (unsigned char)*prefix - (unsigned char)*str; -} - int ends_with(const char *str, const char *suffix) { int len = strlen(str), suflen = strlen(suffix); @@ -28,15 +19,6 @@ int ends_with(const char *str, const char *suffix) return !strcmp(str + len - suflen, suffix); } -int suffixcmp(const char *str, const char *suffix) -{ - int len = strlen(str), suflen = strlen(suffix); - if (len suflen) - return -1; - else - return strcmp(str + len - suflen, suffix); -} - /* * Used as the default -buf value, so that people can always assume * buf is non NULL and -buf is NUL terminated even for a freshly -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/5] use starts_with() and ends_with()
This is a new patch series along the lines Junio suggested in this thread: http://thread.gmane.org/gmane.comp.version-control.git/238054/ I send it now because I saw a 1.8.5 tag. The patches in this series can be related to what Junio suggested this way: * A set of clean-up patches to normalize oddball usages of existing functions (e.g. normalize 'prefixcmp(a,b) != 0' in some file(s) to 'prefixcmp(a,b)'); - Patches 1/5 and 2/5 are such kind of cleanups. * A single patch to introduce the new function(s), to be applied on top of 1.8.5; - Patch 3/5 does that. * A large patch to convert all uses of prefixcmp to starts_with and suffixcmp to ends_with in the 1.8.5 codebase; - Patch 4/5 does that. * A patch for each topic in flight to convert newly introduced prefixcmp/suffixcmp to starts_with/ends_with, to be applied after the topic graduates to 'master' after 1.8.5; and then finally - I didn't start to work on that yet. I hope that I will only need to take care of what is going on in 'next'. * A separate patch to remove prefixcmp and suffixcmp, to be applied after _all_ in-flight topic has graduated to 'master'. - Patch 5/5 does that. Christian Couder (5): environment: normalize use of prefixcmp() by removing != 0 builtin/remote: remove postfixcmp() and use suffixcmp() instead strbuf: introduce starts_with() and ends_with() Replace {pre,suf}fixcmp() with {starts,ends}_with() strbuf: remove prefixcmp() and suffixcmp() alias.c | 2 +- attr.c| 2 +- bisect.c | 4 +-- branch.c | 4 +-- builtin/apply.c | 12 +++ builtin/archive.c | 4 +-- builtin/branch.c | 6 ++-- builtin/checkout.c| 8 ++--- builtin/clean.c | 4 +-- builtin/clone.c | 8 ++--- builtin/column.c | 2 +- builtin/commit.c | 10 +++--- builtin/describe.c| 2 +- builtin/fast-export.c | 2 +- builtin/fetch-pack.c | 6 ++-- builtin/fetch.c | 18 +-- builtin/fmt-merge-msg.c | 10 +++--- builtin/for-each-ref.c| 14 - builtin/fsck.c| 6 ++-- builtin/help.c| 8 ++--- builtin/index-pack.c | 8 ++--- builtin/init-db.c | 2 +- builtin/log.c | 8 ++--- builtin/ls-remote.c | 4 +-- builtin/mailinfo.c| 16 +- builtin/merge-recursive.c | 4 +-- builtin/merge.c | 12 +++ builtin/name-rev.c| 6 ++-- builtin/notes.c | 2 +- builtin/pack-objects.c| 2 +- builtin/prune.c | 4 +-- builtin/receive-pack.c| 6 ++-- builtin/reflog.c | 4 +-- builtin/remote.c | 22 + builtin/repack.c | 2 +- builtin/rev-parse.c | 24 +++--- builtin/send-pack.c | 8 ++--- builtin/shortlog.c| 6 ++-- builtin/show-branch.c | 20 ++-- builtin/show-ref.c| 6 ++-- builtin/symbolic-ref.c| 2 +- builtin/tag.c | 2 +- builtin/tar-tree.c| 2 +- builtin/unpack-objects.c | 2 +- builtin/update-ref.c | 10 +++--- builtin/upload-archive.c | 2 +- commit.c | 6 ++-- config.c | 16 +- connect.c | 2 +- connected.c | 2 +- convert.c | 2 +- daemon.c | 40 diff.c| 56 - environment.c | 2 +- fast-import.c | 80 +++ fetch-pack.c | 12 +++ git-compat-util.h | 4 +-- git.c | 12 +++ help.c| 8 ++--- http-backend.c| 4 +-- http-push.c | 4 +-- http.c| 10 +++--- imap-send.c | 10 +++--- log-tree.c| 8 ++--- merge-recursive.c | 6 ++-- notes-utils.c | 4 +-- notes.c | 8 ++--- pager.c | 2 +- parse-options.c | 12 +++ pathspec.c| 2 +- pkt-line.c| 4 +-- pretty.c | 36 ++--- refs.c| 30 +- remote-curl.c | 14 - remote-testsvn.c | 10 +++--- remote.c | 46 +-- revision.c| 38 +++--- send-pack.c | 4 +-- sequencer.c | 8 ++--- setup.c | 4 +-- sha1_name.c | 16 +- shell.c | 2 +- strbuf.c | 12 +++ submodule.c | 2 +- tag.c | 10 +++--- test-line-buffer.c| 6 ++-- test-string-list.c| 2 +- transport-helper.c| 16 +- transport.c | 28
[PATCH 1/5] environment: normalize use of prefixcmp() by removing != 0
To be able to automatically convert prefixcmp() to starts_with() we need first to make sure that prefixcmp() is always used in the same way. So let's remove != 0 after prefixcmp(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- environment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.c b/environment.c index 0a15349..cd2b068 100644 --- a/environment.c +++ b/environment.c @@ -171,7 +171,7 @@ const char *get_git_namespace(void) const char *strip_namespace(const char *namespaced_ref) { - if (prefixcmp(namespaced_ref, get_git_namespace()) != 0) + if (prefixcmp(namespaced_ref, get_git_namespace())) return NULL; return namespaced_ref + namespace_len; } -- 1.8.4.1.561.g12affca -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/5] use starts_with() and ends_with()
From: Junio C Hamano gits...@pobox.com Jeff King p...@peff.net writes: On Sun, Dec 01, 2013 at 08:49:13AM +0100, Christian Couder wrote: This is a new patch series along the lines Junio suggested in this thread: http://thread.gmane.org/gmane.comp.version-control.git/238054/ I send it now because I saw a 1.8.5 tag. This looks sane to me. Your 4/5 did not make it to the list (nor directly to me), though. Perhaps because it is huge? Nor to me, either. Sorry about that I don't know what happened. Maybe my ISP has blocked it because it is big. I just tried to send it again. Best, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Fwd: [PATCH 4/5] Replace {pre,suf}fixcmp() with {starts,ends}_with()
On Tue, Dec 3, 2013 at 1:46 PM, Jeff King p...@peff.net wrote: This made it through to me, but not the list. There are at least two things going on: 1. The message is 172K, which is over the 100K limit imposed by vger; the list is silently dropping it. 2. In my case, the direct mail was being flagged by spam because it contains the blacklisted domain old.name. Which of course is not a domain at all but rather this code: old.name = old.path + strlen(refs/heads/); I've tweaked my server. I can't say why it wasn't getting to Junio via direct mail. Maybe the same spam thing, or maybe something else. [...] I skimmed the patch and didn't notice any problems. It's whitespace-damaged by gmail, of course. The simplest thing is probably to just point us at a public repo with the commit, if you have one. Ok, the commit is in the use_starts_ends_with branch on this github repo: https://github.com/chriscool/git.git Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/5] teach replace objects to sha1_object_info_extended()
From: Junio C Hamano gits...@pobox.com Jeff King p...@peff.net writes: On Mon, Dec 02, 2013 at 09:52:25AM -0500, Jeff King wrote: I find it a little funny that we reuse the READ_SHA1_FILE_REPLACE flag directly in lookup_replace_object. That means that it is now a meaningful flag for sha1_object_info_extended, even though the name does not say so. It also means that the two may have to coordinate further flags (since a portion of their flag namespace is shared by lookup_replace_object). I don't foresee adding a lot of new flags, though, so it probably isn't a huge deal. I also would have expected sha1_object_info_extended to simply receive the new flag via the struct object_info. Again, probably not a big deal, because there aren't many callsites that needed updating. But if we were not sharing flags with read_sha1_file, I think doing it as a flag in the struct would be nicer. Curious what this would look like, I wrote the patch. If you drop your patches 2 and 3, then your final patch (actually fixing the problem) would look like the one below: We may be getting into bikeshed territory, and I don't feel super-strongly about it, so I won't say anything more. Now we've seen both alternatives, and you or Junio can pick. :) Thanks for doing that. I still prefer a flag used by sha1_object_info_extended(), read_sha1_file_extended() and lookup_replace_object_extended(). I think it is more coherent this way. FWIW, I shared that a little funny feeling ;-) Yeah, it's true that I should have renamed the flag. READ_SHA1_FILE_REPLACE is too much related to the read_sha1_file*() functions. As it is related to lookup_replace_object*() functions, what about LOOKUP_REPLACE_OBJECT? Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/5] teach replace objects to sha1_object_info_extended()
From: Jeff King p...@peff.net On Sat, Nov 30, 2013 at 02:51:18PM +0100, Christian Couder wrote: Here is a patch series to improve the way sha1_object_info_extended() behaves when it is passed a replaced object. Overall looks OK to me. Thanks for reviewing it. [...] I checked the resulting behavior against the list I made earlier; looks like all of the _extended callsites are doing the right thing. I do think the checks you added in 277336a (replace: forbid replacing an object with one of a different type, 2013-09-06) need updating. I started on that, but I wonder if all of cmd_replace should simply turn off read_replace_refs. I'd think it would always want to be dealing with the true objects. Yeah, I think you are right. I will have a look and probably turn off read_replace_ref in cmd_replace() as you suggest. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Fwd: [PATCH 4/5] Replace {pre,suf}fixcmp() with {starts,ends}_with()
On Wed, Dec 4, 2013 at 11:02 PM, Junio C Hamano gits...@pobox.com wrote: Junio C Hamano gits...@pobox.com writes: Christian Couder christian.cou...@gmail.com writes: Ok, the commit is in the use_starts_ends_with branch on this github repo: https://github.com/chriscool/git.git I looked at the patches, and they looked alright. The endgame needs to be on a separate topic to be held until a distant future, though. Will queue. Thanks. Great! It turns out that, naturally, there are many new uses of prefixcmp in the topics in flight. I can manage, but adjusting all of them would not look too pretty X-. Tell me if I can do something. I can prepare patches for the topics in flight in 'next' for example. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: What's cooking in git.git (Dec 2013, #01; Wed, 4)
On Thu, Dec 5, 2013 at 2:23 AM, Junio C Hamano gits...@pobox.com wrote: * cc/starts-n-ends-with (2013-12-04) 4 commits - replace {pre,suf}fixcmp() with {starts,ends}_with() - strbuf: introduce starts_with() and ends_with() - builtin/remote: remove postfixcmp() and use suffixcmp() instead - environment: normalize use of prefixcmp() by removing != 0 (this branch is used by cc/starts-n-ends-with-endgame.) Remove a few duplicate implementations of prefix/suffix comparison functions, and rename them to starts_with and ends_with. This conflicts with a part of cc/remote-remove-redundant-postfixcmp topic (I think it actually subsumes it). Yeah, it subsumes it. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 00/10] teach replace objects to sha1_object_info_extended()
Here is version 2 of a patch series to improve the way sha1_object_info_extended() behaves when it is passed a replaced object. The idea is to add a flags argument to it in the same way as what has been done to read_sha1_file(). This patch series was inspired by a sub thread in this discussion: http://thread.gmane.org/gmane.comp.version-control.git/238118 Patches 1/10, 2/10 and 3/10 are cleanups, among them only 1/10 is new. Patches 4/10, 5/10 and 6/10 were also in the previous version. Patches 7/10, 8/10, 9/10 and 10/10 are new. They add a new --format option to list replace refs. 'short' (which is the default), 'medium' and 'full' formats are supported. This could be considered another patch series, but it is also related, because it uses sha1_object_info() and it fixes its use in builtin/replace.c by unsetting the global variable read_replace_refs in cmd_replace(). Christian Couder (10): Rename READ_SHA1_FILE_REPLACE flag to LOOKUP_REPLACE_OBJECT replace_object: don't check read_replace_refs twice Introduce lookup_replace_object_extended() to pass flags Add an unsigned flags parameter to sha1_object_info_extended() t6050: show that git cat-file --batch fails with replace objects sha1_file: perform object replacement in sha1_object_info_extended() builtin/replace: teach listing using short, medium or full formats t6050: add tests for listing with --format builtin/replace: unset read_replace_refs Documentation/git-replace: describe --format option Documentation/git-replace.txt | 19 - builtin/cat-file.c| 2 +- builtin/replace.c | 63 ++- cache.h | 12 ++--- replace_object.c | 3 --- sha1_file.c | 20 +++--- streaming.c | 2 +- t/t6050-replace.sh| 32 ++ 8 files changed, 127 insertions(+), 26 deletions(-) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 10/10] Documentation/git-replace: describe --format option
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- Documentation/git-replace.txt | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index f373ab4..7a07828 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git replace' [-f] object replacement 'git replace' -d object... -'git replace' -l [pattern] +'git replace' [--format=format] [-l [pattern]] DESCRIPTION --- @@ -70,6 +70,23 @@ OPTIONS Typing git replace without arguments, also lists all replace refs. +--format=format:: + When listing, use the specified format, which can be one of + 'short', 'medium' and 'full'. When omitted, the format + defaults to 'short'. + +FORMATS +--- + +The following format are available: + +* 'short': + replaced sha1 +* 'medium': + replaced sha1 - replacement sha1 +* 'full' + replaced sha1 (replaced type) - replacement sha1 (replacement type) + CREATING REPLACEMENT OBJECTS -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 07/10] builtin/replace: teach listing using short, medium or full formats
By default when listing replace refs, only the sha1 of the replaced objects are shown. In many cases, it is much nicer to be able to list all the sha1 of the replaced objects along with the sha1 of the replacment objects. And in other cases it might be interesting to also show the types of the replaced and replacement objects. This patch introduce a new --format=fmt option where fmt can be any of the following: 'short': this is the same as when no --format option is used, that is only the sha1 of the replaced objects are shown 'medium': this also lists the sha1 of the replacement objects 'full': this shows the sha1 and the type of both the replaced and the replacement objects Some documentation and some tests will follow. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/replace.c | 61 --- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index b1bd3ef..9f3619a 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -16,27 +16,65 @@ static const char * const git_replace_usage[] = { N_(git replace [-f] object replacement), N_(git replace -d object...), - N_(git replace -l [pattern]), + N_(git replace [--format=format] [-l [pattern]]), NULL }; +enum repl_fmt { SHORT, MEDIUM, FULL }; + +struct show_data { + const char *pattern; + enum repl_fmt fmt; +}; + static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { - const char *pattern = cb_data; + struct show_data *data = cb_data; + + if (!fnmatch(data-pattern, refname, 0)) { + if (data-fmt == SHORT) + printf(%s\n, refname); + else if (data-fmt == MEDIUM) + printf(%s - %s\n, refname, sha1_to_hex(sha1)); + else { /* data-fmt == FULL */ + unsigned char object[20]; + enum object_type obj_type, repl_type; - if (!fnmatch(pattern, refname, 0)) - printf(%s\n, refname); + if (get_sha1(refname, object)) + return error(Failed to resolve '%s' as a valid ref., refname); + + obj_type = sha1_object_info(object, NULL); + repl_type = sha1_object_info(sha1, NULL); + + printf(%s (%s) - %s (%s)\n, refname, typename(obj_type), + sha1_to_hex(sha1), typename(repl_type)); + } + } return 0; } -static int list_replace_refs(const char *pattern) +static int list_replace_refs(const char *pattern, const char *format) { + struct show_data data; + if (pattern == NULL) pattern = *; + data.pattern = pattern; + + if (format == NULL || *format == '\0' || !strcmp(format, short)) + data.fmt = SHORT; + else if (!strcmp(format, medium)) + data.fmt = MEDIUM; + else if (!strcmp(format, full)) + data.fmt = FULL; + else + die(invalid replace format '%s'\n + valid formats are 'short', 'medium' and 'full'\n, + format); - for_each_replace_ref(show_reference, (void *) pattern); + for_each_replace_ref(show_reference, (void *) data); return 0; } @@ -127,10 +165,12 @@ static int replace_object(const char *object_ref, const char *replace_ref, int cmd_replace(int argc, const char **argv, const char *prefix) { int list = 0, delete = 0, force = 0; + const char *format = NULL; struct option options[] = { OPT_BOOL('l', list, list, N_(list replace refs)), OPT_BOOL('d', delete, delete, N_(delete replace refs)), OPT_BOOL('f', force, force, N_(replace the ref if it exists)), + OPT_STRING(0, format, format, N_(format), N_(use this format)), OPT_END() }; @@ -140,6 +180,10 @@ int cmd_replace(int argc, const char **argv, const char *prefix) usage_msg_opt(-l and -d cannot be used together, git_replace_usage, options); + if (format delete) + usage_msg_opt(--format and -d cannot be used together, + git_replace_usage, options); + if (force (list || delete)) usage_msg_opt(-f cannot be used with -d or -l, git_replace_usage, options); @@ -157,6 +201,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix) if (argc != 2) usage_msg_opt(bad number of arguments, git_replace_usage, options); + if (format
[PATCH v2 09/10] builtin/replace: unset read_replace_refs
When checking to see if some objects are of the same type and when displaying the type of objects, git replace uses the sha1_object_info() function. Unfortunately this function by default respects replace refs, so instead of the type of a replaced object, it gives the type of the replacement object which might be different. To fix this bug, and because git replace should work at a level before replacement takes place, let's unset the read_replace_refs global variable at the beginning of cmd_replace(). Suggested-by: Jeff King p...@peff.net Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/replace.c | 2 ++ t/t6050-replace.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/replace.c b/builtin/replace.c index 9f3619a..1672870 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -174,6 +174,8 @@ int cmd_replace(int argc, const char **argv, const char *prefix) OPT_END() }; + read_replace_refs = 0; + argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0); if (list delete) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 3627b4c..f15b805 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -296,7 +296,7 @@ test_expect_success 'test --format medium' ' test_cmp expected actual ' -test_expect_failure 'test --format full' ' +test_expect_success 'test --format full' ' { echo $H1 (commit) - $BLOB (blob) echo $BLOB (blob) - $REPLACED (blob) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 04/10] Add an unsigned flags parameter to sha1_object_info_extended()
This parameter is not used yet, but it will be used to tell sha1_object_info_extended() if it should perform object replacement or not. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/cat-file.c | 2 +- cache.h| 2 +- sha1_file.c| 6 +++--- streaming.c| 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b2ca775..b15c064 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -238,7 +238,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt, return 0; } - if (sha1_object_info_extended(data-sha1, data-info) 0) { + if (sha1_object_info_extended(data-sha1, data-info, LOOKUP_REPLACE_OBJECT) 0) { printf(%s missing\n, obj_name); fflush(stdout); return 0; diff --git a/cache.h b/cache.h index 563f85f..701e42c 100644 --- a/cache.h +++ b/cache.h @@ -1104,7 +1104,7 @@ struct object_info { } packed; } u; }; -extern int sha1_object_info_extended(const unsigned char *, struct object_info *); +extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags); /* Dumb servers support */ extern int update_server_info(int); diff --git a/sha1_file.c b/sha1_file.c index 4fb2f17..482037e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2443,7 +2443,7 @@ static int sha1_loose_object_info(const unsigned char *sha1, return 0; } -int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) +int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags) { struct cached_object *co; struct pack_entry e; @@ -2477,7 +2477,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi); + return sha1_object_info_extended(sha1, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { @@ -2499,7 +2499,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep) oi.typep = type; oi.sizep = sizep; - if (sha1_object_info_extended(sha1, oi) 0) + if (sha1_object_info_extended(sha1, oi, LOOKUP_REPLACE_OBJECT) 0) return -1; return type; } diff --git a/streaming.c b/streaming.c index debe904..9659f18 100644 --- a/streaming.c +++ b/streaming.c @@ -113,7 +113,7 @@ static enum input_source istream_source(const unsigned char *sha1, oi-typep = type; oi-sizep = size; - status = sha1_object_info_extended(sha1, oi); + status = sha1_object_info_extended(sha1, oi, 0); if (status 0) return stream_error; -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 06/10] sha1_file: perform object replacement in sha1_object_info_extended()
sha1_object_info_extended() should perform object replacement if it is needed. The simplest way to do that is to make it call lookup_replace_object_extended(). And now its unsigned flags parameter is used as it is passed to lookup_replace_object_extended(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- sha1_file.c| 13 +++-- t/t6050-replace.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 482037e..ee224e4 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2448,8 +2448,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, struct cached_object *co; struct pack_entry e; int rtype; + const unsigned char *real = lookup_replace_object_extended(sha1, flags); - co = find_cached_object(sha1); + co = find_cached_object(real); if (co) { if (oi-typep) *(oi-typep) = co-type; @@ -2461,23 +2462,23 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, return 0; } - if (!find_pack_entry(sha1, e)) { + if (!find_pack_entry(real, e)) { /* Most likely it's a loose object. */ - if (!sha1_loose_object_info(sha1, oi)) { + if (!sha1_loose_object_info(real, oi)) { oi-whence = OI_LOOSE; return 0; } /* Not a loose object; someone else may have just packed it. */ reprepare_packed_git(); - if (!find_pack_entry(sha1, e)) + if (!find_pack_entry(real, e)) return -1; } rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { - mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi, 0); + mark_bad_packed_object(e.p, real); + return sha1_object_info_extended(real, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index b90dbdc..bb785ec 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -276,7 +276,7 @@ test_expect_success '-f option bypasses the type check' ' git replace -f HEAD^ $BLOB ' -test_expect_failure 'git cat-file --batch works on replace objects' ' +test_expect_success 'git cat-file --batch works on replace objects' ' git replace | grep $PARA3 echo $PARA3 | git cat-file --batch ' -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 03/10] Introduce lookup_replace_object_extended() to pass flags
Currently, there is only one caller to lookup_replace_object() that can benefit from passing it some flags, but we expect that there could be more. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- cache.h | 6 ++ sha1_file.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cache.h b/cache.h index 873a6b5..563f85f 100644 --- a/cache.h +++ b/cache.h @@ -773,6 +773,12 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh return sha1; return do_lookup_replace_object(sha1); } +static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag) +{ + if (! (flag LOOKUP_REPLACE_OBJECT)) + return sha1; + return lookup_replace_object(sha1); +} /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); diff --git a/sha1_file.c b/sha1_file.c index 76e9f32..4fb2f17 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2591,8 +2591,7 @@ void *read_sha1_file_extended(const unsigned char *sha1, void *data; char *path; const struct packed_git *p; - const unsigned char *repl = (flag LOOKUP_REPLACE_OBJECT) - ? lookup_replace_object(sha1) : sha1; + const unsigned char *repl = lookup_replace_object_extended(sha1, flag); errno = 0; data = read_object(repl, type, size); -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 02/10] replace_object: don't check read_replace_refs twice
Since ecef (inline lookup_replace_object() calls, May 15 2011) the read_replace_refs global variable is checked twice, once in lookup_replace_object() and once again in do_lookup_replace_object(). As do_lookup_replace_object() is called only from lookup_replace_object(), we can remove the check in do_lookup_replace_object(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- replace_object.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/replace_object.c b/replace_object.c index d0b1548..cdcaf8c 100644 --- a/replace_object.c +++ b/replace_object.c @@ -97,9 +97,6 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1) int pos, depth = MAXREPLACEDEPTH; const unsigned char *cur = sha1; - if (!read_replace_refs) - return sha1; - prepare_replace_object(); /* Try to recursively replace the object */ -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 09/10] builtin/replace: unset read_replace_refs
On Sat, Dec 7, 2013 at 8:02 PM, Jakub Narebski jna...@gmail.com wrote: Wasn't replace mechanism tightened, so that replacing object must be the same type as replaced object? Yes, but if --force is used or if the replace ref is created with git update-ref, then it is not enforced. Is there a situation where you might want replace object with different type of object? This was discussed: http://thread.gmane.org/gmane.comp.version-control.git/233157/ Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 08/10] t6050: add tests for listing with --format
From: Eric Sunshine sunsh...@sunshineco.com On Sat, Dec 7, 2013 at 11:21 AM, Christian Couder chrisc...@tuxfamily.org wrote: This patch adds tests for git replace -l --format=fmt. Only tests when fmt is 'medium' and 'full' are needed because 'short' is the same as with no --format option. Nevertheless, don't you want to test that it behaves in the expected manner when given --format=short and other legal or illegal combinations? --format --format short --format bogus ...etc... Ok, I will add more tests. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 03/10] Introduce lookup_replace_object_extended() to pass flags
Currently, there is only one caller to lookup_replace_object() that can benefit from passing it some flags, but we expect that there could be more. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- cache.h | 6 ++ sha1_file.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cache.h b/cache.h index 873a6b5..563f85f 100644 --- a/cache.h +++ b/cache.h @@ -773,6 +773,12 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh return sha1; return do_lookup_replace_object(sha1); } +static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag) +{ + if (! (flag LOOKUP_REPLACE_OBJECT)) + return sha1; + return lookup_replace_object(sha1); +} /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); diff --git a/sha1_file.c b/sha1_file.c index 76e9f32..4fb2f17 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2591,8 +2591,7 @@ void *read_sha1_file_extended(const unsigned char *sha1, void *data; char *path; const struct packed_git *p; - const unsigned char *repl = (flag LOOKUP_REPLACE_OBJECT) - ? lookup_replace_object(sha1) : sha1; + const unsigned char *repl = lookup_replace_object_extended(sha1, flag); errno = 0; data = read_object(repl, type, size); -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 01/10] Rename READ_SHA1_FILE_REPLACE flag to LOOKUP_REPLACE_OBJECT
The READ_SHA1_FILE_REPLACE flag is more related to using the lookup_replace_object() function rather than the read_sha1_file() function. We also need such a flag to be used with sha1_object_info() instead of read_sha1_file(). The name LOOKUP_REPLACE_OBJECT is therefore better for this flag. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- cache.h | 4 ++-- sha1_file.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index ce377e1..873a6b5 100644 --- a/cache.h +++ b/cache.h @@ -760,11 +760,11 @@ int daemon_avoid_alias(const char *path); int offset_1st_component(const char *path); /* object replacement */ -#define READ_SHA1_FILE_REPLACE 1 +#define LOOKUP_REPLACE_OBJECT 1 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag); static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) { - return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE); + return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT); } extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1); static inline const unsigned char *lookup_replace_object(const unsigned char *sha1) diff --git a/sha1_file.c b/sha1_file.c index daacc0c..76e9f32 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2591,7 +2591,7 @@ void *read_sha1_file_extended(const unsigned char *sha1, void *data; char *path; const struct packed_git *p; - const unsigned char *repl = (flag READ_SHA1_FILE_REPLACE) + const unsigned char *repl = (flag LOOKUP_REPLACE_OBJECT) ? lookup_replace_object(sha1) : sha1; errno = 0; -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 02/10] replace_object: don't check read_replace_refs twice
Since ecef (inline lookup_replace_object() calls, May 15 2011) the read_replace_refs global variable is checked twice, once in lookup_replace_object() and once again in do_lookup_replace_object(). As do_lookup_replace_object() is called only from lookup_replace_object(), we can remove the check in do_lookup_replace_object(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- replace_object.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/replace_object.c b/replace_object.c index d0b1548..cdcaf8c 100644 --- a/replace_object.c +++ b/replace_object.c @@ -97,9 +97,6 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1) int pos, depth = MAXREPLACEDEPTH; const unsigned char *cur = sha1; - if (!read_replace_refs) - return sha1; - prepare_replace_object(); /* Try to recursively replace the object */ -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 00/10] teach replace objects to sha1_object_info_extended()
Here is version 3 of a patch series to improve the way sha1_object_info_extended() behaves when it is passed a replaced object. The idea is to add a flags argument to it in the same way as what has been done to read_sha1_file(). This patch series was inspired by a sub thread in this discussion: http://thread.gmane.org/gmane.comp.version-control.git/238118 The only change compared to version 2 is that a few more tests have been added to patch 8/10, as suggested by Eric Sunchine. As in the previous version, patches 7/10, 8/10, 9/10 and 10/10 add a new --format option to list replace refs. 'short' (which is the default), 'medium' and 'full' formats are supported. This could be considered another patch series, but it is also related, because it uses sha1_object_info() and it fixes its use in builtin/replace.c by unsetting the global variable read_replace_refs in cmd_replace(). Christian Couder (10): Rename READ_SHA1_FILE_REPLACE flag to LOOKUP_REPLACE_OBJECT replace_object: don't check read_replace_refs twice Introduce lookup_replace_object_extended() to pass flags Add an unsigned flags parameter to sha1_object_info_extended() t6050: show that git cat-file --batch fails with replace objects sha1_file: perform object replacement in sha1_object_info_extended() builtin/replace: teach listing using short, medium or full formats t6050: add tests for listing with --format builtin/replace: unset read_replace_refs Documentation/git-replace: describe --format option Documentation/git-replace.txt | 19 - builtin/cat-file.c| 2 +- builtin/replace.c | 63 ++- cache.h | 12 ++--- replace_object.c | 3 --- sha1_file.c | 20 +++--- streaming.c | 2 +- t/t6050-replace.sh| 42 + 8 files changed, 137 insertions(+), 26 deletions(-) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 09/10] builtin/replace: unset read_replace_refs
When checking to see if some objects are of the same type and when displaying the type of objects, git replace uses the sha1_object_info() function. Unfortunately this function by default respects replace refs, so instead of the type of a replaced object, it gives the type of the replacement object which might be different. To fix this bug, and because git replace should work at a level before replacement takes place, let's unset the read_replace_refs global variable at the beginning of cmd_replace(). Suggested-by: Jeff King p...@peff.net Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/replace.c | 2 ++ t/t6050-replace.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/replace.c b/builtin/replace.c index 9f3619a..1672870 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -174,6 +174,8 @@ int cmd_replace(int argc, const char **argv, const char *prefix) OPT_END() }; + read_replace_refs = 0; + argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0); if (list delete) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index e1cc3b8..d0c62f7 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -306,7 +306,7 @@ test_expect_success 'test --format medium' ' test_cmp expected actual ' -test_expect_failure 'test --format full' ' +test_expect_success 'test --format full' ' { echo $H1 (commit) - $BLOB (blob) echo $BLOB (blob) - $REPLACED (blob) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 04/10] Add an unsigned flags parameter to sha1_object_info_extended()
This parameter is not used yet, but it will be used to tell sha1_object_info_extended() if it should perform object replacement or not. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/cat-file.c | 2 +- cache.h| 2 +- sha1_file.c| 6 +++--- streaming.c| 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b2ca775..b15c064 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -238,7 +238,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt, return 0; } - if (sha1_object_info_extended(data-sha1, data-info) 0) { + if (sha1_object_info_extended(data-sha1, data-info, LOOKUP_REPLACE_OBJECT) 0) { printf(%s missing\n, obj_name); fflush(stdout); return 0; diff --git a/cache.h b/cache.h index 563f85f..701e42c 100644 --- a/cache.h +++ b/cache.h @@ -1104,7 +1104,7 @@ struct object_info { } packed; } u; }; -extern int sha1_object_info_extended(const unsigned char *, struct object_info *); +extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags); /* Dumb servers support */ extern int update_server_info(int); diff --git a/sha1_file.c b/sha1_file.c index 4fb2f17..482037e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2443,7 +2443,7 @@ static int sha1_loose_object_info(const unsigned char *sha1, return 0; } -int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) +int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags) { struct cached_object *co; struct pack_entry e; @@ -2477,7 +2477,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi) rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi); + return sha1_object_info_extended(sha1, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { @@ -2499,7 +2499,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep) oi.typep = type; oi.sizep = sizep; - if (sha1_object_info_extended(sha1, oi) 0) + if (sha1_object_info_extended(sha1, oi, LOOKUP_REPLACE_OBJECT) 0) return -1; return type; } diff --git a/streaming.c b/streaming.c index debe904..9659f18 100644 --- a/streaming.c +++ b/streaming.c @@ -113,7 +113,7 @@ static enum input_source istream_source(const unsigned char *sha1, oi-typep = type; oi-sizep = size; - status = sha1_object_info_extended(sha1, oi); + status = sha1_object_info_extended(sha1, oi, 0); if (status 0) return stream_error; -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 05/10] t6050: show that git cat-file --batch fails with replace objects
When --batch is passed to git cat-file, the sha1_object_info_extended() function is used to get information about the objects passed to git cat-file. Unfortunately sha1_object_info_extended() doesn't take care of object replacement properly, so it will often fail with a message like this: $ echo a3fb2e1845a1aaf129b7975048973414dc172173 | git cat-file --batch a3fb2e1845a1aaf129b7975048973414dc172173 commit 231 fatal: object a3fb2e1845a1aaf129b7975048973414dc172173 change size!? The goal of this patch is to show this breakage. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- t/t6050-replace.sh | 5 + 1 file changed, 5 insertions(+) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 7d47984..b90dbdc 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -276,6 +276,11 @@ test_expect_success '-f option bypasses the type check' ' git replace -f HEAD^ $BLOB ' +test_expect_failure 'git cat-file --batch works on replace objects' ' + git replace | grep $PARA3 + echo $PARA3 | git cat-file --batch +' + test_expect_success 'replace ref cleanup' ' test -n $(git replace) git replace -d $(git replace) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 06/10] sha1_file: perform object replacement in sha1_object_info_extended()
sha1_object_info_extended() should perform object replacement if it is needed. The simplest way to do that is to make it call lookup_replace_object_extended(). And now its unsigned flags parameter is used as it is passed to lookup_replace_object_extended(). Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- sha1_file.c| 13 +++-- t/t6050-replace.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 482037e..ee224e4 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2448,8 +2448,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, struct cached_object *co; struct pack_entry e; int rtype; + const unsigned char *real = lookup_replace_object_extended(sha1, flags); - co = find_cached_object(sha1); + co = find_cached_object(real); if (co) { if (oi-typep) *(oi-typep) = co-type; @@ -2461,23 +2462,23 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, return 0; } - if (!find_pack_entry(sha1, e)) { + if (!find_pack_entry(real, e)) { /* Most likely it's a loose object. */ - if (!sha1_loose_object_info(sha1, oi)) { + if (!sha1_loose_object_info(real, oi)) { oi-whence = OI_LOOSE; return 0; } /* Not a loose object; someone else may have just packed it. */ reprepare_packed_git(); - if (!find_pack_entry(sha1, e)) + if (!find_pack_entry(real, e)) return -1; } rtype = packed_object_info(e.p, e.offset, oi); if (rtype 0) { - mark_bad_packed_object(e.p, sha1); - return sha1_object_info_extended(sha1, oi, 0); + mark_bad_packed_object(e.p, real); + return sha1_object_info_extended(real, oi, 0); } else if (in_delta_base_cache(e.p, e.offset)) { oi-whence = OI_DBCACHED; } else { diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index b90dbdc..bb785ec 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -276,7 +276,7 @@ test_expect_success '-f option bypasses the type check' ' git replace -f HEAD^ $BLOB ' -test_expect_failure 'git cat-file --batch works on replace objects' ' +test_expect_success 'git cat-file --batch works on replace objects' ' git replace | grep $PARA3 echo $PARA3 | git cat-file --batch ' -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 08/10] t6050: add tests for listing with --format
This patch adds tests for git replace -l --format=fmt. 'short', 'medium' and 'full' are the only allowed values for fmt. 'short' is the same as with no --format option. Tests for 'medium' and 'full' are the most needed. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- t/t6050-replace.sh | 37 + 1 file changed, 37 insertions(+) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index bb785ec..e1cc3b8 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -281,6 +281,43 @@ test_expect_success 'git cat-file --batch works on replace objects' ' echo $PARA3 | git cat-file --batch ' +test_expect_success 'test --format bogus' ' + test_must_fail git replace --format bogus /dev/null 21 +' + +test_expect_success 'test --format short' ' + git replace --format=short actual + git replace expected + test_cmp expected actual +' + +test_expect_success 'test --format medium' ' + H1=$(git --no-replace-objects rev-parse HEAD~1) + HT=$(git --no-replace-objects rev-parse HEAD^{tree}) + MYTAG=$(git --no-replace-objects rev-parse mytag) + { + echo $H1 - $BLOB + echo $BLOB - $REPLACED + echo $HT - $H1 + echo $PARA3 - $S + echo $MYTAG - $HASH1 + } | sort expected + git replace -l --format medium | sort actual + test_cmp expected actual +' + +test_expect_failure 'test --format full' ' + { + echo $H1 (commit) - $BLOB (blob) + echo $BLOB (blob) - $REPLACED (blob) + echo $HT (tree) - $H1 (commit) + echo $PARA3 (commit) - $S (commit) + echo $MYTAG (tag) - $HASH1 (commit) + } | sort expected + git replace --format=full | sort actual + test_cmp expected actual +' + test_expect_success 'replace ref cleanup' ' test -n $(git replace) git replace -d $(git replace) -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 07/10] builtin/replace: teach listing using short, medium or full formats
By default when listing replace refs, only the sha1 of the replaced objects are shown. In many cases, it is much nicer to be able to list all the sha1 of the replaced objects along with the sha1 of the replacment objects. And in other cases it might be interesting to also show the types of the replaced and replacement objects. This patch introduce a new --format=fmt option where fmt can be any of the following: 'short': this is the same as when no --format option is used, that is only the sha1 of the replaced objects are shown 'medium': this also lists the sha1 of the replacement objects 'full': this shows the sha1 and the type of both the replaced and the replacement objects Some documentation and some tests will follow. Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/replace.c | 61 --- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index b1bd3ef..9f3619a 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -16,27 +16,65 @@ static const char * const git_replace_usage[] = { N_(git replace [-f] object replacement), N_(git replace -d object...), - N_(git replace -l [pattern]), + N_(git replace [--format=format] [-l [pattern]]), NULL }; +enum repl_fmt { SHORT, MEDIUM, FULL }; + +struct show_data { + const char *pattern; + enum repl_fmt fmt; +}; + static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { - const char *pattern = cb_data; + struct show_data *data = cb_data; + + if (!fnmatch(data-pattern, refname, 0)) { + if (data-fmt == SHORT) + printf(%s\n, refname); + else if (data-fmt == MEDIUM) + printf(%s - %s\n, refname, sha1_to_hex(sha1)); + else { /* data-fmt == FULL */ + unsigned char object[20]; + enum object_type obj_type, repl_type; - if (!fnmatch(pattern, refname, 0)) - printf(%s\n, refname); + if (get_sha1(refname, object)) + return error(Failed to resolve '%s' as a valid ref., refname); + + obj_type = sha1_object_info(object, NULL); + repl_type = sha1_object_info(sha1, NULL); + + printf(%s (%s) - %s (%s)\n, refname, typename(obj_type), + sha1_to_hex(sha1), typename(repl_type)); + } + } return 0; } -static int list_replace_refs(const char *pattern) +static int list_replace_refs(const char *pattern, const char *format) { + struct show_data data; + if (pattern == NULL) pattern = *; + data.pattern = pattern; + + if (format == NULL || *format == '\0' || !strcmp(format, short)) + data.fmt = SHORT; + else if (!strcmp(format, medium)) + data.fmt = MEDIUM; + else if (!strcmp(format, full)) + data.fmt = FULL; + else + die(invalid replace format '%s'\n + valid formats are 'short', 'medium' and 'full'\n, + format); - for_each_replace_ref(show_reference, (void *) pattern); + for_each_replace_ref(show_reference, (void *) data); return 0; } @@ -127,10 +165,12 @@ static int replace_object(const char *object_ref, const char *replace_ref, int cmd_replace(int argc, const char **argv, const char *prefix) { int list = 0, delete = 0, force = 0; + const char *format = NULL; struct option options[] = { OPT_BOOL('l', list, list, N_(list replace refs)), OPT_BOOL('d', delete, delete, N_(delete replace refs)), OPT_BOOL('f', force, force, N_(replace the ref if it exists)), + OPT_STRING(0, format, format, N_(format), N_(use this format)), OPT_END() }; @@ -140,6 +180,10 @@ int cmd_replace(int argc, const char **argv, const char *prefix) usage_msg_opt(-l and -d cannot be used together, git_replace_usage, options); + if (format delete) + usage_msg_opt(--format and -d cannot be used together, + git_replace_usage, options); + if (force (list || delete)) usage_msg_opt(-f cannot be used with -d or -l, git_replace_usage, options); @@ -157,6 +201,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix) if (argc != 2) usage_msg_opt(bad number of arguments, git_replace_usage, options); + if (format
[PATCH v3 10/10] Documentation/git-replace: describe --format option
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- Documentation/git-replace.txt | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index f373ab4..7a07828 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git replace' [-f] object replacement 'git replace' -d object... -'git replace' -l [pattern] +'git replace' [--format=format] [-l [pattern]] DESCRIPTION --- @@ -70,6 +70,23 @@ OPTIONS Typing git replace without arguments, also lists all replace refs. +--format=format:: + When listing, use the specified format, which can be one of + 'short', 'medium' and 'full'. When omitted, the format + defaults to 'short'. + +FORMATS +--- + +The following format are available: + +* 'short': + replaced sha1 +* 'medium': + replaced sha1 - replacement sha1 +* 'full' + replaced sha1 (replaced type) - replacement sha1 (replacement type) + CREATING REPLACEMENT OBJECTS -- 1.8.5.1.102.g090758b -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/10] builtin/replace: teach listing using short, medium or full formats
On Wed, Dec 18, 2013 at 1:37 PM, Karsten Blees karsten.bl...@gmail.com wrote: Am 11.12.2013 08:46, schrieb Christian Couder: +enum repl_fmt { SHORT, MEDIUM, FULL }; SHORT is predefined on Windows, could you choose another name? Ok, I will change to: enum repl_fmt { SHORT_FMT, MEDIUM_FMT, FULL_FMT }; Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/10] builtin/replace: teach listing using short, medium or full formats
On Wed, Dec 18, 2013 at 6:37 PM, Junio C Hamano gits...@pobox.com wrote: Christian Couder christian.cou...@gmail.com writes: On Wed, Dec 18, 2013 at 1:37 PM, Karsten Blees karsten.bl...@gmail.com wrote: Am 11.12.2013 08:46, schrieb Christian Couder: +enum repl_fmt { SHORT, MEDIUM, FULL }; SHORT is predefined on Windows, could you choose another name? Ok, I will change to: enum repl_fmt { SHORT_FMT, MEDIUM_FMT, FULL_FMT }; What are these for in the first place? Your SHORT conflicting with something totally unrelated is a sign that you should be naming them in a way that is more specific to your use. SHORT_FMT is still not specific enough to tell what they are for. With SHOW_REPLACE_ prefix, perhaps? Also perhaps give characterization better than their output lengths? I am ok with SHORT_REPLACE_FMT and so on. My quick read of show_reference() tells me that they are name only, name and value, and something else that does not seem very useful unless you are debugging. Yeah, SHORT_REPLACE_FMT is name only which means something like: $ git replace --format=short 14ac020163ea60a9d683ce68e36c946f31ecc856 4b48deed3a433909bfd6b6ab3d4b91348b6af464 5c37393794868bc8e708cccd7c9d9aaa7a5e53cb a3fb2e1845a1aaf129b7975048973414dc172173 e25dc7954f0832d962347872884aab2dffb426c5 MEDIUM_REPLACE_FMT is name and value, like this: $ git replace --format=medium 14ac020163ea60a9d683ce68e36c946f31ecc856 - 4b48deed3a433909bfd6b6ab3d4b91348b6af464 4b48deed3a433909bfd6b6ab3d4b91348b6af464 - feae347d8510cfba5eb8c8ac80056777b07c2528 5c37393794868bc8e708cccd7c9d9aaa7a5e53cb - 14ac020163ea60a9d683ce68e36c946f31ecc856 a3fb2e1845a1aaf129b7975048973414dc172173 - 9af2a15082b7c95982473e32f3376558c149a7e7 e25dc7954f0832d962347872884aab2dffb426c5 - 00ad688edb1a79423184992de45a5f0322c8bdf5 and FULL _REPLACE_FMT is name with type and value with type, like this: $ git replace --format=full 14ac020163ea60a9d683ce68e36c946f31ecc856 (commit) - 4b48deed3a433909bfd6b6ab3d4b91348b6af464 (blob) 4b48deed3a433909bfd6b6ab3d4b91348b6af464 (blob) - feae347d8510cfba5eb8c8ac80056777b07c2528 (blob) 5c37393794868bc8e708cccd7c9d9aaa7a5e53cb (tree) - 14ac020163ea60a9d683ce68e36c946f31ecc856 (commit) a3fb2e1845a1aaf129b7975048973414dc172173 (commit) - 9af2a15082b7c95982473e32f3376558c149a7e7 (commit) e25dc7954f0832d962347872884aab2dffb426c5 (tag) - 00ad688edb1a79423184992de45a5f0322c8bdf5 (commit) I think this last one might be useful for people replacing objects with objects that have another type. And as we let people do that using --force, it could be useful for them to have a way to easily see what they have done. Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing
On Fri, Dec 20, 2013 at 8:04 AM, Jeff King p...@peff.net wrote: On Fri, Dec 20, 2013 at 07:51:00AM +0100, Johannes Sixt wrote: for (i = 1; i argc *argv[i] == '-'; i++) { const char *arg = argv[i]; + const char *optarg; - if (starts_with(arg, --upload-pack=)) { - args.uploadpack = arg + 14; + if ((optarg = skip_prefix(arg, --upload-pack=)) != NULL) { + args.uploadpack = optarg; Quite frankly, I do not think this is an improvement. The old code is *MUCH* easier to understand because starts_with is clearly a predicate that is either true or false, but the code with skip_prefix is much heavier on the eye with its extra level of parenthesis. That it removes a hard-coded constant does not count much IMHO because it is very clear where the value comes from. Yeah, I agree that is unfortunate. I agree too. Maybe we could have the best of both worlds, like: if (starts_with(arg, --upload-pack=, optarg)) ... use optarg ... Probably we do not want to call it just starts_with, as quite a few callers to do not care about what comes next, and would just pass NULL. I cannot seem to think of a good name, though, as the with means that obvious things like starts_with_value naturally parse as a single (nonsensical) sentence. Something like parse_prefix would work, but it is not as clearly a predicate as starts_with (but we have at least gotten rid of the extra parentheses). Elsewhere in the thread, the concept was discussed of returning the full string to mean did not match, which makes some other idioms simpler (but IMHO makes the simple cases like this even harder to read). My proposal splits the start of string out parameter from the boolean return, so it handles both cases naturally: /* here we care if we saw the prefix, as above */ if (parse_prefix(foo, prefix, the_rest)) ... /* * and here we do not care, and just want to optionally strip the * prefix, and take the full value otherwise; we just have to ignore * the return value in this case. */ parse_prefix(foo, prefix, foo); Yeah, I agree that the function signature you suggest is better, but I like the skip_prefix name better. Or perhaps remove_prefix? Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/10] builtin/replace: teach listing using short, medium or full formats
On Thu, Dec 19, 2013 at 7:58 PM, Junio C Hamano gits...@pobox.com wrote: Christian Couder christian.cou...@gmail.com writes: I think this last one might be useful for people replacing objects with objects that have another type. ... which IIUC is strongly discouraged---didn't you have to tighten it recently? And that makes it useful primarily for debugging unusual situations. Ok, so would you prefer the following: - NAME_ONLY_REPLACE_FMT and --format=name_only instead of SHORT_REPLACE_FMT and --format=short - NAME_AND_VALUE_REPLACE_FMT and --format=name_and_value instead of MEDIUM_REPLACE_FMT and --format=medium - DEBUG_REPLACE_FMT and --format=debug instead of FULL _REPLACE_FMT and --format=full ? Thanks, Christian. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v1 1/3] replace: add --graft option
The usage string for this option is: git replace [-f] --graft commit [parent...] First we create a new commit that is the same as commit except that its parents are [parents...] Then we create a replace ref that replace commit with the commit we just created. With this new option, it should be straightforward to convert grafts to replace refs, with something like: cat .git/info/grafts | while read line do git replace --graft $line; done Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- builtin/replace.c | 84 ++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/builtin/replace.c b/builtin/replace.c index 1bb491d..9d1e82f 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -17,6 +17,7 @@ static const char * const git_replace_usage[] = { N_(git replace [-f] object replacement), N_(git replace [-f] --edit object), + N_(git replace [-f] --graft commit [parent...]), N_(git replace -d object...), N_(git replace [--format=format] [-l [pattern]]), NULL @@ -294,6 +295,76 @@ static int edit_and_replace(const char *object_ref, int force) return replace_object_sha1(object_ref, old, replacement, new, force); } +static int read_sha1_commit(const unsigned char *sha1, struct strbuf *dst) +{ + void *buf; + enum object_type type; + unsigned long size; + + buf = read_sha1_file(sha1, type, size); + if (!buf) + return error(_(cannot read object %s), sha1_to_hex(sha1)); + if (type != OBJ_COMMIT) { + free(buf); + return error(_(object %s is not a commit), sha1_to_hex(sha1)); + } + strbuf_attach(dst, buf, size, size + 1); + return 0; +} + +static int create_graft(int argc, const char **argv, int force) +{ + unsigned char old[20], new[20]; + const char *old_ref = argv[0]; + struct commit *commit; + struct strbuf buf = STRBUF_INIT; + struct strbuf new_parents = STRBUF_INIT; + const char *parent_start, *parent_end; + int i; + + if (get_sha1(old_ref, old) 0) + die(_(Not a valid object name: '%s'), old_ref); + commit = lookup_commit_or_die(old, old_ref); + if (read_sha1_commit(old, buf)) + die(_(Invalid commit: '%s'), old_ref); + + /* make sure the commit is not corrupt */ + if (parse_commit_buffer(commit, buf.buf, buf.len)) + die(_(Could not parse commit: '%s'), old_ref); + + /* find existing parents */ + parent_start = buf.buf; + parent_start += 46; /* tree + hex sha1 + \n */ + parent_end = parent_start; + + while (starts_with(parent_end, parent )) + parent_end += 48; /* parent + hex sha1 + \n */ + + /* prepare new parents */ + for (i = 1; i argc; i++) { + unsigned char sha1[20]; + if (get_sha1(argv[i], sha1) 0) + die(_(Not a valid object name: '%s'), argv[i]); + lookup_commit_or_die(sha1, argv[i]); + strbuf_addf(new_parents, parent %s\n, sha1_to_hex(sha1)); + } + + /* replace existing parents with new ones */ + strbuf_splice(buf, parent_start - buf.buf, parent_end - parent_start, + new_parents.buf, new_parents.len); + + if (write_sha1_file(buf.buf, buf.len, commit_type, new)) + die(_(could not write replacement commit for: '%s'), old_ref); + + strbuf_release(new_parents); + strbuf_release(buf); + + if (!hashcmp(old, new)) + return error(new commit is the same as the old one: '%s', sha1_to_hex(old)); + + return replace_object_sha1(old_ref, old, replacement, new, force); +} + int cmd_replace(int argc, const char **argv, const char *prefix) { int force = 0; @@ -303,12 +374,14 @@ int cmd_replace(int argc, const char **argv, const char *prefix) MODE_LIST, MODE_DELETE, MODE_EDIT, + MODE_GRAFT, MODE_REPLACE } cmdmode = MODE_UNSPECIFIED; struct option options[] = { OPT_CMDMODE('l', list, cmdmode, N_(list replace refs), MODE_LIST), OPT_CMDMODE('d', delete, cmdmode, N_(delete replace refs), MODE_DELETE), OPT_CMDMODE('e', edit, cmdmode, N_(edit existing object), MODE_EDIT), + OPT_CMDMODE('g', graft, cmdmode, N_(change a commit's parents), MODE_GRAFT), OPT_BOOL('f', force, force, N_(replace the ref if it exists)), OPT_STRING(0, format, format, N_(format), N_(use this format)), OPT_END() @@ -325,7 +398,10 @@ int cmd_replace(int argc, const char **argv, const char *prefix) usage_msg_opt(--format cannot be used when not listing, git_replace_usage, options); - if (force cmdmode != MODE_REPLACE
[PATCH v1 0/3] Add --graft option to git replace
Here is a small patch series to implement: git replace [-f] --graft commit [parent...] The changes since the RFC/PATCH are the following: - in patch 1/3, parse_commit_buffer() is now used to make sure commit is not corrupt - patch 2/3 add some tests - patch 3/3 add some documentation About the documentation, maybe we should add that --graft can now be used instead of grafts in .git/info/grafts, and maybe we could add an example that shows how it can be done. Christian Couder (3): replace: add --graft option replace: add test for --graft Documentation: replace: add --graft option Documentation/git-replace.txt | 8 + builtin/replace.c | 84 ++- t/t6050-replace.sh| 12 +++ 3 files changed, 103 insertions(+), 1 deletion(-) -- 1.9.rc0.17.g651113e -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v1 2/3] replace: add test for --graft
Signed-off-by: Christian Couder chrisc...@tuxfamily.org --- t/t6050-replace.sh | 12 1 file changed, 12 insertions(+) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 68b3cb2..ca45a84 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -351,4 +351,16 @@ test_expect_success 'replace ref cleanup' ' test -z $(git replace) ' +test_expect_success '--graft with and without already replaced object' ' + test $(git log --oneline | wc -l) = 7 + git replace --graft $HASH5 + test $(git log --oneline | wc -l) = 3 + git cat-file -p $HASH5 | test_must_fail grep parent + test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 + git replace --force -g $HASH5 $HASH4 $HASH3 + git cat-file -p $HASH5 | grep parent $HASH4 + git cat-file -p $HASH5 | grep parent $HASH3 + git replace -d $HASH5 +' + test_done -- 1.9.rc0.17.g651113e -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v12 10/11] trailer: add tests for commands in config file
And add a few other tests for some special cases. Signed-off-by: Christian Couder chrisc...@tuxfamily.org Signed-off-by: Junio C Hamano gits...@pobox.com --- t/t7513-interpret-trailers.sh | 124 ++ 1 file changed, 124 insertions(+) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 9911c7b..d1e4970 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -441,4 +441,128 @@ test_expect_success 'using ifMissing = doNothing' ' test_cmp expected actual ' +test_expect_success 'with simple command' ' + git config trailer.sign.key Signed-off-by: + git config trailer.sign.where after + git config trailer.sign.ifExists addIfDifferentNeighbor + git config trailer.sign.command echo \A U Thor aut...@example.com\ + cat complex_message_body expected + sed -e s/ Z\$/ / expected -\EOF + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer review: --trailer fix=22 \ + complex_message actual + test_cmp expected actual +' + +test_expect_success 'with command using commiter information' ' + git config trailer.sign.ifExists addIfDifferent + git config trailer.sign.command echo \\$GIT_COMMITTER_NAME \$GIT_COMMITTER_EMAIL\ + cat complex_message_body expected + sed -e s/ Z\$/ / expected -\EOF + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: C O Mitter commit...@example.com + EOF + git interpret-trailers --trailer review: --trailer fix=22 \ + complex_message actual + test_cmp expected actual +' + +test_expect_success 'with command using author information' ' + git config trailer.sign.key Signed-off-by: + git config trailer.sign.where after + git config trailer.sign.ifExists addIfDifferentNeighbor + git config trailer.sign.command echo \\$GIT_AUTHOR_NAME \$GIT_AUTHOR_EMAIL\ + cat complex_message_body expected + sed -e s/ Z\$/ / expected -\EOF + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer review: --trailer fix=22 \ + complex_message actual + test_cmp expected actual +' + +test_expect_success 'setup a commit' ' + echo Content of the first commit. a.txt + git add a.txt + git commit -m Add file a.txt +' + +test_expect_success 'with command using $ARG' ' + git config trailer.fix.ifExists overwrite + git config trailer.fix.command git log -1 --oneline --format=\%h (%s)\ --abbrev-commit --abbrev=14 \$ARG + FIXED=$(git log -1 --oneline --format=%h (%s) --abbrev-commit --abbrev=14 HEAD) + cat complex_message_body expected + sed -e s/ Z\$/ / expected -EOF + Fixes: $FIXED + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer review: --trailer fix=HEAD \ + complex_message actual + test_cmp expected actual +' + +test_expect_success 'with failing command using $ARG' ' + git config trailer.fix.ifExists overwrite + git config trailer.fix.command false \$ARG + cat complex_message_body expected + sed -e s/ Z\$/ / expected -EOF + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer review: --trailer fix=HEAD \ + complex_message actual + test_cmp expected actual +' + +test_expect_success 'with empty tokens' ' + cat expected -EOF + + Signed-off-by: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer : --trailer :test actual -EOF + EOF + test_cmp expected actual +' + +test_expect_success 'with command but no key' ' + git config --unset trailer.sign.key + cat expected -EOF + + sign: A U Thor aut...@example.com + EOF + git interpret-trailers actual -EOF + EOF + test_cmp expected actual +' + +test_expect_success 'with no command and no key' ' + git config --unset trailer.review.key + cat expected -EOF + + review: Junio + sign: A U Thor aut...@example.com + EOF + git interpret-trailers --trailer review:Junio actual -EOF + EOF + test_cmp expected actual +' + test_done -- 1.9.rc0.17