@matheusbsbs / matheus-bagliano / commits / f8ec916731
Fork 0

Allow helpers to report in "list" command that the ref is unchanged

Helpers may use a line like "? name unchanged" to specify that there is nothing new at that name, without any git-specific code to determine the correct response. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Nov 18, 2009 at 02:42 UTC f8ec916731ef8d81eefc5db61e3405dade65d821
2 files changed +25 -1
Documentation/git-remote-helpers.txt
+3 -1
@@ -84,7 +84,9 @@ CAPABILITIES
84 REF LIST ATTRIBUTES
85 -------------------
86
87 -None are defined yet, but the caller must accept any which are supplied.
87 +'unchanged'::
88 + This ref is unchanged since the last import or fetch, although
89 + the helper cannot necessarily determine what value that produced.
90
91 Documentation
92 -------------
transport-helper.c
+22
@@ -206,6 +206,22 @@ static int fetch(struct transport *transport,
206 return -1;
207 }
208
209 +static int has_attribute(const char *attrs, const char *attr) {
210 + int len;
211 + if (!attrs)
212 + return 0;
213 +
214 + len = strlen(attr);
215 + for (;;) {
216 + const char *space = strchrnul(attrs, ' ');
217 + if (len == space - attrs && !strncmp(attrs, attr, len))
218 + return 1;
219 + if (!*space)
220 + return 0;
221 + attrs = space + 1;
222 + }
223 +}
224 +
225 static struct ref *get_refs_list(struct transport *transport, int for_push)
226 {
227 struct child_process *helper;
@@ -240,6 +256,12 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
256 (*tail)->symref = xstrdup(buf.buf + 1);
257 else if (buf.buf[0] != '?')
258 get_sha1_hex(buf.buf, (*tail)->old_sha1);
259 + if (eon) {
260 + if (has_attribute(eon + 1, "unchanged")) {
261 + (*tail)->status |= REF_STATUS_UPTODATE;
262 + read_ref((*tail)->name, (*tail)->old_sha1);
263 + }
264 + }
265 tail = &((*tail)->next);
266 }
267 strbuf_release(&buf);