Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
514f7135
Commit
514f7135
authored
Feb 26, 2018
by
Claes Sjofors
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wb revision, git-tree and git-work in git command, and all wb_rev files automatically added to repo
parent
f67a3cac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
56 deletions
+35
-56
wb/lib/wb/src/wb_revision.cpp
wb/lib/wb/src/wb_revision.cpp
+32
-55
wb/lib/wb/src/wb_revision.h
wb/lib/wb/src/wb_revision.h
+3
-1
No files found.
wb/lib/wb/src/wb_revision.cpp
View file @
514f7135
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#include <vector>
#include <vector>
#include "pwr.h"
#include "pwr.h"
#include "co_time.h"
#include "co_time.h"
#include "co_dcli.h"
#include "wb_revision.h"
#include "wb_revision.h"
#include "wb_lfu.h"
#include "wb_lfu.h"
#include "wb_log.h"
#include "wb_log.h"
...
@@ -151,6 +152,8 @@ pwr_tStatus wb_revision::create( int all, char *name, char *descr)
...
@@ -151,6 +152,8 @@ pwr_tStatus wb_revision::create( int all, char *name, char *descr)
pwr_tCmd
cmd
;
pwr_tCmd
cmd
;
bool
in_main
=
false
;
bool
in_main
=
false
;
int
main_idx
;
int
main_idx
;
pwr_tFileName
file_spec
,
found_file
;
pwr_tStatus
lsts
;
// Create is allowed only if revision is an end node
// Create is allowed only if revision is an end node
if
(
m_current_sub_idx
==
-
1
&&
m_current_main_idx
==
-
1
)
{
if
(
m_current_sub_idx
==
-
1
&&
m_current_main_idx
==
-
1
)
{
...
@@ -200,6 +203,13 @@ pwr_tStatus wb_revision::create( int all, char *name, char *descr)
...
@@ -200,6 +203,13 @@ pwr_tStatus wb_revision::create( int all, char *name, char *descr)
// Commit revision
// Commit revision
if
(
m_manager
)
{
if
(
m_manager
)
{
// Check that the wb_rev files are added to repo
strcpy
(
file_spec
,
"$pwrp_db/*.wb_rev"
);
for
(
lsts
=
dcli_search_file
(
file_spec
,
found_file
,
DCLI_DIR_SEARCH_INIT
);
ODD
(
lsts
);
lsts
=
dcli_search_file
(
file_spec
,
found_file
,
DCLI_DIR_SEARCH_NEXT
))
m_manager
->
check_add
(
found_file
);
m_sts
=
m_manager
->
store_revision
(
name
,
descr
,
in_main
);
m_sts
=
m_manager
->
store_revision
(
name
,
descr
,
in_main
);
if
(
EVEN
(
m_sts
))
return
m_sts
;
if
(
EVEN
(
m_sts
))
return
m_sts
;
}
}
...
@@ -774,8 +784,9 @@ void wb_version_manager_git::init()
...
@@ -774,8 +784,9 @@ void wb_version_manager_git::init()
pwr_tTime
t
;
pwr_tTime
t
;
bool
new_git
=
false
;
bool
new_git
=
false
;
dcli_translate_filename
(
fname
,
"$pwrp_root/src/.git"
);
dcli_translate_filename
(
m_git_dir
,
"$pwrp_root/src/.git"
);
if
(
EVEN
(
dcli_file_time
(
fname
,
&
t
)))
{
dcli_translate_filename
(
m_work_tree
,
"$pwrp_root/src"
);
if
(
EVEN
(
dcli_file_time
(
m_git_dir
,
&
t
)))
{
// No git repository found, init git
// No git repository found, init git
strcpy
(
cmd
,
"git init $pwrp_root/src"
);
strcpy
(
cmd
,
"git init $pwrp_root/src"
);
...
@@ -824,10 +835,10 @@ db/rt_eventlog_info.txt" << endl;
...
@@ -824,10 +835,10 @@ db/rt_eventlog_info.txt" << endl;
}
}
if
(
new_git
)
{
if
(
new_git
)
{
s
trcpy
(
cmd
,
"cd $pwrp_root/src; git add ."
);
s
nprintf
(
cmd
,
sizeof
(
cmd
),
"git --git-dir=%s --work-tree=%s add ."
,
m_git_dir
,
m_work_tree
);
system
(
cmd
);
system
(
cmd
);
s
trcpy
(
cmd
,
"cd $pwrp_root/src; git commit -m
\"
Initial commit
\"
-a"
);
s
nprintf
(
cmd
,
sizeof
(
cmd
),
"git --git-dir=%s --work-tree=%s commit -m
\"
Initial commit
\"
-a"
,
m_git_dir
,
m_work_tree
);
system
(
cmd
);
system
(
cmd
);
}
}
...
@@ -839,7 +850,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
...
@@ -839,7 +850,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
int
sts
;
int
sts
;
// Commit all changes
// Commit all changes
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
commit -m
\"
%s
\"
-a"
,
descr
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s commit -m
\"
%s
\"
-a"
,
m_git_dir
,
m_work_tree
,
descr
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
{
if
(
sts
!=
0
)
{
...
@@ -848,7 +859,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
...
@@ -848,7 +859,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
}
}
// Tag last commit
// Tag last commit
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
tag
\"
%s
\"\n
"
,
name
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s tag
\"
%s
\"\n
"
,
m_git_dir
,
m_work_tree
,
name
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
{
if
(
sts
!=
0
)
{
...
@@ -858,7 +869,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
...
@@ -858,7 +869,7 @@ int wb_version_manager_git::store_revision( char *name, char *descr, bool new_br
if
(
new_branch
)
{
if
(
new_branch
)
{
// Create branch on last commit
// Create branch on last commit
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
branch
\"
%s
\"\n
"
,
wb_revision
::
branch_name
(
name
));
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s branch
\"
%s
\"\n
"
,
m_git_dir
,
m_work_tree
,
wb_revision
::
branch_name
(
name
));
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
{
if
(
sts
!=
0
)
{
...
@@ -878,15 +889,15 @@ int wb_version_manager_git::restore_revision( char *name, char *branch, int chec
...
@@ -878,15 +889,15 @@ int wb_version_manager_git::restore_revision( char *name, char *branch, int chec
if
(
checkout_master
)
{
if
(
checkout_master
)
{
// Checkout master branch
// Checkout master branch
s
trcpy
(
cmd
,
"git checkout master"
);
s
nprintf
(
cmd
,
sizeof
(
cmd
),
"git --git-dir=%s --work-tree=%s checkout master"
,
m_git_dir
,
m_work_tree
);
}
}
else
if
(
checkout_branch
)
{
else
if
(
checkout_branch
)
{
// Checkout supplied branch
// Checkout supplied branch
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
checkout
\"
%s
\"
"
,
branch
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s checkout
\"
%s
\"
"
,
m_git_dir
,
m_work_tree
,
branch
);
}
}
else
{
else
{
// Checkout supplied tag
// Checkout supplied tag
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
checkout
\"
%s
\"
"
,
name
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s checkout
\"
%s
\"
"
,
m_git_dir
,
m_work_tree
,
name
);
}
}
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
...
@@ -907,7 +918,7 @@ int wb_version_manager_git::get_current( char *name)
...
@@ -907,7 +918,7 @@ int wb_version_manager_git::get_current( char *name)
dcli_translate_filename
(
fname
,
fname
);
dcli_translate_filename
(
fname
,
fname
);
// Get current tag
// Get current tag
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
describe --tags --abbrev=0 > %s 2>/dev/null"
,
fname
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s describe --tags --abbrev=0 > %s 2>/dev/null"
,
m_git_dir
,
m_work_tree
,
fname
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
{
if
(
sts
!=
0
)
{
// printf( "** Error from git describe %d\n", sts >> 8);
// printf( "** Error from git describe %d\n", sts >> 8);
...
@@ -940,10 +951,10 @@ int wb_version_manager_git::check( vector<wb_rev_item>& v)
...
@@ -940,10 +951,10 @@ int wb_version_manager_git::check( vector<wb_rev_item>& v)
dcli_translate_filename
(
fname
,
fname
);
dcli_translate_filename
(
fname
,
fname
);
// Get current tag
// Get current tag
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
tag > %s"
,
fname
);
snprintf
(
cmd
,
sizeof
(
cmd
),
"git
--git-dir=%s --work-tree=%s tag > %s"
,
m_git_dir
,
m_work_tree
,
fname
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
{
if
(
sts
!=
0
)
{
printf
(
"** Error from git
describe
%d
\n
"
,
sts
>>
8
);
printf
(
"** Error from git
tag
%d
\n
"
,
sts
>>
8
);
return
REV__GITERROR
;
return
REV__GITERROR
;
}
}
...
@@ -983,55 +994,21 @@ int wb_version_manager_git::check( vector<wb_rev_item>& v)
...
@@ -983,55 +994,21 @@ int wb_version_manager_git::check( vector<wb_rev_item>& v)
int
wb_version_manager_git
::
check_add
(
char
*
filename
)
int
wb_version_manager_git
::
check_add
(
char
*
filename
)
{
{
pwr_tCmd
cmd
;
pwr_tCmd
cmd
;
pwr_tFileName
fname
,
f2name
;
pwr_tFileName
fname
;
char
*
s
,
*
s1
=
0
;
pwr_tFileName
rname
=
"$pwrp_tmp/gitresult.tmp"
;
char
line
[
200
];
int
sts
;
int
sts
;
dcli_translate_filename
(
rname
,
rname
);
dcli_translate_filename
(
fname
,
filename
);
dcli_translate_filename
(
f2name
,
filename
);
int
cnt
=
0
;
sprintf
(
cmd
,
"git --git-dir=%s --work-tree=%s ls-files --error-unmatch %s >/dev/null 2>/dev/null"
,
m_git_dir
,
m_work_tree
,
fname
);
bool
found
=
false
;
for
(
s
=
&
f2name
[
strlen
(
f2name
)
-
1
];
s
!=
f2name
;
s
--
)
{
if
(
*
s
==
'/'
)
{
cnt
++
;
if
(
cnt
==
2
)
{
strncpy
(
fname
,
s
+
1
,
sizeof
(
fname
));
found
=
true
;
break
;
}
else
s1
=
s
;
}
}
if
(
!
found
&&
s1
)
strncpy
(
fname
,
s1
+
1
,
sizeof
(
fname
));
else
if
(
!
found
)
strncpy
(
fname
,
filename
,
sizeof
(
fname
));
sprintf
(
cmd
,
"cd $pwrp_root/src; git ls-files -o --exclude-standard | grep %s$ > %s"
,
fname
,
rname
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
if
(
sts
==
0
)
return
0
;
// File exist in repo
return
1
;
ifstream
fp
(
rname
);
fp
.
getline
(
line
,
sizeof
(
line
));
fp
.
close
();
dcli_trim
(
line
,
line
);
if
(
strcmp
(
line
,
""
)
==
0
)
return
0
;
sprintf
(
cmd
,
"
cd $pwrp_root/src; git add %s"
,
lin
e
);
sprintf
(
cmd
,
"
git --git-dir=%s --work-tree=%s add %s"
,
m_git_dir
,
m_work_tree
,
fnam
e
);
sts
=
system
(
cmd
);
sts
=
system
(
cmd
);
if
(
sts
!=
0
)
if
(
sts
!=
0
)
printf
(
"** Git error %d
\n
"
,
sts
);
printf
(
"** Git add error %d
\n
"
,
sts
);
sprintf
(
cmd
,
"rm -f %s"
,
rname
);
system
(
cmd
);
return
1
;
return
1
;
}
}
wb/lib/wb/src/wb_revision.h
View file @
514f7135
...
@@ -93,6 +93,8 @@ class wb_version_manager_git : public wb_version_manager
...
@@ -93,6 +93,8 @@ class wb_version_manager_git : public wb_version_manager
public:
public:
wb_version_manager_git
()
:
wb_version_manager
(
pwr_eVersionManagerEnum_None
)
{
init
();}
wb_version_manager_git
()
:
wb_version_manager
(
pwr_eVersionManagerEnum_None
)
{
init
();}
~
wb_version_manager_git
()
{}
~
wb_version_manager_git
()
{}
pwr_tFileName
m_git_dir
;
pwr_tFileName
m_work_tree
;
void
init
();
void
init
();
int
store_revision
(
char
*
name
,
char
*
descr
,
bool
new_branch
);
int
store_revision
(
char
*
name
,
char
*
descr
,
bool
new_branch
);
int
restore_revision
(
char
*
name
,
char
*
branch
,
int
checkout_master
,
int
checkout_branch
);
int
restore_revision
(
char
*
name
,
char
*
branch
,
int
checkout_master
,
int
checkout_branch
);
...
@@ -148,4 +150,4 @@ class wb_revision : public wb_status
...
@@ -148,4 +150,4 @@ class wb_revision : public wb_status
static
int
check_add_file
(
char
*
filename
);
static
int
check_add_file
(
char
*
filename
);
};
};
#endif
#endif
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment