MCPcopy Create free account
hub / github.com/git/git / get_ref_information

Function get_ref_information

replay.c:137–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135};
136
137static void get_ref_information(struct repository *repo,
138 struct rev_cmdline_info *cmd_info,
139 struct ref_info *ref_info)
140{
141 ref_info->onto = NULL;
142 strset_init(&ref_info->positive_refs);
143 strset_init(&ref_info->negative_refs);
144 ref_info->positive_refexprs = 0;
145 ref_info->negative_refexprs = 0;
146
147 /*
148 * When the user specifies e.g.
149 * git replay origin/main..mybranch
150 * git replay ^origin/next mybranch1 mybranch2
151 * we want to be able to determine where to replay the commits. In
152 * these examples, the branches are probably based on an old version
153 * of either origin/main or origin/next, so we want to replay on the
154 * newest version of that branch. In contrast we would want to error
155 * out if they ran
156 * git replay ^origin/master ^origin/next mybranch
157 * git replay mybranch~2..mybranch
158 * the first of those because there's no unique base to choose, and
159 * the second because they'd likely just be replaying commits on top
160 * of the same commit and not making any difference.
161 */
162 for (size_t i = 0; i < cmd_info->nr; i++) {
163 struct rev_cmdline_entry *e = cmd_info->rev + i;
164 struct object_id oid;
165 const char *refexpr = e->name;
166 char *fullname = NULL;
167 int can_uniquely_dwim = 1;
168
169 if (*refexpr == '^')
170 refexpr++;
171 if (repo_dwim_ref(repo, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
172 can_uniquely_dwim = 0;
173
174 if (e->flags & BOTTOM) {
175 if (can_uniquely_dwim)
176 strset_add(&ref_info->negative_refs, fullname);
177 if (!ref_info->negative_refexprs)
178 ref_info->onto = lookup_commit_reference_gently(repo,
179 &e->item->oid, 1);
180 ref_info->negative_refexprs++;
181 } else {
182 if (can_uniquely_dwim)
183 strset_add(&ref_info->positive_refs, fullname);
184 ref_info->positive_refexprs++;
185 }
186
187 free(fullname);
188 }
189}
190
191static void set_up_branch_mode(struct repository *repo,
192 char **branch_name,

Callers 1

set_up_replay_modeFunction · 0.85

Calls 4

strset_initFunction · 0.85
repo_dwim_refFunction · 0.85
strset_addFunction · 0.85

Tested by

no test coverage detected