Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git_borg_linker
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
LBMC
Hub
git_borg_linker
Commits
44cbdb91
Commit
44cbdb91
authored
1 year ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/pull.rs src/push.rs: change in order to push/pull the commits pointed by a branch name
parent
c76b6e8a
Branches
master
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pull.rs
+62
-2
62 additions, 2 deletions
src/pull.rs
src/push.rs
+3
-1
3 additions, 1 deletion
src/push.rs
with
65 additions
and
3 deletions
src/pull.rs
+
62
−
2
View file @
44cbdb91
...
...
@@ -12,6 +12,34 @@ use std::path::PathBuf;
use
std
::
process
::
exit
;
use
std
::
process
::
Command
;
use
std
::
process
::
Stdio
;
use
std
::
collections
::
HashMap
;
/// Function used to execute a given command and get it's output
///
/// # Arguments
/// - `prog`: String of the program to execute
/// - `args`: The list of arguments
///
/// # Return
/// std::process::Output objects
fn
execute_cmd
(
prog
:
&
str
,
args
:
Vec
<&
str
>
)
->
std
::
process
::
Output
{
let
output
=
Command
::
new
(
prog
)
.args
(
&
args
)
.output
();
let
res
=
match
output
{
Err
(
e
)
=>
{
eprintln!
(
"{}: {} log terminated with an error {}"
,
"error"
.red
(),
prog
,
e
);
exit
(
1
);
}
Ok
(
r
)
=>
r
,
};
res
}
/// Function used to import a tar archive in the remote folder of the current
/// filsesystem
...
...
@@ -148,7 +176,7 @@ pub(crate) fn get_git_commits() -> Vec<String> {
let
res
=
match
output
{
Err
(
e
)
=>
{
eprintln!
(
"{}:
borg list
terminated with an error {}"
,
"{}:
git log
terminated with an error {}"
,
"error"
.red
(),
e
);
...
...
@@ -347,6 +375,37 @@ pub(crate) fn pull_all_archives(remote: &str) {
}
}
/// Function that determines if an archive is a tag or a branch
///
/// # Argument
/// - `commit`: A commit SHA1 or a branch or tag name
///
/// # Return The SHA1 of the corresponding commit
pub
(
crate
)
fn
get_sha1_commit
(
commit
:
&
str
)
->
String
{
let
args
:
Vec
<&
str
>
=
vec!
[
"for-each-ref"
,
"--format='%(refname:short)~~%(objectname)'"
,
"refs/heads/"
];
let
output
=
execute_cmd
(
"git"
,
args
);
let
mut
branches_str
=
String
::
from_utf8
(
output
.stdout
)
.unwrap
()
.replace
(
"'"
,
""
)
.split_whitespace
()
.map
(|
c
|
{
c
.to_owned
()
})
.collect
::
<
Vec
<
String
>>
();
let
args
:
Vec
<&
str
>
=
vec!
[
"for-each-ref"
,
"--format='%(refname:short)~~%(objectname)'"
,
"refs/tags/"
];
let
output
=
execute_cmd
(
"git"
,
args
);
let
tag_str
=
String
::
from_utf8
(
output
.stdout
)
.unwrap
()
.replace
(
"'"
,
""
)
.split_whitespace
()
.map
(|
c
|
{
c
.to_owned
()
})
.collect
::
<
Vec
<
String
>>
();
branches_str
.extend
(
tag_str
);
let
mut
my_dic
:
HashMap
<
String
,
String
>
=
HashMap
::
new
();
for
br
in
branches_str
{
let
tmp
:
Vec
<&
str
>
=
br
.split
(
"~~"
)
.collect
();
if
tmp
.len
()
!=
2
{
eprintln!
(
"{}: Cannot recover git branch and SHA1 commit"
,
"error"
.red
());
exit
(
1
)
}
let
(
k
,
v
)
=
(
tmp
.get
(
0
)
.unwrap
()
.to_owned
()
.to_owned
(),
tmp
.get
(
1
)
.unwrap
()
.to_owned
()
.to_owned
());
my_dic
.insert
(
k
,
v
);
}
match
my_dic
.get
(
commit
)
{
Some
(
sha1
)
=>
sha1
,
None
=>
commit
}
.to_owned
()
}
/// Create a push the tar achive on the selected remote path
/// # Arguments
/// - `remote`: The name of a remote
...
...
@@ -362,7 +421,8 @@ pub fn pull(remote: &str, archive: &Option<String>, all: bool) -> () {
}
Some
(
arc
)
=>
{
let
git_commits
=
get_git_commits
();
pull_archive_when_needed
(
remote
,
arc
,
&
git_commits
);
let
arc
=
get_sha1_commit
(
&
arc
);
pull_archive_when_needed
(
remote
,
&
arc
,
&
git_commits
);
},
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/push.rs
+
3
−
1
View file @
44cbdb91
...
...
@@ -4,6 +4,7 @@
use
crate
::
commit
;
use
crate
::
mount
;
use
crate
::
pull
;
use
crate
::
remote
;
use
colored
::
Colorize
;
use
std
::
fs
;
...
...
@@ -434,7 +435,8 @@ pub fn push(remote: &str, archive: &str, compression: &str) -> () {
let
borg_folder
=
borg_folder
.canonicalize
()
.unwrap
();
let
(
adress
,
url
)
=
get_adress_and_url
(
remote
);
check_dest_and_copy
(
&
borg_folder
,
&
url
,
&
adress
);
let
remote_file
=
get_remote_file
(
&
url
,
archive
,
compression
);
let
archive
=
pull
::
get_sha1_commit
(
archive
);
let
remote_file
=
get_remote_file
(
&
url
,
&
archive
,
compression
);
let
remote_file
=
handle_existing_remote_file
(
&
remote_file
,
&
adress
,
"push"
);
export_tar
(
&
borg_folder
,
&
remote_file
,
&
adress
,
&
archive
);
}
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