tweak progress output related to references during clone and fetch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
diff --git a/got/got.c b/got/got.c
index f6da950..b62a8f0 100644
--- a/got/got.c
+++ b/got/got.c
@@ -891,16 +891,16 @@ create_head_ref(struct got_reference *target_ref, int verbosity,
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)
return 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;
}
@@ -934,6 +934,32 @@ list_remote_refs(struct got_pathlist_head *symrefs,
}
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 *
cmd_clone(int argc, char *argv[])
{
const struct got_error *error = NULL;
@@ -1119,14 +1145,9 @@ cmd_clone(int argc, char *argv[])
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);
- if (error)
- goto done;
- error = got_ref_write(ref, repo);
- got_ref_close(ref);
+ error = create_ref(refname, id, verbosity - 1, repo);
if (error)
goto done;
@@ -1142,11 +1163,7 @@ cmd_clone(int argc, char *argv[])
error = got_error_from_errno("asprintf");
goto done;
}
- error = got_ref_alloc(&ref, remote_refname, id);
- if (error)
- goto done;
- error = got_ref_write(ref, repo);
- got_ref_close(ref);
+ error = create_ref(remote_refname, id, verbosity - 1, repo);
if (error)
goto done;
}
@@ -1262,7 +1279,6 @@ cmd_clone(int argc, char *argv[])
goto done;
}
-
if (verbosity >= 0)
printf("Created %s repository '%s'\n",
mirror_references ? "mirrored" : "cloned", repo_path);
@@ -1305,25 +1321,6 @@ done:
}
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 *
update_ref(struct got_reference *ref, struct got_object_id *new_id,
int verbosity, struct got_repository *repo)
{
@@ -1340,17 +1337,13 @@ update_ref(struct got_reference *ref, struct got_object_id *new_id,
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)
@@ -1359,19 +1352,20 @@ update_ref(struct got_reference *ref, struct got_object_id *new_id,
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);
@@ -1426,14 +1420,14 @@ delete_missing_refs(struct got_pathlist_head *their_refs,
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;
@@ -1655,18 +1649,14 @@ cmd_fetch(int argc, char *argv[])
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) {
error = got_ref_open(&ref, repo, refname, 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 {
@@ -1686,7 +1676,7 @@ cmd_fetch(int argc, char *argv[])
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;
@@ -1702,15 +1692,13 @@ cmd_fetch(int argc, char *argv[])
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);