commit - 30718c93b068945b03ae008cb2ae6ac36348e206
commit + 6338a6a13e7e3c9768dfd2b2093150dfa4a83029
blob - f6da950edc2f40d5af1db5945ed3f7f3cb9bd4e7
blob + b62a8f059984b904f52333190a6f2e03f1fb5d26
--- got/got.c
+++ got/got.c
{
const struct got_error *err;
struct got_reference *head_symref;
-
- if (verbosity >= 0)
- printf("Setting %s to %s\n", GOT_REF_HEAD,
- got_ref_get_name(target_ref));
err = got_ref_alloc_symref(&head_symref, GOT_REF_HEAD, target_ref);
if (err)
err = got_ref_write(head_symref, repo);
got_ref_close(head_symref);
+ if (err == NULL && verbosity > 0) {
+ printf("Created reference %s: %s\n", GOT_REF_HEAD,
+ got_ref_get_name(target_ref));
+ }
return err;
}
}
return NULL;
+}
+
+static const struct got_error *
+create_ref(const char *refname, struct got_object_id *id,
+ int verbosity, struct got_repository *repo)
+{
+ const struct got_error *err = NULL;
+ struct got_reference *ref;
+ char *id_str;
+
+ err = got_object_id_str(&id_str, id);
+ if (err)
+ return err;
+
+ err = got_ref_alloc(&ref, refname, id);
+ if (err)
+ goto done;
+
+ err = got_ref_write(ref, repo);
+ got_ref_close(ref);
+
+ if (err == NULL && verbosity >= 0)
+ printf("Created reference %s: %s\n", refname, id_str);
+done:
+ free(id_str);
+ return err;
}
static const struct got_error *
TAILQ_FOREACH(pe, &refs, entry) {
const char *refname = pe->path;
struct got_object_id *id = pe->data;
- struct got_reference *ref;
char *remote_refname;
- error = got_ref_alloc(&ref, refname, id);
+ error = create_ref(refname, id, verbosity - 1, repo);
if (error)
goto done;
- error = got_ref_write(ref, repo);
- got_ref_close(ref);
- if (error)
- goto done;
if (mirror_references)
continue;
error = got_error_from_errno("asprintf");
goto done;
}
- error = got_ref_alloc(&ref, remote_refname, id);
+ error = create_ref(remote_refname, id, verbosity - 1, repo);
if (error)
goto done;
- error = got_ref_write(ref, repo);
- got_ref_close(ref);
- if (error)
- goto done;
}
/* Set the HEAD reference if the server provided one. */
goto done;
}
-
if (verbosity >= 0)
printf("Created %s repository '%s'\n",
mirror_references ? "mirrored" : "cloned", repo_path);
free(gitconfig_path);
free(git_url);
return error;
-}
-
-static const struct got_error *
-create_ref(const char *refname, struct got_object_id *id,
- const char *id_str, int verbosity, struct got_repository *repo)
-{
- const struct got_error *err = NULL;
- struct got_reference *ref;
-
- if (verbosity >= 0)
- printf("Creating %s: %s\n", refname, id_str);
-
- err = got_ref_alloc(&ref, refname, id);
- if (err)
- return err;
-
- err = got_ref_write(ref, repo);
- got_ref_close(ref);
- return err;
}
static const struct got_error *
err = got_ref_alloc(&new_ref, got_ref_get_name(ref), new_id);
if (err)
goto done;
- if (verbosity >= 0) {
- printf("Deleting symbolic reference %s -> %s\n",
- got_ref_get_name(ref),
- got_ref_get_symref_target(ref));
- }
err = got_ref_delete(ref, repo);
if (err)
goto done;
if (verbosity >= 0) {
- printf("Setting %s to %s\n", got_ref_get_name(ref),
- new_id_str);
+ printf("Deleted reference %s: %s\n",
+ got_ref_get_name(ref),
+ got_ref_get_symref_target(ref));
}
err = got_ref_write(new_ref, repo);
if (err)
err = got_ref_resolve(&old_id, repo, ref);
if (err)
goto done;
- if (got_object_id_cmp(old_id, new_id) != 0) {
- if (verbosity >= 0) {
- printf("Setting %s to %s\n",
- got_ref_get_name(ref), new_id_str);
- }
- err = got_ref_change_ref(ref, new_id);
- if (err)
- goto done;
- err = got_ref_write(ref, repo);
- if (err)
- goto done;
- }
+ if (got_object_id_cmp(old_id, new_id) == 0)
+ goto done;
+
+ err = got_ref_change_ref(ref, new_id);
+ if (err)
+ goto done;
+ err = got_ref_write(ref, repo);
+ if (err)
+ goto done;
}
+
+ if (verbosity >= 0)
+ printf("Updated reference %s: %s\n", got_ref_get_name(ref),
+ new_id_str);
done:
free(old_id);
free(new_id_str);
if (err)
break;
- if (verbosity >= 0) {
- printf("Deleting %s: %s\n",
- got_ref_get_name(re->ref), id_str);
- }
free(id_str);
err = got_ref_delete(re->ref, repo);
if (err)
break;
+ if (verbosity >= 0) {
+ printf("Deleted reference %s: %s\n",
+ got_ref_get_name(re->ref), id_str);
+ }
}
return err;
struct got_object_id *id = pe->data;
struct got_reference *ref;
char *remote_refname;
-
- error = got_object_id_str(&id_str, id);
- if (error)
- goto done;
if (remote->mirror_references ||
strncmp("refs/tags/", refname, 10) == 0) {
if (error) {
if (error->code != GOT_ERR_NOT_REF)
goto done;
- error = create_ref(refname, id, id_str,
- verbosity, repo);
+ error = create_ref(refname, id, verbosity,
+ repo);
if (error)
goto done;
} else {
if (error) {
if (error->code != GOT_ERR_NOT_REF)
goto done;
- error = create_ref(remote_refname, id, id_str,
+ error = create_ref(remote_refname, id,
verbosity, repo);
if (error)
goto done;
if (error) {
if (error->code != GOT_ERR_NOT_REF)
goto done;
- error = create_ref(refname, id, id_str,
- verbosity, repo);
+ error = create_ref(refname, id, verbosity,
+ repo);
if (error)
goto done;
} else
got_ref_close(ref);
}
- free(id_str);
- id_str = NULL;
}
if (delete_refs)
error = delete_missing_refs(&refs, verbosity, repo);