{"thread":{"id":"12591","subject":"[PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","startedAt":"2008-03-08T23:04:18Z","lastAt":"2008-03-09T06:23:30Z","messageCount":5,"participants":["Daniel Barkalow","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"71464","messageId":"alpine.LNX.1.00.0803081804170.19665@iabervon.org","threadId":"12591","inReplyTo":null,"subject":"[PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-08T23:04:18Z","receivedAt":"2008-03-08T23:04:18Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This is useful, for example, for listing the refs in a reference\nrepository during clone, when you don't have your own refs that cover\nthe objects that are in your alternate repository.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n refs.c |   18 ++++++++++++++++++\n refs.h |    9 +++++++++\n 2 files changed, 27 insertions(+), 0 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1b0050e..356396d 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -159,6 +159,8 @@ static struct cached_refs {\n } cached_refs;\n static struct ref_list *current_ref;\n \n+static struct ref_list *extra_refs;\n+\n static void free_ref_list(struct ref_list *list)\n {\n \tstruct ref_list *next;\n@@ -215,6 +217,17 @@ static void read_packed_refs(FILE *f, struct cached_refs *cached_refs)\n \tcached_refs->packed = sort_ref_list(list);\n }\n \n+void add_extra_ref(const char *name, const unsigned char *sha1, int flag)\n+{\n+\textra_refs = add_ref(name, sha1, flag, extra_refs, NULL);\n+}\n+\n+void clear_extra_refs(void)\n+{\n+\tfree_ref_list(extra_refs);\n+\textra_refs = NULL;\n+}\n+\n static struct ref_list *get_packed_refs(void)\n {\n \tif (!cached_refs.did_packed) {\n@@ -535,6 +548,11 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,\n \tstruct ref_list *packed = get_packed_refs();\n \tstruct ref_list *loose = get_loose_refs();\n \n+\tstruct ref_list *extra;\n+\n+\tfor (extra = extra_refs; extra; extra = extra->next)\n+\t\tretval = do_one_ref(base, fn, trim, cb_data, extra);\n+\n \twhile (packed && loose) {\n \t\tstruct ref_list *entry;\n \t\tint cmp = strcmp(packed->name, loose->name);\ndiff --git a/refs.h b/refs.h\nindex 06abee1..06ad260 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -24,6 +24,15 @@ extern int for_each_tag_ref(each_ref_fn, void *);\n extern int for_each_branch_ref(each_ref_fn, void *);\n extern int for_each_remote_ref(each_ref_fn, void *);\n \n+/*\n+ * Extra refs will be listed by for_each_ref() before any actual refs\n+ * for the duration of this process or until clear_extra_refs() is\n+ * called. Only extra refs added before for_each_ref() is called will\n+ * be listed on a given call of for_each_ref().\n+ */\n+extern void add_extra_ref(const char *refname, const unsigned char *sha1, int flags);\n+extern void clear_extra_refs(void);\n+\n extern int peel_ref(const char *, unsigned char *);\n \n /** Locks a \"refs/\" ref returning the lock on success and NULL on failure. **/\n-- \n1.5.4.3.327.g614d7.dirty\n\n"},{"id":"71473","messageId":"alpine.LSU.1.00.0803090020430.3975@racer.site","threadId":"12591","inReplyTo":"alpine.LNX.1.00.0803081804170.19665@iabervon.org","subject":"Re: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-08T23:22:41Z","receivedAt":"2008-03-08T23:22:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 8 Mar 2008, Daniel Barkalow wrote:\n\n> This is useful, for example, for listing the refs in a reference \n> repository during clone, when you don't have your own refs that cover \n> the objects that are in your alternate repository.\n\nHow about this commit oneline instead:\n\n\tfor_each_ref(): Allow adding extra refs to be traversed\n\nHmm?\n\nYou can explain in the body that the SHA-1s are not verified locally, so \nthat you can add extra refs that do not reference local objects.\n\nCiao,\nDscho\n"},{"id":"71476","messageId":"alpine.LNX.1.00.0803081823230.19665@iabervon.org","threadId":"12591","inReplyTo":"alpine.LSU.1.00.0803090020430.3975@racer.site","subject":"Re: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-08T23:25:23Z","receivedAt":"2008-03-08T23:25:23Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sun, 9 Mar 2008, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Sat, 8 Mar 2008, Daniel Barkalow wrote:\n> \n> > This is useful, for example, for listing the refs in a reference \n> > repository during clone, when you don't have your own refs that cover \n> > the objects that are in your alternate repository.\n> \n> How about this commit oneline instead:\n> \n> \tfor_each_ref(): Allow adding extra refs to be traversed\n> \n> Hmm?\n> \n> You can explain in the body that the SHA-1s are not verified locally, so \n> that you can add extra refs that do not reference local objects.\n\nThe non-local aspect is actually that the repository's refs doesn't \nactually include them. We actually do have these objects, in an alternate \nrepo. Clearly I need a better commit message, with this info not trying to \nfit in the first line.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"71488","messageId":"7vd4q4sg5r.fsf@gitster.siamese.dyndns.org","threadId":"12591","inReplyTo":"alpine.LNX.1.00.0803081804170.19665@iabervon.org","subject":"Re: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-09T03:57:36Z","receivedAt":"2008-03-09T03:57:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> This is useful, for example, for listing the refs in a reference\n> repository during clone, when you don't have your own refs that cover\n> the objects that are in your alternate repository.\n\nI hate to ask a question that I myself do not have a good answer to, but\nit is a bit worrysome that using these extra refs would cause for-each-ref\nto report different refs with the same name (the alternate's master branch\nand this one's master branch are both called refs/heads/master).\n\nI think no caller that reads from for_each_ref() keeps track of names that\nit has seen and tries clever things like flagging duplicates as errors,\nbut it still feels like it is inviting trouble.\n"},{"id":"71492","messageId":"alpine.LNX.1.00.0803090116430.19665@iabervon.org","threadId":"12591","inReplyTo":"7vd4q4sg5r.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-09T06:23:30Z","receivedAt":"2008-03-09T06:23:30Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sat, 8 Mar 2008, Junio C Hamano wrote:\n\n> Daniel Barkalow <barkalow@iabervon.org> writes:\n> \n> > This is useful, for example, for listing the refs in a reference\n> > repository during clone, when you don't have your own refs that cover\n> > the objects that are in your alternate repository.\n> \n> I hate to ask a question that I myself do not have a good answer to, but\n> it is a bit worrysome that using these extra refs would cause for-each-ref\n> to report different refs with the same name (the alternate's master branch\n> and this one's master branch are both called refs/heads/master).\n> \n> I think no caller that reads from for_each_ref() keeps track of names that\n> it has seen and tries clever things like flagging duplicates as errors,\n> but it still feels like it is inviting trouble.\n\nI considered that, and didn't come to any particular conclusion about \nanything to do about it. In the particular case in this series, there are \nno non-extra refs, and the for_each_ref caller doesn't actually look at \nnames at all, so it's really not a problem, but the interface could \ndefinitely generate odd results. For that matter, non-extra refs are \nsorted by name, and the extra refs are just done first. I think additional \ncallers are needed before we can determine in more detail how the \ninterface should work, since none of these details matters at all to this \none.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}