Skip to content

Commit

Permalink
Bunch of changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
it3xl committed Jan 2, 2018
1 parent 29f2e24 commit f9b8821
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 54 deletions.
246 changes: 207 additions & 39 deletions changed_refs.awk
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Tests
## Restore

BEGIN {
prefRemote = "refs/remotes/";
prefLocal = "refs/heads/";
local_refs_prefix = "refs/remotes/";
remote_refs_prefix = "refs/heads/";

remote_1 = origin_1;
remote_2 = origin_2;
local_1 = prefix_1;
local_2 = prefix_2;

tty_attached = "/dev/tty";

Expand All @@ -9,24 +17,40 @@ BEGIN {
BEGINFILE {
file_states();
}
$2 {
common_key();
{
if($2){
common_key();

refs[$3][dest]["sha"] = $1;
refs[$3][dest]["ref"] = $2;
refs[$3][dest]["sha"] = $1;
refs[$3][dest]["ref"] = $2;
}
}
END {
dest = "";
origin = "";

# Action array variables.
split("", a_ff1); split("", a_ff2);
split("", a_del1); split("", a_del2);
split("", a_restore);
split("", a_f1); split("", a_f2);
split("", a_solv);
# Operation array variables.
split("", op_push_ff1); split("", op_push_ff2);
split("", op_push1); split("", op_push2);
split("", op_fetch1); split("", op_fetch2);
split("", op_del_local);
split("", op_solv_push1); split("", op_solv_push2);
split("", op_solv_fetch1); split("", op_solv_fetch2);
# Output variables.
out_push1; out_push2;
out_fetch1; out_fetch2;
out_del;
out_solv_push1; out_solv_push2;
out_solv_fetch1; out_solv_fetch2;
}
END {
#ff1;
#ff2;
#del1;
#del2;
#fetch1;
#fetch2;
#solv; - the owner repo can lose a ref. Behaves as a restoring.
generate_missing_refs();

deletion_allowed = 0;
unlock_deletion( \
Expand All @@ -35,7 +59,8 @@ END {
refs[must_exist_branch][local_1]["sha"], \
refs[must_exist_branch][local_2]["sha"] \
);
tty_dbg("deletion allowed = " deletion_allowed " by " must_exist_branch);
tty_dbg("deletion allowance = " deletion_allowed " by " must_exist_branch);

for(currentRef in refs){
assign_action( \
currentRef, \
Expand All @@ -45,61 +70,181 @@ END {
refs[currentRef][local_2]["sha"] \
);
}
actions_to_operations();
output_operations();
}

function assign_action(cr, rr1, rr2, lr1, lr2, lr, rr){
if(rr1 == rr2 && lr1 == lr2 && lr1 == rr2){
# Nothing to change.
return;
}
if(!(rr1 rr2)){
tty_dbg("solv, no remote refs: " cr);
solv[cr];
tty_dbg("a_restore, no remote refs: " cr);
a_restore[cr];
return;
}
if(rr1 == rr2){
rr = rr1;

if(lr1 != rr){
tty_dbg("a_f1, net fail: " cr);
a_f1[cr];
}
if(lr2 != rr){
tty_dbg("a_f2, net fail: " cr);
a_f2[cr];
}
return;
}

if(!(lr1 lr2)){
tty_dbg("solv, no local: " cr);
solve[cr];
tty_dbg("a_solv, no local: " cr);
a_solv[cr];
return;
}

if(lr1 == lr2){
lr = lr1;

if(rr2 == lr && !rr1){
tty_dbg("del2: " cr);
del2[cr];
if(!rr1 && rr2 == lr){
tty_dbg("a_del2: " cr);
a_del2[cr];
return;
}
if(rr1 == lr && !rr2){
tty_dbg("del1: " cr);
del1[cr];
if(!rr2 && rr1 == lr){
tty_dbg("a_del1: " cr);
a_del1[cr];
return;
}

if(rr1 == lr && rr2 != lr){
tty_dbg("ff1: " cr);
ff1[cr];
tty_dbg("a_ff1: " cr);
a_ff1[cr];
return;
}
if(rr2 == lr && rr1 != lr){
tty_dbg("ff2: " cr);
ff2[cr];
tty_dbg("a_ff2: " cr);
a_ff2[cr];
return;
}
}
if(rr1 == rr2){
rr = rr1;

a_solv[cr];
}
function actions_to_operations( ref, sha1, sha2){

if(lr1 != rr){
tty_dbg("fetch1, net fail: " cr);
fetch1[cr];
for(ref in a_ff1){
op_push_ff1[ref];
op_fetch1[ref];
op_fetch2[ref];
}
for(ref in a_ff2){
op_push_ff2[ref];
op_fetch1[ref];
op_fetch2[ref];
}
if(deletion_allowed){
for(ref in a_del1){
op_push1[ref];
op_del_local[ref];
}
if(lr2 != rr){
tty_dbg("fetch2, net fail: " cr);
fetch2[cr];
for(ref in a_del2){
op_push2[ref];
op_del_local[ref];
}
return;
}
solv[cr];
for(ref in a_restore){
if(refs[ref][local_1]["sha"]){
op_push1[ref];
op_fetch1[ref];
}
if(refs[ref][local_2]["sha"]){
op_push2[ref];
op_fetch2[ref];
}
}
for(ref in a_f1){
op_fetch1[ref];
}
for(ref in a_f2){
op_fetch2[ref];
}
for(ref in a_solv){
if(!index(refs[ref][local_1]["ref"], local_1)){
op_solv_push1[ref];
}
if(!index(refs[ref][local_2]["ref"], local_2)){
op_solv_push2[ref];
}
op_solv_fetch1[ref];
op_solv_fetch2[ref];
}
}
function output_operations(){
print "{[Result lines: push 1; push 2; fetch 1; fetch 2; del; push solv 1; push solv 2; fetch solv 1; fetch solv 2;]}"

{
for(ref in op_push_ff1){
out_push1 = out_push1 " '" refs[ref][local_1]["ref"] "':'" refs[ref][remote_1]["ref"] "'";
}
for(ref in op_push_ff2){
out_push2 = out_push2 " '" refs[ref][local_2]["ref"] "':'" refs[ref][remote_2]["ref"] "'";
}

for(ref in op_push1){
out_push1 = out_push1 " +'" refs[ref][local_1]["ref"] "':'" refs[ref][remote_1]["ref"] "'";
}
for(ref in op_push2){
out_push2 = out_push2 " +'" refs[ref][local_2]["ref"] "':'" refs[ref][remote_2]["ref"] "'";
}
}
print out_push1;
print out_push2;

for(ref in op_fetch1){
out_fetch1 = out_fetch1 " +'" refs[ref][remote_1]["ref"] "':'" refs[ref][local_1]["ref"];
}
print out_fetch1;
for(ref in op_fetch2){
out_fetch2 = out_fetch2 " +'" refs[ref][remote_2]["ref"] "':'" refs[ref][local_2]["ref"];
}
print out_fetch2;


for(ref in op_del_local){
if(refs[ref][local_1]["sha"]){
out_del = out_del " '" origin_1 "/" ref "'";
}
if(refs[ref][local_2]["sha"]){
out_del = out_del " '" origin_2 "/" ref "'";
}
}
print out_del;

{
for(ref in op_solv_push1){
out_push_solv1 = out_push_solv1 " +'" refs[ref][local_1]["ref"] "':'" refs[ref][remote_1]["ref"] "'";
}
print out_push_solv1;
for(ref in op_solv_push2){
out_push_solv2 = out_push_solv2 " +'" refs[ref][local_2]["ref"] "':'" refs[ref][remote_2]["ref"] "'";
}
print out_push_solv2;

for(ref in op_solv_fetch1){
out_fetch_solv1 = out_fetch_solv1 " +'" refs[ref][remote_1]["ref"] "':'" refs[ref][local_1]["ref"] "'";
}
print out_fetch_solv1;
for(ref in op_solv_fetch2){
out_fetch_solv2 = out_fetch_solv2 " +'" refs[ref][remote_2]["ref"] "':'" refs[ref][local_2]["ref"] "'";
}
print out_fetch_solv2;
}

print "{[End results]}";
}

function unlock_deletion(rr1, rr2, lr1, lr2){
if(!rr1)
return;
Expand All @@ -114,6 +259,7 @@ function unlock_deletion(rr1, rr2, lr1, lr2){

deletion_allowed = 1;
}

function file_states() {
switch (++file_num) {
case 1:
Expand All @@ -135,7 +281,7 @@ function file_states() {
function common_key() {
# Generates a common key for all 4 locations of every ref.
$3 = $2
split($3, split_refs, prefRemote origin "/");
split($3, split_refs, local_refs_prefix origin "/");
if(split_refs[2]){
# Removes "refs/remotes/current_origin/"
$3 = split_refs[2];
Expand All @@ -144,7 +290,29 @@ function common_key() {
sub("refs/[^/]*/", "", $3);
}
}
function generate_missing_refs(){
for(ref in refs){
tty_dbg("zzzz");
tty_dbg(ref);
for(x in refs[ref]){
tty_dbg(x " : " refs[ref][x]["ref"]);
}

if(!refs[ref][remote_1]["ref"])
refs[ref][remote_1]["ref"] = remote_refs_prefix ref
if(!refs[ref][remote_2]["ref"])
refs[ref][remote_2]["ref"] = remote_refs_prefix ref
if(!refs[ref][local_1]["ref"])
refs[ref][local_1]["ref"] = local_refs_prefix origin_1 "/" ref
if(!refs[ref][local_2]["ref"])
refs[ref][local_2]["ref"] = local_refs_prefix origin_2 "/" ref

tty_dbg();
for(x in refs[ref]){
tty_dbg(x " : " refs[ref][x]["ref"]);
}
}
}

function tty(msg){
print msg >> tty_attached;
Expand Down
Empty file removed conflict_solving_convention.sh
Empty file.
10 changes: 5 additions & 5 deletions git-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ local_refs_2=$(git for-each-ref --format="%(objectname) %(refname)" "refs/remote

changed_refs=$(awk \
-f "$path_git_sync/changed_refs.awk" \
`#echo --lint` \
`# --lint` \
--assign must_exist_branch=$must_exist_branch \
--assign remote_1="$origin_1" \
--assign remote_2="$origin_2" \
--assign local_1="$prefix_1" \
--assign local_2="$prefix_2" \
--assign origin_1="$origin_1" \
--assign origin_2="$origin_2" \
--assign prefix_1="$prefix_1" \
--assign prefix_2="$prefix_2" \
--assign debug_on=1 \
<(echo "$remote_refs_1") \
<(echo "$remote_refs_2") \
Expand Down
2 changes: 1 addition & 1 deletion repo_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git init


git config --local advice.pushUpdateRejected false

#git config --local core.logAllRefUpdates


echo Repo created at $repo_path
Expand Down
2 changes: 1 addition & 1 deletion repo_settings/sample_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project_folder=sample_repo


# A conventional prefix for refs for repo 1.
prefix_1=client_co/
prefix_1=clie/nt_co/
#url_1=https://your-repo1-url.org/git/my_repo.git
url_1="$path_git_sync/sample_repos/remote_$prefix_1"

Expand Down
7 changes: 2 additions & 5 deletions sample_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
echo Start `basename "$BASH_SOURCE"`

url_local="$path_git_sync/sample_repos"
url_local_1="$url_local/local_$prefix_1"
url_local_2="$url_local/local_$prefix_2"
url_local_1="$url_local/local_$prefix_1_safe"
url_local_2="$url_local/local_$prefix_2_safe"

first_branch=$must_exist_branch
second_branch=${prefix_2}develop

export must_exist_branch=$first_branch


if [[ ! -f "$url_1/config" ]]; then
echo
echo '@ Creation of sample repos. 2 remote & 2 local'
Expand Down
Loading

0 comments on commit f9b8821

Please sign in to comment.