From f2df934d2b8e62ae1b3b3f16679baa18abbf77af Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 1 Mar 2010 19:20:10 +0100 Subject: [PATCH] added other host:/path syntax to diff and revert --- TODO | 2 +- bak-git-server.pl | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 4a11319..b013427 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ + commit --author support ++ diff/revert from another host:/paths/ - bak ls - daily cron job to create branch with uncommited changes -- diff/merge with different host:/paths/ diff --git a/bak-git-server.pl b/bak-git-server.pl index ce4c099..1a074da 100755 --- a/bak-git-server.pl +++ b/bak-git-server.pl @@ -19,12 +19,12 @@ bak command overview: bak add /path bak commit [/path [message]] - bak diff [/path] + bak diff [host:][/path] bak status [/path] bak log [/path] bak ch[anges] - bak revert /path + bak revert [host:]/path bak - push all changed files to server @@ -99,6 +99,7 @@ while (my $client = $server->accept()) { warn "<<< $line\n"; my ($user,$hostname,$pwd,$command,$rel_path,$message) = split(/\s+/,$line,5); + my $on_host = $1 if $rel_path =~ s/^([^:]+):(.+)$/$2/ && -e $1; my $path = $rel_path =~ m{^/} ? $rel_path : "$pwd/$rel_path"; $message ||= ''; @@ -133,11 +134,23 @@ while (my $client = $server->accept()) { $command .= ' --stat' if $command eq 'log'; $command = 'log --patch-with-stat' if $command =~ m/^ch/; pull_changes $hostname if $command eq 'diff'; - # commands without path will show host-wide status/changes - print $client git($command, $rel_path ? $backup_path : $hostname); + if ( $on_host ) { + system 'rsync', '-avv', "root\@$on_host:$path", "$on_host/$path"; + open(my $diff, '-|', "diff -uw $hostname$path $on_host$path"); + while(<$diff>) { + print $client $_; + } + } else { + # commands without path will show host-wide status/changes + print $client git($command, $rel_path ? $backup_path : $hostname); + } } elsif ( $command eq 'revert' ) { - print $client git "checkout -- $hostname/$path"; - system 'rsync', '-avv', "$hostname/$path", "root\@$hostname:$path"; + if ( $on_host ) { + system 'rsync', '-avv', "$on_host/$path", "root\@$hostname:$path"; + } else { + print $client git "checkout -- $hostname/$path"; + system 'rsync', '-avv', "$hostname/$path", "root\@$hostname:$path"; + } } else { print $client "Unknown command: $command\n"; } -- 2.20.1