Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nora Puchreiner
Nix
Commits
7abf9911
Commit
7abf9911
authored
21 years ago
by
Eelco Dolstra
Browse files
Options
Downloads
Patches
Plain Diff
* Refactoring.
parent
49bafe1f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/nix-env/Makefile.am
+1
-1
1 addition, 1 deletion
src/nix-env/Makefile.am
src/nix-env/main.cc
+1
-130
1 addition, 130 deletions
src/nix-env/main.cc
src/nix-env/names.cc
+121
-0
121 additions, 0 deletions
src/nix-env/names.cc
src/nix-env/names.hh
+29
-0
29 additions, 0 deletions
src/nix-env/names.hh
with
152 additions
and
131 deletions
src/nix-env/Makefile.am
+
1
−
1
View file @
7abf9911
bin_PROGRAMS
=
nix-env
nix_env_SOURCES
=
main.cc help.txt
nix_env_SOURCES
=
main.cc
names.cc names.hh
help.txt
nix_env_LDADD
=
../libmain/libmain.a ../libexpr/libexpr.a
\
../libstore/libstore.a ../libutil/libutil.a
\
../boost/format/libformat.a
-L
../../externals/inst/lib
-ldb_cxx
\
...
...
This diff is collapsed.
Click to expand it.
src/nix-env/main.cc
+
1
−
130
View file @
7abf9911
#include
<cerrno>
#include
"names.hh"
#include
"globals.hh"
#include
"normalise.hh"
#include
"shared.hh"
...
...
@@ -253,136 +254,6 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
}
struct
DrvName
{
string
fullName
;
string
name
;
string
version
;
unsigned
int
hits
;
/* Parse a derivation name. The `name' part of a derivation name
is everything up to but not including the first dash *not*
followed by a letter. The `version' part is the rest
(excluding the separating dash). E.g., `apache-httpd-2.0.48'
is parsed to (`apache-httpd', '2.0.48'). */
DrvName
(
const
string
&
s
)
:
hits
(
0
)
{
name
=
fullName
=
s
;
for
(
unsigned
int
i
=
0
;
i
<
s
.
size
();
++
i
)
{
/* !!! isalpha/isdigit are affected by the locale. */
if
(
s
[
i
]
==
'-'
&&
i
+
1
<
s
.
size
()
&&
!
isalpha
(
s
[
i
+
1
]))
{
name
=
string
(
s
,
0
,
i
);
version
=
string
(
s
,
i
+
1
);
break
;
}
}
}
bool
matches
(
DrvName
&
n
)
{
if
(
name
!=
"*"
&&
name
!=
n
.
name
)
return
false
;
if
(
version
!=
""
&&
version
!=
n
.
version
)
return
false
;
return
true
;
}
};
string
nextComponent
(
string
::
const_iterator
&
p
,
const
string
::
const_iterator
end
)
{
/* Skip any dots and dashes (component separators). */
while
(
p
!=
end
&&
(
*
p
==
'.'
||
*
p
==
'-'
))
++
p
;
if
(
p
==
end
)
return
""
;
/* If the first character is a digit, consume the longest sequence
of digits. Otherwise, consume the longest sequence of
non-digit, non-separator characters. */
string
s
;
if
(
isdigit
(
*
p
))
while
(
p
!=
end
&&
isdigit
(
*
p
))
s
+=
*
p
++
;
else
while
(
p
!=
end
&&
(
!
isdigit
(
*
p
)
&&
*
p
!=
'.'
&&
*
p
!=
'-'
))
s
+=
*
p
++
;
return
s
;
}
#include
<fstream>
bool
parseInt
(
const
string
&
s
,
int
&
n
)
{
istringstream
st
(
s
);
st
>>
n
;
return
!
st
.
fail
();
}
static
bool
componentsLT
(
const
string
&
c1
,
const
string
&
c2
)
{
int
n1
,
n2
;
bool
c1Num
=
parseInt
(
c1
,
n1
),
c2Num
=
parseInt
(
c2
,
n2
);
if
(
c1Num
&&
c2Num
)
return
n1
<
n2
;
else
if
(
c1
==
""
&&
c2Num
)
return
true
;
else
if
(
c1
==
"pre"
&&
c2
!=
"pre"
)
return
true
;
else
if
(
c2
==
"pre"
)
return
false
;
/* Assume that `2.3a' < `2.3.1'. */
else
if
(
c2Num
)
return
true
;
else
if
(
c1Num
)
return
false
;
else
return
c1
<
c2
;
}
static
int
compareVersions
(
const
string
&
v1
,
const
string
&
v2
)
{
string
::
const_iterator
p1
=
v1
.
begin
();
string
::
const_iterator
p2
=
v2
.
begin
();
while
(
p1
!=
v1
.
end
()
||
p2
!=
v2
.
end
())
{
string
c1
=
nextComponent
(
p1
,
v1
.
end
());
string
c2
=
nextComponent
(
p2
,
v2
.
end
());
if
(
componentsLT
(
c1
,
c2
))
return
-
1
;
else
if
(
componentsLT
(
c2
,
c1
))
return
1
;
}
return
0
;
}
static
void
testCompareVersions
()
{
#define TEST(v1, v2, n) assert( \
compareVersions(v1, v2) == n && compareVersions(v2, v1) == -n)
TEST
(
"1.0"
,
"2.3"
,
-
1
);
TEST
(
"2.1"
,
"2.3"
,
-
1
);
TEST
(
"2.3"
,
"2.3"
,
0
);
TEST
(
"2.5"
,
"2.3"
,
1
);
TEST
(
"3.1"
,
"2.3"
,
1
);
TEST
(
"2.3.1"
,
"2.3"
,
1
);
TEST
(
"2.3.1"
,
"2.3a"
,
1
);
TEST
(
"2.3pre1"
,
"2.3"
,
-
1
);
TEST
(
"2.3pre3"
,
"2.3pre12"
,
-
1
);
TEST
(
"2.3a"
,
"2.3c"
,
-
1
);
TEST
(
"2.3pre1"
,
"2.3c"
,
-
1
);
TEST
(
"2.3pre1"
,
"2.3q"
,
-
1
);
}
typedef
list
<
DrvName
>
DrvNames
;
static
DrvNames
drvNamesFromArgs
(
const
Strings
&
opArgs
)
{
DrvNames
result
;
for
(
Strings
::
const_iterator
i
=
opArgs
.
begin
();
i
!=
opArgs
.
end
();
++
i
)
result
.
push_back
(
DrvName
(
*
i
));
return
result
;
}
static
void
installDerivations
(
EvalState
&
state
,
Path
nePath
,
DrvNames
&
selectors
,
const
Path
&
profile
)
{
...
...
This diff is collapsed.
Click to expand it.
src/nix-env/names.cc
0 → 100644
+
121
−
0
View file @
7abf9911
#include
"names.hh"
/* Parse a derivation name. The `name' part of a derivation name is
everything up to but not including the first dash *not* followed by
a letter. The `version' part is the rest (excluding the separating
dash). E.g., `apache-httpd-2.0.48' is parsed to (`apache-httpd',
'2.0.48'). */
DrvName
::
DrvName
(
const
string
&
s
)
:
hits
(
0
)
{
name
=
fullName
=
s
;
for
(
unsigned
int
i
=
0
;
i
<
s
.
size
();
++
i
)
{
/* !!! isalpha/isdigit are affected by the locale. */
if
(
s
[
i
]
==
'-'
&&
i
+
1
<
s
.
size
()
&&
!
isalpha
(
s
[
i
+
1
]))
{
name
=
string
(
s
,
0
,
i
);
version
=
string
(
s
,
i
+
1
);
break
;
}
}
}
bool
DrvName
::
matches
(
DrvName
&
n
)
{
if
(
name
!=
"*"
&&
name
!=
n
.
name
)
return
false
;
if
(
version
!=
""
&&
version
!=
n
.
version
)
return
false
;
return
true
;
}
static
string
nextComponent
(
string
::
const_iterator
&
p
,
const
string
::
const_iterator
end
)
{
/* Skip any dots and dashes (component separators). */
while
(
p
!=
end
&&
(
*
p
==
'.'
||
*
p
==
'-'
))
++
p
;
if
(
p
==
end
)
return
""
;
/* If the first character is a digit, consume the longest sequence
of digits. Otherwise, consume the longest sequence of
non-digit, non-separator characters. */
string
s
;
if
(
isdigit
(
*
p
))
while
(
p
!=
end
&&
isdigit
(
*
p
))
s
+=
*
p
++
;
else
while
(
p
!=
end
&&
(
!
isdigit
(
*
p
)
&&
*
p
!=
'.'
&&
*
p
!=
'-'
))
s
+=
*
p
++
;
return
s
;
}
#include
<fstream>
static
bool
parseInt
(
const
string
&
s
,
int
&
n
)
{
istringstream
st
(
s
);
st
>>
n
;
return
!
st
.
fail
();
}
static
bool
componentsLT
(
const
string
&
c1
,
const
string
&
c2
)
{
int
n1
,
n2
;
bool
c1Num
=
parseInt
(
c1
,
n1
),
c2Num
=
parseInt
(
c2
,
n2
);
if
(
c1Num
&&
c2Num
)
return
n1
<
n2
;
else
if
(
c1
==
""
&&
c2Num
)
return
true
;
else
if
(
c1
==
"pre"
&&
c2
!=
"pre"
)
return
true
;
else
if
(
c2
==
"pre"
)
return
false
;
/* Assume that `2.3a' < `2.3.1'. */
else
if
(
c2Num
)
return
true
;
else
if
(
c1Num
)
return
false
;
else
return
c1
<
c2
;
}
int
compareVersions
(
const
string
&
v1
,
const
string
&
v2
)
{
string
::
const_iterator
p1
=
v1
.
begin
();
string
::
const_iterator
p2
=
v2
.
begin
();
while
(
p1
!=
v1
.
end
()
||
p2
!=
v2
.
end
())
{
string
c1
=
nextComponent
(
p1
,
v1
.
end
());
string
c2
=
nextComponent
(
p2
,
v2
.
end
());
if
(
componentsLT
(
c1
,
c2
))
return
-
1
;
else
if
(
componentsLT
(
c2
,
c1
))
return
1
;
}
return
0
;
}
static
void
testCompareVersions
()
{
#define TEST(v1, v2, n) assert( \
compareVersions(v1, v2) == n && compareVersions(v2, v1) == -n)
TEST
(
"1.0"
,
"2.3"
,
-
1
);
TEST
(
"2.1"
,
"2.3"
,
-
1
);
TEST
(
"2.3"
,
"2.3"
,
0
);
TEST
(
"2.5"
,
"2.3"
,
1
);
TEST
(
"3.1"
,
"2.3"
,
1
);
TEST
(
"2.3.1"
,
"2.3"
,
1
);
TEST
(
"2.3.1"
,
"2.3a"
,
1
);
TEST
(
"2.3pre1"
,
"2.3"
,
-
1
);
TEST
(
"2.3pre3"
,
"2.3pre12"
,
-
1
);
TEST
(
"2.3a"
,
"2.3c"
,
-
1
);
TEST
(
"2.3pre1"
,
"2.3c"
,
-
1
);
TEST
(
"2.3pre1"
,
"2.3q"
,
-
1
);
}
DrvNames
drvNamesFromArgs
(
const
Strings
&
opArgs
)
{
DrvNames
result
;
for
(
Strings
::
const_iterator
i
=
opArgs
.
begin
();
i
!=
opArgs
.
end
();
++
i
)
result
.
push_back
(
DrvName
(
*
i
));
return
result
;
}
This diff is collapsed.
Click to expand it.
src/nix-env/names.hh
0 → 100644
+
29
−
0
View file @
7abf9911
#ifndef __NAMES_H
#define __NAMES_H
#include
<string>
#include
<list>
#include
"util.hh"
struct
DrvName
{
string
fullName
;
string
name
;
string
version
;
unsigned
int
hits
;
DrvName
(
const
string
&
s
);
bool
matches
(
DrvName
&
n
);
};
typedef
list
<
DrvName
>
DrvNames
;
int
compareVersions
(
const
string
&
v1
,
const
string
&
v2
);
DrvNames
drvNamesFromArgs
(
const
Strings
&
opArgs
);
#endif
/* !__NAMES_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment