Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/cs/vcs_src/vcs_dir.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
/*
21
* rs_dir()
22
*/
23
24
#include "vcs_rscs.h"
25
26
static time_t now;
27
28
static rdirent_t* add_entry(head, tp)
29
rdirent_t* head;
30
tag_t* tp;
31
{
32
register rdirent_t* ndp;
33
register rdirent_t* dp;
34
register rdirent_t** prev_posn;
35
int result;
36
tag_t* ntp;
37
char* link = NULL;
38
int marker;
39
40
41
if (R_ISLINK(tp))
42
link = rs_readlink(tp->version);
43
44
marker = (R_ISMARKER(tp) ? 1 : 0);
45
46
47
48
dp = head;
49
prev_posn = &head;
50
while (dp != NULL)
51
{
52
if (!marker && R_ISMARKER(dp->tag))
53
{
54
if ((dp->tag->stat.st_ctime < tp->stat.st_ctime) && markermatch(dp->tag->version, tp->version))
55
{
56
*prev_posn = dp->next;
57
ndp = dp->next;
58
free((char *)dp->tag);
59
free((char *)dp);
60
dp = ndp;
61
continue;
62
}
63
}
64
if ((result = strcmp(dp->tag->version, tp->version)) == 0)
65
{
66
/* check if the minor key (domain) is the same */
67
if (dp->tag->domain == tp->domain)
68
{
69
if (dp->tag->stat.st_ctime > tp->stat.st_ctime)
70
return (head);
71
ntp = (tag_t *)malloc(tp->length);
72
memcpy((char *)ntp, (char *)tp, tp->length);
73
free((char *)dp->tag);
74
dp->tag = ntp;
75
if (R_ISLINK(tp) && link)
76
dp->link = strdup(link);
77
return (head);
78
}
79
}
80
else if (result > 0)
81
{
82
ndp = (rdirent_t *)malloc(sizeof(rdirent_t));
83
ntp = (tag_t *)malloc(tp->length);
84
memcpy((char *)ntp, (char *)tp, tp->length);
85
ndp->tag = ntp;
86
ndp->next = dp;
87
if (R_ISLINK(tp) && link)
88
ndp->link = strdup(link);
89
*prev_posn = ndp;
90
return (head);
91
}
92
prev_posn = &(dp->next);
93
dp = dp->next;
94
}
95
ndp = (rdirent_t *)malloc(sizeof(rdirent_t));
96
ntp = (tag_t *)malloc(tp->length);
97
memcpy((char *)ntp, (char *)tp, tp->length);
98
ndp->tag = ntp;
99
ndp->next = NULL;
100
if (R_ISLINK(tp) && link)
101
ndp->link = strdup(link);
102
*prev_posn = ndp;
103
return (head);
104
}
105
106
107
rdirent_t* rs_dir(rf, ap)
108
Sfio_t* rf;
109
register attr_t* ap;
110
{
111
tag_t tag;
112
register tag_t* tp;
113
rdirent_t* head;
114
register rdirent_t* dp;
115
register rdirent_t* ndp;
116
register rdirent_t** prev_posn;
117
118
now = cs.time;
119
120
tp = &tag;
121
head = NULL;
122
TOLOG(rf, ap);
123
while(get_tag(rf, tp))
124
head = add_entry(head, tp);
125
126
TOTAG(rf, ap);
127
while((WHERE(rf)<ap->del_reg) && get_tag(rf, tp))
128
head = add_entry(head, tp);
129
130
/*
131
* remove expired marker
132
*/
133
dp = head;
134
prev_posn = &head;
135
while (dp != NULL)
136
{
137
if (R_ISMARKER(dp->tag) && dp->tag->stat.st_mtime < now)
138
{
139
*prev_posn = dp->next;
140
ndp = dp->next;
141
free((char *)dp->tag);
142
free((char *)dp);
143
dp = ndp;
144
}
145
else
146
{
147
prev_posn = &(dp->next);
148
dp = dp->next;
149
}
150
151
}
152
153
return (head);
154
155
}
156
157
158
159
160
161