From: Stefan Sperling Subject: Re: handle reference arguments that look like short object IDs To: Christian Weisgerber Cc: gameoftrees@openbsd.org Date: Thu, 10 Mar 2022 22:01:28 +0100 On Thu, Mar 10, 2022 at 09:45:49PM +0100, Christian Weisgerber wrote: > Christian Weisgerber: > > > It looks like > > add_ref() > > cmd_cherrypick() > > cmd_backout() > > don't use got_repo_match_object_id() and have hand-rolled code that > > matches the old logic. > > This switches add_ref() to got_repo_match_object_id(). > The regression tests succeed. > > OK? Yes, thanks! > ----------------------------------------------- > commit 8df42e14fd8adeb0b241cef2d2600352ed887d94 (work) > from: Christian Weisgerber > date: Thu Mar 10 20:40:55 2022 UTC > > make "got ref" match argument against references before matching object IDs > > Use got_repo_match_object_id() instead of hand-rolled code and pick up > the updated handling of reference arguments. > > M got/got.c > > diff 3f2fd00e02ca3a76b51c3e95a6fcf0c3f29ea0e2 3d7b346aea3857eff347f2289ed33714e87a5afc > blob - 5939e9366900091eb56fe2aa3cdbe21f4f7a63eb > blob + a8e02bf8f39f50b80a56e690e28c3ba7851cc7af > --- got/got.c > +++ got/got.c > @@ -5661,8 +5661,9 @@ static const struct got_error * > add_ref(struct got_repository *repo, const char *refname, const char *target) > { > const struct got_error *err = NULL; > - struct got_object_id *id; > + struct got_object_id *id = NULL; > struct got_reference *ref = NULL; > + struct got_reflist_head refs; > > /* > * Don't let the user create a reference name with a leading '-'. > @@ -5672,22 +5673,16 @@ add_ref(struct got_repository *repo, const char *refna > if (refname[0] == '-') > return got_error_path(refname, GOT_ERR_REF_NAME_MINUS); > > - err = got_repo_match_object_id_prefix(&id, target, GOT_OBJ_TYPE_ANY, > - repo); > - if (err) { > - struct got_reference *target_ref; > + TAILQ_INIT(&refs); > + err = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL); > + if (err) > + goto done; > + err = got_repo_match_object_id(&id, NULL, target, GOT_OBJ_TYPE_ANY, > + &refs, repo); > + got_ref_list_free(&refs); > + if (err) > + goto done; > > - if (err->code != GOT_ERR_BAD_OBJ_ID_STR) > - return err; > - err = got_ref_open(&target_ref, repo, target, 0); > - if (err) > - return err; > - err = got_ref_resolve(&id, repo, target_ref); > - got_ref_close(target_ref); > - if (err) > - return err; > - } > - > err = got_ref_alloc(&ref, refname, id); > if (err) > goto done; > > -- > Christian "naddy" Weisgerber naddy@mips.inka.de > >