35
#include "commit-reach.h"
36
#include "rebase-interactive.h"
37
#include "reset.h"
38
+#include "branch.h"
39
40
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
41
5674
return 0;
5675
}
5676
5677
+struct todo_add_branch_context {
5678
+ struct todo_item *items;
5679
+ size_t items_nr;
5680
+ size_t items_alloc;
5681
+ struct strbuf *buf;
5682
+ struct commit *commit;
5683
+ struct string_list refs_to_oids;
5684
+};
5685
+
5686
+static int add_decorations_to_list(const struct commit *commit,
5687
+ struct todo_add_branch_context *ctx)
5688
+{
5689
+ const struct name_decoration *decoration = get_name_decoration(&commit->object);
5690
+
5691
+ while (decoration) {
5692
+ struct todo_item *item;
5693
+ const char *path;
5694
+ size_t base_offset = ctx->buf->len;
5695
+
5696
+ ALLOC_GROW(ctx->items,
5697
+ ctx->items_nr + 1,
5698
+ ctx->items_alloc);
5699
+ item = &ctx->items[ctx->items_nr];
5700
+ memset(item, 0, sizeof(*item));
5701
+
5702
+ /* If the branch is checked out, then leave a comment instead. */
5703
+ if ((path = branch_checked_out(decoration->name))) {
5704
+ item->command = TODO_COMMENT;
5705
+ strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
5706
+ decoration->name, path);
5707
+ } else {
5708
+ struct string_list_item *sti;
5709
+ item->command = TODO_UPDATE_REF;
5710
+ strbuf_addf(ctx->buf, "%s\n", decoration->name);
5711
+
5712
+ sti = string_list_insert(&ctx->refs_to_oids,
5713
+ decoration->name);
5714
+ sti->util = oiddup(the_hash_algo->null_oid);
5715
+ }
5716
+
5717
+ item->offset_in_buf = base_offset;
5718
+ item->arg_offset = base_offset;
5719
+ item->arg_len = ctx->buf->len - base_offset;
5720
+ ctx->items_nr++;
5721
+
5722
+ decoration = decoration->next;
5723
+ }
5724
+
5725
+ return 0;
5726
+}
5727
+
5728
+/*
5729
+ * For each 'pick' command, find out if the commit has a decoration in
5730
+ * refs/heads/. If so, then add a 'label for-update-refs/' command.
5731
+ */
5732
+static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
5733
+{
5734
+ int i;
5735
+ static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
5736
+ static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
5737
+ static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
5738
+ struct decoration_filter decoration_filter = {
5739
+ .include_ref_pattern = &decorate_refs_include,
5740
+ .exclude_ref_pattern = &decorate_refs_exclude,
5741
+ .exclude_ref_config_pattern = &decorate_refs_exclude_config,
5742
+ };
5743
+ struct todo_add_branch_context ctx = {
5744
+ .buf = &todo_list->buf,
5745
+ .refs_to_oids = STRING_LIST_INIT_DUP,
5746
+ };
5747
+
5748
+ ctx.items_alloc = 2 * todo_list->nr + 1;
5749
+ ALLOC_ARRAY(ctx.items, ctx.items_alloc);
5750
+
5751
+ string_list_append(&decorate_refs_include, "refs/heads/");
5752
+ load_ref_decorations(&decoration_filter, 0);
5753
+
5754
+ for (i = 0; i < todo_list->nr; ) {
5755
+ struct todo_item *item = &todo_list->items[i];
5756
+
5757
+ /* insert ith item into new list */
5758
+ ALLOC_GROW(ctx.items,
5759
+ ctx.items_nr + 1,
5760
+ ctx.items_alloc);
5761
+
5762
+ ctx.items[ctx.items_nr++] = todo_list->items[i++];
5763
+
5764
+ if (item->commit) {
5765
+ ctx.commit = item->commit;
5766
+ add_decorations_to_list(item->commit, &ctx);
5767
+ }
5768
+ }
5769
+
5770
+ string_list_clear(&ctx.refs_to_oids, 1);
5771
+ free(todo_list->items);
5772
+ todo_list->items = ctx.items;
5773
+ todo_list->nr = ctx.items_nr;
5774
+ todo_list->alloc = ctx.items_alloc;
5775
+
5776
+ return 0;
5777
+}
5778
+
5779
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
5780
const char *shortrevisions, const char *onto_name,
5781
struct commit *onto, const struct object_id *orig_head,
5782
struct string_list *commands, unsigned autosquash,
5783
+ unsigned update_refs,
5784
struct todo_list *todo_list)
5785
{
5786
char shortonto[GIT_MAX_HEXSZ + 1];
5799
item->arg_len = item->arg_offset = item->flags = item->offset_in_buf = 0;
5800
}
5801
5802
+ if (update_refs && todo_list_add_update_ref_commands(todo_list))
5803
+ return -1;
5804
+
5805
if (autosquash && todo_list_rearrange_squash(todo_list))
5806
return -1;
5807