refs: rename "refname" variables
Try to consistently use the variable name "refname" when referring to a string that names a reference. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Dec 12, 2011 at 06:38 UTC
dfefa935ae050d859022017bf9d5d23f4238a7e5
3 files changed
+175
-163
cache.h
+3
-3
@@ -831,9 +831,9 @@ static inline int get_sha1_with_context(const char *str, unsigned char *sha1, st
831
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
832
833
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
834
-extern int read_ref_full(const char *filename, unsigned char *sha1,
834
+extern int read_ref_full(const char *refname, unsigned char *sha1,
835
int reading, int *flags);
836
-extern int read_ref(const char *filename, unsigned char *sha1);
836
+extern int read_ref(const char *refname, unsigned char *sha1);
837
838
/*
839
* Resolve a reference, recursively following symbolic refererences.
@@ -865,7 +865,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
865
*
866
* errno is sometimes set on errors, but not always.
867
*/
868
-extern const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag);
868
+extern const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, int *flag);
869
870
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
871
extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
refs.c
+157
-149
@@ -48,7 +48,7 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
48
return line;
49
}
50
51
-static void add_ref(const char *name, const unsigned char *sha1,
51
+static void add_ref(const char *refname, const unsigned char *sha1,
52
int flag, int check_name, struct ref_array *refs,
53
struct ref_entry **new_entry)
54
{
@@ -56,14 +56,14 @@ static void add_ref(const char *name, const unsigned char *sha1,
56
struct ref_entry *entry;
57
58
/* Allocate it and add it in.. */
59
- len = strlen(name) + 1;
59
+ len = strlen(refname) + 1;
60
entry = xmalloc(sizeof(struct ref_entry) + len);
61
hashcpy(entry->sha1, sha1);
62
hashclr(entry->peeled);
63
if (check_name &&
64
- check_refname_format(name, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
65
- die("Reference has invalid format: '%s'", name);
66
- memcpy(entry->name, name, len);
64
+ check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
65
+ die("Reference has invalid format: '%s'", refname);
66
+ memcpy(entry->name, refname, len);
67
entry->flag = flag;
68
if (new_entry)
69
*new_entry = entry;
@@ -106,20 +106,20 @@ static void sort_ref_array(struct ref_array *array)
106
array->nr = i + 1;
107
}
108
109
-static struct ref_entry *search_ref_array(struct ref_array *array, const char *name)
109
+static struct ref_entry *search_ref_array(struct ref_array *array, const char *refname)
110
{
111
struct ref_entry *e, **r;
112
int len;
113
114
- if (name == NULL)
114
+ if (refname == NULL)
115
return NULL;
116
117
if (!array->nr)
118
return NULL;
119
120
- len = strlen(name) + 1;
120
+ len = strlen(refname) + 1;
121
e = xmalloc(sizeof(struct ref_entry) + len);
122
- memcpy(e->name, name, len);
122
+ memcpy(e->name, refname, len);
123
124
r = bsearch(&e, array->refs, array->nr, sizeof(*array->refs), ref_entry_cmp);
125
@@ -223,7 +223,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
223
224
while (fgets(refline, sizeof(refline), f)) {
225
unsigned char sha1[20];
226
- const char *name;
226
+ const char *refname;
227
static const char header[] = "# pack-refs with:";
228
229
if (!strncmp(refline, header, sizeof(header)-1)) {
@@ -234,9 +234,9 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
234
continue;
235
}
236
237
- name = parse_ref_line(refline, sha1);
238
- if (name) {
239
- add_ref(name, sha1, flag, 1, array, &last);
237
+ refname = parse_ref_line(refline, sha1);
238
+ if (refname) {
239
+ add_ref(refname, sha1, flag, 1, array, &last);
240
continue;
241
}
242
if (last &&
@@ -249,9 +249,9 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
249
sort_ref_array(array);
250
}
251
252
-void add_extra_ref(const char *name, const unsigned char *sha1, int flag)
252
+void add_extra_ref(const char *refname, const unsigned char *sha1, int flag)
253
{
254
- add_ref(name, sha1, flag, 0, &extra_refs, NULL);
254
+ add_ref(refname, sha1, flag, 0, &extra_refs, NULL);
255
}
256
257
void clear_extra_refs(void)
@@ -298,11 +298,11 @@ static void get_ref_dir(const char *submodule, const char *base,
298
if (dir) {
299
struct dirent *de;
300
int baselen = strlen(base);
301
- char *ref = xmalloc(baselen + 257);
301
+ char *refname = xmalloc(baselen + 257);
302
303
- memcpy(ref, base, baselen);
303
+ memcpy(refname, base, baselen);
304
if (baselen && base[baselen-1] != '/')
305
- ref[baselen++] = '/';
305
+ refname[baselen++] = '/';
306
307
while ((de = readdir(dir)) != NULL) {
308
unsigned char sha1[20];
@@ -318,30 +318,30 @@ static void get_ref_dir(const char *submodule, const char *base,
318
continue;
319
if (has_extension(de->d_name, ".lock"))
320
continue;
321
- memcpy(ref + baselen, de->d_name, namelen+1);
321
+ memcpy(refname + baselen, de->d_name, namelen+1);
322
refdir = submodule
323
- ? git_path_submodule(submodule, "%s", ref)
324
- : git_path("%s", ref);
323
+ ? git_path_submodule(submodule, "%s", refname)
324
+ : git_path("%s", refname);
325
if (stat(refdir, &st) < 0)
326
continue;
327
if (S_ISDIR(st.st_mode)) {
328
- get_ref_dir(submodule, ref, array);
328
+ get_ref_dir(submodule, refname, array);
329
continue;
330
}
331
if (submodule) {
332
hashclr(sha1);
333
flag = 0;
334
- if (resolve_gitlink_ref(submodule, ref, sha1) < 0) {
334
+ if (resolve_gitlink_ref(submodule, refname, sha1) < 0) {
335
hashclr(sha1);
336
flag |= REF_ISBROKEN;
337
}
338
- } else if (read_ref_full(ref, sha1, 1, &flag)) {
338
+ } else if (read_ref_full(refname, sha1, 1, &flag)) {
339
hashclr(sha1);
340
flag |= REF_ISBROKEN;
341
}
342
- add_ref(ref, sha1, flag, 1, array, NULL);
342
+ add_ref(refname, sha1, flag, 1, array, NULL);
343
}
344
- free(ref);
344
+ free(refname);
345
closedir(dir);
346
}
347
}
@@ -401,7 +401,8 @@ static struct ref_array *get_loose_refs(const char *submodule)
401
* from "name", which is "module/.git/<refname>". Find <refname> in
402
* the packed-refs file for the submodule.
403
*/
404
-static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result)
404
+static int resolve_gitlink_packed_ref(char *name, int pathlen,
405
+ const char *refname, unsigned char *result)
406
{
407
int retval = -1;
408
struct ref_entry *ref;
@@ -420,7 +421,9 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refna
421
return retval;
422
}
423
423
-static int resolve_gitlink_ref_recursive(char *name, int pathlen, const char *refname, unsigned char *result, int recursion)
424
+static int resolve_gitlink_ref_recursive(char *name, int pathlen,
425
+ const char *refname, unsigned char *result,
426
+ int recursion)
427
{
428
int fd, len = strlen(refname);
429
char buffer[128], *p;
@@ -487,10 +490,10 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re
490
* Try to read ref from the packed references. On success, set sha1
491
* and return 0; otherwise, return -1.
492
*/
490
-static int get_packed_ref(const char *ref, unsigned char *sha1)
493
+static int get_packed_ref(const char *refname, unsigned char *sha1)
494
{
495
struct ref_array *packed = get_packed_refs(NULL);
493
- struct ref_entry *entry = search_ref_array(packed, ref);
496
+ struct ref_entry *entry = search_ref_array(packed, refname);
497
if (entry) {
498
hashcpy(sha1, entry->sha1);
499
return 0;
@@ -498,17 +501,17 @@ static int get_packed_ref(const char *ref, unsigned char *sha1)
501
return -1;
502
}
503
501
-const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
504
+const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, int *flag)
505
{
506
int depth = MAXDEPTH;
507
ssize_t len;
508
char buffer[256];
506
- static char ref_buffer[256];
509
+ static char refname_buffer[256];
510
511
if (flag)
512
*flag = 0;
513
511
- if (check_refname_format(ref, REFNAME_ALLOW_ONELEVEL))
514
+ if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
515
return NULL;
516
517
for (;;) {
@@ -520,7 +523,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
523
if (--depth < 0)
524
return NULL;
525
523
- git_snpath(path, sizeof(path), "%s", ref);
526
+ git_snpath(path, sizeof(path), "%s", refname);
527
528
if (lstat(path, &st) < 0) {
529
if (errno != ENOENT)
@@ -529,17 +532,17 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
532
* The loose reference file does not exist;
533
* check for a packed reference.
534
*/
532
- if (!get_packed_ref(ref, sha1)) {
535
+ if (!get_packed_ref(refname, sha1)) {
536
if (flag)
537
*flag |= REF_ISPACKED;
535
- return ref;
538
+ return refname;
539
}
540
/* The reference is not a packed reference, either. */
541
if (reading) {
542
return NULL;
543
} else {
544
hashclr(sha1);
542
- return ref;
545
+ return refname;
546
}
547
}
548
@@ -551,8 +554,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
554
buffer[len] = 0;
555
if (!prefixcmp(buffer, "refs/") &&
556
!check_refname_format(buffer, 0)) {
554
- strcpy(ref_buffer, buffer);
555
- ref = ref_buffer;
557
+ strcpy(refname_buffer, buffer);
558
+ refname = refname_buffer;
559
if (flag)
560
*flag |= REF_ISSYMREF;
561
continue;
@@ -595,7 +598,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
598
*flag |= REF_ISBROKEN;
599
return NULL;
600
}
598
- ref = strcpy(ref_buffer, buf);
601
+ refname = strcpy(refname_buffer, buf);
602
}
603
/* Please note that FETCH_HEAD has a second line containing other data. */
604
if (get_sha1_hex(buffer, sha1) || (buffer[40] != '\0' && !isspace(buffer[40]))) {
@@ -603,7 +606,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
606
*flag |= REF_ISBROKEN;
607
return NULL;
608
}
606
- return ref;
609
+ return refname;
610
}
611
612
/* The argument to filter_refs */
@@ -613,16 +616,16 @@ struct ref_filter {
616
void *cb_data;
617
};
618
616
-int read_ref_full(const char *ref, unsigned char *sha1, int reading, int *flags)
619
+int read_ref_full(const char *refname, unsigned char *sha1, int reading, int *flags)
620
{
618
- if (resolve_ref(ref, sha1, reading, flags))
621
+ if (resolve_ref(refname, sha1, reading, flags))
622
return 0;
623
return -1;
624
}
625
623
-int read_ref(const char *ref, unsigned char *sha1)
626
+int read_ref(const char *refname, unsigned char *sha1)
627
{
625
- return read_ref_full(ref, sha1, 1, NULL);
628
+ return read_ref_full(refname, sha1, 1, NULL);
629
}
630
631
#define DO_FOR_EACH_INCLUDE_BROKEN 01
@@ -644,23 +647,23 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
647
return fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
648
}
649
647
-static int filter_refs(const char *ref, const unsigned char *sha, int flags,
648
- void *data)
650
+static int filter_refs(const char *refname, const unsigned char *sha, int flags,
651
+ void *data)
652
{
653
struct ref_filter *filter = (struct ref_filter *)data;
651
- if (fnmatch(filter->pattern, ref, 0))
654
+ if (fnmatch(filter->pattern, refname, 0))
655
return 0;
653
- return filter->fn(ref, sha, flags, filter->cb_data);
656
+ return filter->fn(refname, sha, flags, filter->cb_data);
657
}
658
656
-int peel_ref(const char *ref, unsigned char *sha1)
659
+int peel_ref(const char *refname, unsigned char *sha1)
660
{
661
int flag;
662
unsigned char base[20];
663
struct object *o;
664
662
- if (current_ref && (current_ref->name == ref
663
- || !strcmp(current_ref->name, ref))) {
665
+ if (current_ref && (current_ref->name == refname
666
+ || !strcmp(current_ref->name, refname))) {
667
if (current_ref->flag & REF_KNOWS_PEELED) {
668
hashcpy(sha1, current_ref->peeled);
669
return 0;
@@ -669,12 +672,12 @@ int peel_ref(const char *ref, unsigned char *sha1)
672
goto fallback;
673
}
674
672
- if (read_ref_full(ref, base, 1, &flag))
675
+ if (read_ref_full(refname, base, 1, &flag))
676
return -1;
677
678
if ((flag & REF_ISPACKED)) {
679
struct ref_array *array = get_packed_refs(NULL);
677
- struct ref_entry *r = search_ref_array(array, ref);
680
+ struct ref_entry *r = search_ref_array(array, refname);
681
682
if (r != NULL && r->flag & REF_KNOWS_PEELED) {
683
hashcpy(sha1, r->peeled);
@@ -685,7 +688,7 @@ int peel_ref(const char *ref, unsigned char *sha1)
688
fallback:
689
o = parse_object(base);
690
if (o && o->type == OBJ_TAG) {
688
- o = deref_tag(o, ref, 0);
691
+ o = deref_tag(o, refname, 0);
692
if (o) {
693
hashcpy(sha1, o->sha1);
694
return 0;
@@ -915,16 +918,16 @@ static inline int bad_ref_char(int ch)
918
}
919
920
/*
918
- * Try to read one refname component from the front of ref. Return
921
+ * Try to read one refname component from the front of refname. Return
922
* the length of the component found, or -1 if the component is not
923
* legal.
924
*/
922
-static int check_refname_component(const char *ref, int flags)
925
+static int check_refname_component(const char *refname, int flags)
926
{
927
const char *cp;
928
char last = '\0';
929
927
- for (cp = ref; ; cp++) {
930
+ for (cp = refname; ; cp++) {
931
char ch = *cp;
932
if (ch == '\0' || ch == '/')
933
break;
@@ -936,34 +939,34 @@ static int check_refname_component(const char *ref, int flags)
939
return -1; /* Refname contains "@{". */
940
last = ch;
941
}
939
- if (cp == ref)
942
+ if (cp == refname)
943
return -1; /* Component has zero length. */
941
- if (ref[0] == '.') {
944
+ if (refname[0] == '.') {
945
if (!(flags & REFNAME_DOT_COMPONENT))
946
return -1; /* Component starts with '.'. */
947
/*
948
* Even if leading dots are allowed, don't allow "."
949
* as a component (".." is prevented by a rule above).
950
*/
948
- if (ref[1] == '\0')
951
+ if (refname[1] == '\0')
952
return -1; /* Component equals ".". */
953
}
951
- if (cp - ref >= 5 && !memcmp(cp - 5, ".lock", 5))
954
+ if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
955
return -1; /* Refname ends with ".lock". */
953
- return cp - ref;
956
+ return cp - refname;
957
}
958
956
-int check_refname_format(const char *ref, int flags)
959
+int check_refname_format(const char *refname, int flags)
960
{
961
int component_len, component_count = 0;
962
963
while (1) {
964
/* We are at the start of a path component. */
962
- component_len = check_refname_component(ref, flags);
965
+ component_len = check_refname_component(refname, flags);
966
if (component_len < 0) {
967
if ((flags & REFNAME_REFSPEC_PATTERN) &&
965
- ref[0] == '*' &&
966
- (ref[1] == '\0' || ref[1] == '/')) {
968
+ refname[0] == '*' &&
969
+ (refname[1] == '\0' || refname[1] == '/')) {
970
/* Accept one wildcard as a full refname component. */
971
flags &= ~REFNAME_REFSPEC_PATTERN;
972
component_len = 1;
@@ -972,13 +975,13 @@ int check_refname_format(const char *ref, int flags)
975
}
976
}
977
component_count++;
975
- if (ref[component_len] == '\0')
978
+ if (refname[component_len] == '\0')
979
break;
980
/* Skip to next component. */
978
- ref += component_len + 1;
981
+ refname += component_len + 1;
982
}
983
981
- if (ref[component_len - 1] == '.')
984
+ if (refname[component_len - 1] == '.')
985
return -1; /* Refname ends with '.'. */
986
if (!(flags & REFNAME_ALLOW_ONELEVEL) && component_count < 2)
987
return -1; /* Refname has only one component. */
@@ -1054,22 +1057,22 @@ static int remove_empty_directories(const char *file)
1057
return result;
1058
}
1059
1057
-static int is_refname_available(const char *ref, const char *oldref,
1060
+static int is_refname_available(const char *refname, const char *oldrefname,
1061
struct ref_array *array, int quiet)
1062
{
1060
- int i, namlen = strlen(ref); /* e.g. 'foo/bar' */
1063
+ int i, namlen = strlen(refname); /* e.g. 'foo/bar' */
1064
for (i = 0; i < array->nr; i++ ) {
1065
struct ref_entry *entry = array->refs[i];
1066
/* entry->name could be 'foo' or 'foo/bar/baz' */
1064
- if (!oldref || strcmp(oldref, entry->name)) {
1067
+ if (!oldrefname || strcmp(oldrefname, entry->name)) {
1068
int len = strlen(entry->name);
1069
int cmplen = (namlen < len) ? namlen : len;
1067
- const char *lead = (namlen < len) ? entry->name : ref;
1068
- if (!strncmp(ref, entry->name, cmplen) &&
1070
+ const char *lead = (namlen < len) ? entry->name : refname;
1071
+ if (!strncmp(refname, entry->name, cmplen) &&
1072
lead[cmplen] == '/') {
1073
if (!quiet)
1074
error("'%s' exists; cannot create '%s'",
1072
- entry->name, ref);
1075
+ entry->name, refname);
1076
return 0;
1077
}
1078
}
@@ -1165,10 +1168,12 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
1168
return logs_found;
1169
}
1170
1168
-static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char *old_sha1, int flags, int *type_p)
1171
+static struct ref_lock *lock_ref_sha1_basic(const char *refname,
1172
+ const unsigned char *old_sha1,
1173
+ int flags, int *type_p)
1174
{
1175
char *ref_file;
1171
- const char *orig_ref = ref;
1176
+ const char *orig_refname = refname;
1177
struct ref_lock *lock;
1178
int last_errno = 0;
1179
int type, lflags;
@@ -1178,27 +1183,27 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
1183
lock = xcalloc(1, sizeof(struct ref_lock));
1184
lock->lock_fd = -1;
1185
1181
- ref = resolve_ref(ref, lock->old_sha1, mustexist, &type);
1182
- if (!ref && errno == EISDIR) {
1186
+ refname = resolve_ref(refname, lock->old_sha1, mustexist, &type);
1187
+ if (!refname && errno == EISDIR) {
1188
/* we are trying to lock foo but we used to
1189
* have foo/bar which now does not exist;
1190
* it is normal for the empty directory 'foo'
1191
* to remain.
1192
*/
1188
- ref_file = git_path("%s", orig_ref);
1193
+ ref_file = git_path("%s", orig_refname);
1194
if (remove_empty_directories(ref_file)) {
1195
last_errno = errno;
1191
- error("there are still refs under '%s'", orig_ref);
1196
+ error("there are still refs under '%s'", orig_refname);
1197
goto error_return;
1198
}
1194
- ref = resolve_ref(orig_ref, lock->old_sha1, mustexist, &type);
1199
+ refname = resolve_ref(orig_refname, lock->old_sha1, mustexist, &type);
1200
}
1201
if (type_p)
1202
*type_p = type;
1198
- if (!ref) {
1203
+ if (!refname) {
1204
last_errno = errno;
1205
error("unable to resolve reference %s: %s",
1201
- orig_ref, strerror(errno));
1206
+ orig_refname, strerror(errno));
1207
goto error_return;
1208
}
1209
missing = is_null_sha1(lock->old_sha1);
@@ -1208,7 +1213,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
1213
* name is a proper prefix of our refname.
1214
*/
1215
if (missing &&
1211
- !is_refname_available(ref, NULL, get_packed_refs(NULL), 0)) {
1216
+ !is_refname_available(refname, NULL, get_packed_refs(NULL), 0)) {
1217
last_errno = ENOTDIR;
1218
goto error_return;
1219
}
@@ -1217,12 +1222,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
1222
1223
lflags = LOCK_DIE_ON_ERROR;
1224
if (flags & REF_NODEREF) {
1220
- ref = orig_ref;
1225
+ refname = orig_refname;
1226
lflags |= LOCK_NODEREF;
1227
}
1223
- lock->ref_name = xstrdup(ref);
1224
- lock->orig_ref_name = xstrdup(orig_ref);
1225
- ref_file = git_path("%s", ref);
1228
+ lock->ref_name = xstrdup(refname);
1229
+ lock->orig_ref_name = xstrdup(orig_refname);
1230
+ ref_file = git_path("%s", refname);
1231
if (missing)
1232
lock->force_write = 1;
1233
if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
@@ -1243,20 +1248,21 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
1248
return NULL;
1249
}
1250
1246
-struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
1251
+struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1)
1252
{
1253
char refpath[PATH_MAX];
1249
- if (check_refname_format(ref, 0))
1254
+ if (check_refname_format(refname, 0))
1255
return NULL;
1251
- strcpy(refpath, mkpath("refs/%s", ref));
1256
+ strcpy(refpath, mkpath("refs/%s", refname));
1257
return lock_ref_sha1_basic(refpath, old_sha1, 0, NULL);
1258
}
1259
1255
-struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags)
1260
+struct ref_lock *lock_any_ref_for_update(const char *refname,
1261
+ const unsigned char *old_sha1, int flags)
1262
{
1257
- if (check_refname_format(ref, REFNAME_ALLOW_ONELEVEL))
1263
+ if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
1264
return NULL;
1259
- return lock_ref_sha1_basic(ref, old_sha1, flags, NULL);
1265
+ return lock_ref_sha1_basic(refname, old_sha1, flags, NULL);
1266
}
1267
1268
static struct lock_file packlock;
@@ -1342,97 +1348,97 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
1348
*/
1349
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
1350
1345
-int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1351
+int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
1352
{
1353
unsigned char sha1[20], orig_sha1[20];
1354
int flag = 0, logmoved = 0;
1355
struct ref_lock *lock;
1356
struct stat loginfo;
1351
- int log = !lstat(git_path("logs/%s", oldref), &loginfo);
1357
+ int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
1358
const char *symref = NULL;
1359
1360
if (log && S_ISLNK(loginfo.st_mode))
1355
- return error("reflog for %s is a symlink", oldref);
1361
+ return error("reflog for %s is a symlink", oldrefname);
1362
1357
- symref = resolve_ref(oldref, orig_sha1, 1, &flag);
1363
+ symref = resolve_ref(oldrefname, orig_sha1, 1, &flag);
1364
if (flag & REF_ISSYMREF)
1365
return error("refname %s is a symbolic ref, renaming it is not supported",
1360
- oldref);
1366
+ oldrefname);
1367
if (!symref)
1362
- return error("refname %s not found", oldref);
1368
+ return error("refname %s not found", oldrefname);
1369
1364
- if (!is_refname_available(newref, oldref, get_packed_refs(NULL), 0))
1370
+ if (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL), 0))
1371
return 1;
1372
1367
- if (!is_refname_available(newref, oldref, get_loose_refs(NULL), 0))
1373
+ if (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL), 0))
1374
return 1;
1375
1370
- if (log && rename(git_path("logs/%s", oldref), git_path(TMP_RENAMED_LOG)))
1376
+ if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))
1377
return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
1372
- oldref, strerror(errno));
1378
+ oldrefname, strerror(errno));
1379
1374
- if (delete_ref(oldref, orig_sha1, REF_NODEREF)) {
1375
- error("unable to delete old %s", oldref);
1380
+ if (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {
1381
+ error("unable to delete old %s", oldrefname);
1382
goto rollback;
1383
}
1384
1379
- if (!read_ref_full(newref, sha1, 1, &flag) &&
1380
- delete_ref(newref, sha1, REF_NODEREF)) {
1385
+ if (!read_ref_full(newrefname, sha1, 1, &flag) &&
1386
+ delete_ref(newrefname, sha1, REF_NODEREF)) {
1387
if (errno==EISDIR) {
1382
- if (remove_empty_directories(git_path("%s", newref))) {
1383
- error("Directory not empty: %s", newref);
1388
+ if (remove_empty_directories(git_path("%s", newrefname))) {
1389
+ error("Directory not empty: %s", newrefname);
1390
goto rollback;
1391
}
1392
} else {
1387
- error("unable to delete existing %s", newref);
1393
+ error("unable to delete existing %s", newrefname);
1394
goto rollback;
1395
}
1396
}
1397
1392
- if (log && safe_create_leading_directories(git_path("logs/%s", newref))) {
1393
- error("unable to create directory for %s", newref);
1398
+ if (log && safe_create_leading_directories(git_path("logs/%s", newrefname))) {
1399
+ error("unable to create directory for %s", newrefname);
1400
goto rollback;
1401
}
1402
1403
retry:
1398
- if (log && rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newref))) {
1404
+ if (log && rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", newrefname))) {
1405
if (errno==EISDIR || errno==ENOTDIR) {
1406
/*
1407
* rename(a, b) when b is an existing
1408
* directory ought to result in ISDIR, but
1409
* Solaris 5.8 gives ENOTDIR. Sheesh.
1410
*/
1405
- if (remove_empty_directories(git_path("logs/%s", newref))) {
1406
- error("Directory not empty: logs/%s", newref);
1411
+ if (remove_empty_directories(git_path("logs/%s", newrefname))) {
1412
+ error("Directory not empty: logs/%s", newrefname);
1413
goto rollback;
1414
}
1415
goto retry;
1416
} else {
1417
error("unable to move logfile "TMP_RENAMED_LOG" to logs/%s: %s",
1412
- newref, strerror(errno));
1418
+ newrefname, strerror(errno));
1419
goto rollback;
1420
}
1421
}
1422
logmoved = log;
1423
1418
- lock = lock_ref_sha1_basic(newref, NULL, 0, NULL);
1424
+ lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);
1425
if (!lock) {
1420
- error("unable to lock %s for update", newref);
1426
+ error("unable to lock %s for update", newrefname);
1427
goto rollback;
1428
}
1429
lock->force_write = 1;
1430
hashcpy(lock->old_sha1, orig_sha1);
1431
if (write_ref_sha1(lock, orig_sha1, logmsg)) {
1426
- error("unable to write current sha1 into %s", newref);
1432
+ error("unable to write current sha1 into %s", newrefname);
1433
goto rollback;
1434
}
1435
1436
return 0;
1437
1438
rollback:
1433
- lock = lock_ref_sha1_basic(oldref, NULL, 0, NULL);
1439
+ lock = lock_ref_sha1_basic(oldrefname, NULL, 0, NULL);
1440
if (!lock) {
1435
- error("unable to lock %s for rollback", oldref);
1441
+ error("unable to lock %s for rollback", oldrefname);
1442
goto rollbacklog;
1443
}
1444
@@ -1440,17 +1446,17 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1446
flag = log_all_ref_updates;
1447
log_all_ref_updates = 0;
1448
if (write_ref_sha1(lock, orig_sha1, NULL))
1443
- error("unable to write current sha1 into %s", oldref);
1449
+ error("unable to write current sha1 into %s", oldrefname);
1450
log_all_ref_updates = flag;
1451
1452
rollbacklog:
1447
- if (logmoved && rename(git_path("logs/%s", newref), git_path("logs/%s", oldref)))
1453
+ if (logmoved && rename(git_path("logs/%s", newrefname), git_path("logs/%s", oldrefname)))
1454
error("unable to restore logfile %s from %s: %s",
1449
- oldref, newref, strerror(errno));
1455
+ oldrefname, newrefname, strerror(errno));
1456
if (!logmoved && log &&
1451
- rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", oldref)))
1457
+ rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", oldrefname)))
1458
error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
1453
- oldref, strerror(errno));
1459
+ oldrefname, strerror(errno));
1460
1461
return 1;
1462
}
@@ -1507,16 +1513,16 @@ static int copy_msg(char *buf, const char *msg)
1513
return cp - buf;
1514
}
1515
1510
-int log_ref_setup(const char *ref_name, char *logfile, int bufsize)
1516
+int log_ref_setup(const char *refname, char *logfile, int bufsize)
1517
{
1518
int logfd, oflags = O_APPEND | O_WRONLY;
1519
1514
- git_snpath(logfile, bufsize, "logs/%s", ref_name);
1520
+ git_snpath(logfile, bufsize, "logs/%s", refname);
1521
if (log_all_ref_updates &&
1516
- (!prefixcmp(ref_name, "refs/heads/") ||
1517
- !prefixcmp(ref_name, "refs/remotes/") ||
1518
- !prefixcmp(ref_name, "refs/notes/") ||
1519
- !strcmp(ref_name, "HEAD"))) {
1522
+ (!prefixcmp(refname, "refs/heads/") ||
1523
+ !prefixcmp(refname, "refs/remotes/") ||
1524
+ !prefixcmp(refname, "refs/notes/") ||
1525
+ !strcmp(refname, "HEAD"))) {
1526
if (safe_create_leading_directories(logfile) < 0)
1527
return error("unable to create directory for %s",
1528
logfile);
@@ -1546,7 +1552,7 @@ int log_ref_setup(const char *ref_name, char *logfile, int bufsize)
1552
return 0;
1553
}
1554
1549
-static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
1555
+static int log_ref_write(const char *refname, const unsigned char *old_sha1,
1556
const unsigned char *new_sha1, const char *msg)
1557
{
1558
int logfd, result, written, oflags = O_APPEND | O_WRONLY;
@@ -1559,7 +1565,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
1565
if (log_all_ref_updates < 0)
1566
log_all_ref_updates = !is_bare_repository();
1567
1562
- result = log_ref_setup(ref_name, log_file, sizeof(log_file));
1568
+ result = log_ref_setup(refname, log_file, sizeof(log_file));
1569
if (result)
1570
return result;
1571
@@ -1730,7 +1736,9 @@ static char *ref_msg(const char *line, const char *endp)
1736
return xmemdupz(line, ep - line);
1737
}
1738
1733
-int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
1739
+int read_ref_at(const char *refname, unsigned long at_time, int cnt,
1740
+ unsigned char *sha1, char **msg,
1741
+ unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
1742
{
1743
const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
1744
char *tz_c;
@@ -1741,7 +1749,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1749
void *log_mapped;
1750
size_t mapsz;
1751
1744
- logfile = git_path("logs/%s", ref);
1752
+ logfile = git_path("logs/%s", refname);
1753
logfd = open(logfile, O_RDONLY, 0);
1754
if (logfd < 0)
1755
die_errno("Unable to read log '%s'", logfile);
@@ -1834,14 +1842,14 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1842
return 1;
1843
}
1844
1837
-int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs, void *cb_data)
1845
+int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long ofs, void *cb_data)
1846
{
1847
const char *logfile;
1848
FILE *logfp;
1849
struct strbuf sb = STRBUF_INIT;
1850
int ret = 0;
1851
1844
- logfile = git_path("logs/%s", ref);
1852
+ logfile = git_path("logs/%s", refname);
1853
logfp = fopen(logfile, "r");
1854
if (!logfp)
1855
return -1;
@@ -1892,9 +1900,9 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs,
1900
return ret;
1901
}
1902
1895
-int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1903
+int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data)
1904
{
1897
- return for_each_recent_reflog_ent(ref, fn, 0, cb_data);
1905
+ return for_each_recent_reflog_ent(refname, fn, 0, cb_data);
1906
}
1907
1908
static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
@@ -2014,7 +2022,7 @@ static void gen_scanf_fmt(char *scanf_fmt, const char *rule)
2022
return;
2023
}
2024
2017
-char *shorten_unambiguous_ref(const char *ref, int strict)
2025
+char *shorten_unambiguous_ref(const char *refname, int strict)
2026
{
2027
int i;
2028
static char **scanf_fmts;
@@ -2043,10 +2051,10 @@ char *shorten_unambiguous_ref(const char *ref, int strict)
2051
2052
/* bail out if there are no rules */
2053
if (!nr_rules)
2046
- return xstrdup(ref);
2054
+ return xstrdup(refname);
2055
2048
- /* buffer for scanf result, at most ref must fit */
2049
- short_name = xstrdup(ref);
2056
+ /* buffer for scanf result, at most refname must fit */
2057
+ short_name = xstrdup(refname);
2058
2059
/* skip first rule, it will always match */
2060
for (i = nr_rules - 1; i > 0 ; --i) {
@@ -2054,7 +2062,7 @@ char *shorten_unambiguous_ref(const char *ref, int strict)
2062
int rules_to_fail = i;
2063
int short_name_len;
2064
2057
- if (1 != sscanf(ref, scanf_fmts[i], short_name))
2065
+ if (1 != sscanf(refname, scanf_fmts[i], short_name))
2066
continue;
2067
2068
short_name_len = strlen(short_name);
@@ -2098,5 +2106,5 @@ char *shorten_unambiguous_ref(const char *ref, int strict)
2106
}
2107
2108
free(short_name);
2101
- return xstrdup(ref);
2109
+ return xstrdup(refname);
2110
}
refs.h
+15
-11
@@ -60,14 +60,16 @@ extern void add_extra_ref(const char *refname, const unsigned char *sha1, int fl
60
extern void clear_extra_refs(void);
61
extern int ref_exists(const char *);
62
63
-extern int peel_ref(const char *, unsigned char *);
63
+extern int peel_ref(const char *refname, unsigned char *sha1);
64
65
/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/
66
-extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1);
66
+extern struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1);
67
68
/** Locks any ref (for 'HEAD' type refs). */
69
#define REF_NODEREF 0x01
70
-extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags);
70
+extern struct ref_lock *lock_any_ref_for_update(const char *refname,
71
+ const unsigned char *old_sha1,
72
+ int flags);
73
74
/** Close the file descriptor owned by a lock and return the status */
75
extern int close_ref(struct ref_lock *lock);
@@ -93,12 +95,14 @@ extern void invalidate_ref_cache(const char *submodule);
95
int log_ref_setup(const char *ref_name, char *logfile, int bufsize);
96
97
/** Reads log for the value of ref during at_time. **/
96
-extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
98
+extern int read_ref_at(const char *refname, unsigned long at_time, int cnt,
99
+ unsigned char *sha1, char **msg,
100
+ unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
101
102
/* iterate over reflog entries */
103
typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *);
100
-int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data);
101
-int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long, void *cb_data);
104
+int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);
105
+int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long, void *cb_data);
106
107
/*
108
* Calls the specified function for each reflog file until it returns nonzero,
@@ -111,9 +115,9 @@ extern int for_each_reflog(each_ref_fn, void *);
115
#define REFNAME_DOT_COMPONENT 4
116
117
/*
114
- * Return 0 iff ref has the correct format for a refname according to
115
- * the rules described in Documentation/git-check-ref-format.txt. If
116
- * REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level
118
+ * Return 0 iff refname has the correct format for a refname according
119
+ * to the rules described in Documentation/git-check-ref-format.txt.
120
+ * If REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level
121
* reference names. If REFNAME_REFSPEC_PATTERN is set in flags, then
122
* allow a "*" wildcard character in place of one of the name
123
* components. No leading or repeated slashes are accepted. If
@@ -121,10 +125,10 @@ extern int for_each_reflog(each_ref_fn, void *);
125
* components to start with "." (but not a whole component equal to
126
* "." or "..").
127
*/
124
-extern int check_refname_format(const char *ref, int flags);
128
+extern int check_refname_format(const char *refname, int flags);
129
130
extern const char *prettify_refname(const char *refname);
127
-extern char *shorten_unambiguous_ref(const char *ref, int strict);
131
+extern char *shorten_unambiguous_ref(const char *refname, int strict);
132
133
/** rename ref, return 0 on success **/
134
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);