From: Stefan Xenos <sxenos@xxxxxxxxxx> This command lists the ongoing changes from the refs/metas namespace. Signed-off-by: Stefan Xenos <sxenos@xxxxxxxxxx> Signed-off-by: Chris Poucet <poucet@xxxxxxxxxx> --- builtin/change.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/builtin/change.c b/builtin/change.c index b0e29e87ec9..67d708dc8de 100644 --- a/builtin/change.c +++ b/builtin/change.c @@ -6,15 +6,78 @@ #include "config.h" static const char * const builtin_change_usage[] = { + N_("git change list [<pattern>...]"), N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"), NULL }; +static const char * const builtin_list_usage[] = { + N_("git change list [<pattern>...]"), + NULL +}; + static const char * const builtin_update_usage[] = { N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"), NULL }; +static int change_list(int argc, const char **argv, const char* prefix) +{ + struct option options[] = { + OPT_END() + }; + struct ref_filter filter; + /* TODO: See below + struct ref_sorting *sorting; + struct string_list sorting_options = STRING_LIST_INIT_DUP; */ + struct ref_format format = REF_FORMAT_INIT; + struct ref_array array; + int i; + + argc = parse_options(argc, argv, prefix, options, builtin_list_usage, 0); + + setup_ref_filter_porcelain_msg(); + + memset(&filter, 0, sizeof(filter)); + memset(&array, 0, sizeof(array)); + + filter.kind = FILTER_REFS_CHANGES; + filter.name_patterns = argv; + + filter_refs(&array, &filter, FILTER_REFS_CHANGES); + + /* TODO: This causes a crash. It sets one of the atom_value handlers to + * something invalid, which causes a crash later when we call + * show_ref_array_item. Figure out why this happens and put back the sorting. + * + * sorting = ref_sorting_options(&sorting_options); + * ref_array_sort(sorting, &array); */ + + if (!format.format) + format.format = "%(refname:lstrip=1)"; + + if (verify_ref_format(&format)) + die(_("unable to parse format string")); + + for (i = 0; i < array.nr; i++) { + struct strbuf output = STRBUF_INIT; + struct strbuf err = STRBUF_INIT; + if (format_ref_array_item(array.items[i], &format, &output, &err)) + die("%s", err.buf); + fwrite(output.buf, 1, output.len, stdout); + putchar('\n'); + + strbuf_release(&err); + strbuf_release(&output); + } + + ref_array_clear(&array); + /* TODO: see above + ref_sorting_release(sorting); */ + + return 0; +} + struct update_state { int options; const char* change; @@ -188,6 +251,8 @@ int cmd_change(int argc, const char **argv, const char *prefix) if (argc < 1) usage_with_options(builtin_change_usage, options); + else if (!strcmp(argv[0], "list")) + result = change_list(argc, argv, prefix); else if (!strcmp(argv[0], "update")) result = change_update(argc, argv, prefix); else { -- gitgitgadget