[Cvs-nserver-commits] CVS: cvs-nserver/src rcs.c,1.1.1.7,1.1.1.7.4.1 rcs.h,1.1.1.4,1.1.1.4.4.1
Brought to you by:
tyranny
From: Alexey M. <ty...@us...> - 2002-05-25 20:59:53
|
Update of /cvsroot/cvs-nserver/cvs-nserver/src In directory usw-pr-cvs1:/tmp/cvs-serv5939 Modified Files: Tag: NCLI-1-11-1 rcs.c rcs.h Log Message: branch_for_revision(): returns name of a branch this revision (or tag) is on Index: rcs.c =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/src/rcs.c,v retrieving revision 1.1.1.7 retrieving revision 1.1.1.7.4.1 diff -u -d -r1.1.1.7 -r1.1.1.7.4.1 --- rcs.c 19 May 2001 12:05:05 -0000 1.1.1.7 +++ rcs.c 25 May 2002 20:59:50 -0000 1.1.1.7.4.1 @@ -8419,3 +8419,100 @@ } return label; } + + +/* + + Returns name of the branch which contains `rev' in the `rcs' file. + + `rev' could be either numeric revision number or symbolic tag + (branch tag or simple tag). + + Returns empty string for revisions which lie on the trunk. + + Returns NULL if the tag is not known, or if something generally went + wrong. + + */ + +char* +branch_for_revision (RCSNode* rcs, char* rev) +{ + Node* head, *cur; + int simple_tag = 0; + int all_numeric; + char* p; + char* orig_version; + char* version; + char* branch = NULL; + char* pZ; + char* pT; + char* magic = NULL; + + /* see if the `rev' is all numeric */ + all_numeric = 1; + for (p = rev; *p; p++) { + if (!isdigit(*p) && (*p != '.')) { + all_numeric = 0; + break; + } + } + + /* don't call RCS_getversion if `rev' is all numeric */ + if (all_numeric) + orig_version = rev; + else + orig_version = RCS_getversion(rcs, rev, NULL, 0, &simple_tag); + + version = xstrdup(orig_version); + if (!version) + goto out; + + /* revisions X.Y are always on a trunk */ + if (numdots(version) == 1) { + branch = ""; + goto out; + } + + /* convert `version' (X.Y.Z.T) to a magic branch number (X.Y.0.Z) */ + pT = strrchr(version, '.'); + if (pT == NULL) + error(1, 0, "Internal error: version '%s' does not contain dots", version); + *pT++ = '\0'; + + pZ = strrchr(version, '.'); + if (pZ == NULL) + error(1, 0, "Internal error: version '%s' does not contain enough dots", version); + *pZ++ = '\0'; + + /* "X.Y." + "." + "0" + "." + "Z" + '\0' */ + magic = malloc(strlen(version) + 1 + 1 + 1 + strlen(pZ) + 1); + if (!magic) + goto out; + strcpy(magic, version); + strcat(magic, "."); + strcat(magic, "0"); /* FIXME: actually RCS_MAGIC_BRANCH should be used here */ + strcat(magic, "."); + strcat(magic, pZ); + + /* get a list of symbolic tags, including branches */ + RCS_symbols(rcs); + if (rcs->symbols) { + head = rcs->symbols->list; + for (cur = head->next; cur != head; cur = cur->next) { + if (strcmp(magic, cur->data) == 0) { + branch = cur->key; + goto out; + } + } + } + if (branch == NULL) + error(1, 0, "Internal error: cannot find branch name of magic revision '%s'", magic); + + out: + free(version); + free(magic); + return branch; +} + + Index: rcs.h =================================================================== RCS file: /cvsroot/cvs-nserver/cvs-nserver/src/rcs.h,v retrieving revision 1.1.1.4 retrieving revision 1.1.1.4.4.1 diff -u -d -r1.1.1.4 -r1.1.1.4.4.1 --- rcs.h 19 May 2001 12:05:07 -0000 1.1.1.4 +++ rcs.h 25 May 2002 20:59:50 -0000 1.1.1.4.4.1 @@ -242,6 +242,8 @@ char **, size_t *)); char *make_file_label PROTO ((char *, char *, RCSNode *)); +char* branch_for_revision (RCSNode* rcs, char* rev); + extern int preserve_perms; /* From import.c. */ |