Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
8f905eb1
G
git
项目概览
李少辉-开发者
/
git
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8f905eb1
编写于
1月 06, 2007
作者:
J
Junio C Hamano
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'jc/remote'
* jc/remote: git-remote
上级
bc8c0294
e194cd1e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
278 addition
and
1 deletion
+278
-1
Makefile
Makefile
+1
-1
git-remote.perl
git-remote.perl
+277
-0
未找到文件。
Makefile
浏览文件 @
8f905eb1
...
...
@@ -179,7 +179,7 @@ SCRIPT_SH = \
SCRIPT_PERL
=
\
git-add--interactive.perl
\
git-archimport.perl git-cvsimport.perl git-relink.perl
\
git-cvsserver.perl
\
git-cvsserver.perl
git-remote.perl
\
git-svnimport.perl git-cvsexportcommit.perl
\
git-send-email.perl git-svn.perl
...
...
git-remote.perl
0 → 100755
浏览文件 @
8f905eb1
#!/usr/bin/perl -w
use
Git
;
my
$git
=
Git
->
repository
();
sub
add_remote_config
{
my
(
$hash
,
$name
,
$what
,
$value
)
=
@_
;
if
(
$what
eq
'
url
')
{
if
(
exists
$hash
->
{
$name
}{'
URL
'})
{
print
STDERR
"
Warning: more than one remote.
$name
.url
\n
";
}
$hash
->
{
$name
}{'
URL
'}
=
$value
;
}
elsif
(
$what
eq
'
fetch
')
{
$hash
->
{
$name
}{'
FETCH
'}
||=
[]
;
push
@
{
$hash
->
{
$name
}{'
FETCH
'}},
$value
;
}
if
(
!
exists
$hash
->
{
$name
}{'
SOURCE
'})
{
$hash
->
{
$name
}{'
SOURCE
'}
=
'
config
';
}
}
sub
add_remote_remotes
{
my
(
$hash
,
$file
,
$name
)
=
@_
;
if
(
exists
$hash
->
{
$name
})
{
$hash
->
{
$name
}{'
WARNING
'}
=
'
ignored due to config
';
return
;
}
my
$fh
;
if
(
!
open
(
$fh
,
'
<
',
$file
))
{
print
STDERR
"
Warning: cannot open
$file
\n
";
return
;
}
my
$it
=
{
'
SOURCE
'
=>
'
remotes
'
};
$hash
->
{
$name
}
=
$it
;
while
(
<
$fh
>
)
{
chomp
;
if
(
/^URL:\s*(.*)$/
)
{
# Having more than one is Ok -- it is used for push.
if
(
!
exists
$it
->
{'
URL
'})
{
$it
->
{'
URL
'}
=
$
1
;
}
}
elsif
(
/^Push:\s*(.*)$/
)
{
;
# later
}
elsif
(
/^Pull:\s*(.*)$/
)
{
$it
->
{'
FETCH
'}
||=
[]
;
push
@
{
$it
->
{'
FETCH
'}},
$
1
;
}
elsif
(
/^\#/
)
{
;
# ignore
}
else
{
print
STDERR
"
Warning: funny line in
$file
:
$_
\n
";
}
}
close
(
$fh
);
}
sub
list_remote
{
my
(
$git
)
=
@_
;
my
%seen
=
();
my
@remotes
=
eval
{
$git
->
command
(
qw(repo-config --get-regexp)
,
'
^remote\.
');
};
for
(
@remotes
)
{
if
(
/^remote\.([^.]*)\.(\S*)\s+(.*)$/
)
{
add_remote_config
(
\
%seen
,
$
1
,
$
2
,
$
3
);
}
}
my
$dir
=
$git
->
repo_path
()
.
"
/remotes
";
if
(
opendir
(
my
$dh
,
$dir
))
{
local
$_
;
while
(
$_
=
readdir
(
$dh
))
{
chomp
;
next
if
(
!
-
f
"
$dir
/
$_
"
||
!
-
r
_
);
add_remote_remotes
(
\
%seen
,
"
$dir
/
$_
",
$_
);
}
}
return
\
%seen
;
}
sub
add_branch_config
{
my
(
$hash
,
$name
,
$what
,
$value
)
=
@_
;
if
(
$what
eq
'
remote
')
{
if
(
exists
$hash
->
{
$name
}{'
REMOTE
'})
{
print
STDERR
"
Warning: more than one branch.
$name
.remote
\n
";
}
$hash
->
{
$name
}{'
REMOTE
'}
=
$value
;
}
elsif
(
$what
eq
'
merge
')
{
$hash
->
{
$name
}{'
MERGE
'}
||=
[]
;
push
@
{
$hash
->
{
$name
}{'
MERGE
'}},
$value
;
}
}
sub
list_branch
{
my
(
$git
)
=
@_
;
my
%seen
=
();
my
@branches
=
eval
{
$git
->
command
(
qw(repo-config --get-regexp)
,
'
^branch\.
');
};
for
(
@branches
)
{
if
(
/^branch\.([^.]*)\.(\S*)\s+(.*)$/
)
{
add_branch_config
(
\
%seen
,
$
1
,
$
2
,
$
3
);
}
}
return
\
%seen
;
}
my
$remote
=
list_remote
(
$git
);
my
$branch
=
list_branch
(
$git
);
sub
update_ls_remote
{
my
(
$harder
,
$info
)
=
@_
;
return
if
((
$harder
==
0
)
||
((
$harder
==
1
)
&&
exists
$info
->
{'
LS_REMOTE
'}));
my
@ref
=
map
{
s|^[0-9a-f]{40}\s+refs/heads/||
;
$_
;
}
$git
->
command
(
qw(ls-remote --heads)
,
$info
->
{'
URL
'});
$info
->
{'
LS_REMOTE
'}
=
\
@ref
;
}
sub
show_wildcard_mapping
{
my
(
$forced
,
$ours
,
$ls
)
=
@_
;
my
%refs
;
for
(
@$ls
)
{
$refs
{
$_
}
=
01
;
# bit #0 to say "they have"
}
for
(
$git
->
command
('
for-each-ref
',
"
refs/remotes/
$ours
"))
{
chomp
;
next
unless
(
s|^[0-9a-f]{40}\s[a-z]+\srefs/remotes/$ours/||
);
next
if
(
$_
eq
'
HEAD
');
$refs
{
$_
}
||=
0
;
$refs
{
$_
}
|=
02
;
# bit #1 to say "we have"
}
my
(
@new
,
@stale
,
@tracked
);
for
(
sort
keys
%refs
)
{
my
$have
=
$refs
{
$_
};
if
(
$have
==
1
)
{
push
@new
,
$_
;
}
elsif
(
$have
==
2
)
{
push
@stale
,
$_
;
}
elsif
(
$have
==
3
)
{
push
@tracked
,
$_
;
}
}
if
(
@new
)
{
print
"
New remote branches (next fetch will store in remotes/
$ours
)
\n
";
print
"
@new
\n
";
}
if
(
@stale
)
{
print
"
Stale tracking branches in remotes/
$ours
(you'd better remove them)
\n
";
print
"
@stale
\n
";
}
if
(
@tracked
)
{
print
"
Tracked remote branches
\n
";
print
"
@tracked
\n
";
}
}
sub
show_mapping
{
my
(
$name
,
$info
)
=
@_
;
my
$fetch
=
$info
->
{'
FETCH
'};
my
$ls
=
$info
->
{'
LS_REMOTE
'};
my
(
@stale
,
@tracked
);
for
(
@$fetch
)
{
next
unless
(
/(\+)?([^:]+):(.*)/
);
my
(
$forced
,
$theirs
,
$ours
)
=
(
$
1
,
$
2
,
$
3
);
if
(
$theirs
eq
'
refs/heads/*
'
&&
$ours
=~
/^refs\/remotes\/(.*)\/\*$/
)
{
# wildcard mapping
show_wildcard_mapping
(
$forced
,
$
1
,
$ls
);
}
elsif
(
$theirs
=~
/\*/
||
$ours
=~
/\*/
)
{
print
STDERR
"
Warning: unrecognized mapping in remotes.
$name
.fetch:
$_
\n
";
}
elsif
(
$theirs
=~
s|^refs/heads/||
)
{
if
(
!
grep
{
$_
eq
$theirs
}
@$ls
)
{
push
@stale
,
$theirs
;
}
elsif
(
$ours
ne
'')
{
push
@tracked
,
$theirs
;
}
}
}
if
(
@stale
)
{
print
"
Stale tracking branches in remotes/
$name
(you'd better remove them)
\n
";
print
"
@stale
\n
";
}
if
(
@tracked
)
{
print
"
Tracked remote branches
\n
";
print
"
@tracked
\n
";
}
}
sub
show_remote
{
my
(
$name
,
$ls_remote
)
=
@_
;
if
(
!
exists
$remote
->
{
$name
})
{
print
STDERR
"
No such remote
$name
\n
";
return
;
}
my
$info
=
$remote
->
{
$name
};
update_ls_remote
(
$ls_remote
,
$info
);
print
"
* remote
$name
\n
";
print
"
URL:
$info
->{'URL'}
\n
";
for
my
$branchname
(
sort
keys
%$branch
)
{
next
if
(
$branch
->
{
$branchname
}{'
REMOTE
'}
ne
$name
);
my
@merged
=
map
{
s|^refs/heads/||
;
$_
;
}
split
('
',"
@{
$
branch
->{$
branchname}
{'MERGE'}}
");
next
unless
(
@merged
);
print
"
Remote branch(es) merged with 'git pull' while on branch
$branchname
\n
";
print
"
@merged
\n
";
}
if
(
$info
->
{'
LS_REMOTE
'})
{
show_mapping
(
$name
,
$info
);
}
}
sub
add_remote
{
my
(
$name
,
$url
)
=
@_
;
if
(
exists
$remote
->
{
$name
})
{
print
STDERR
"
remote
$name
already exists.
\n
";
exit
(
1
);
}
$git
->
command
('
repo-config
',
"
remote.
$name
.url
",
$url
);
$git
->
command
('
repo-config
',
"
remote.
$name
.fetch
",
"
+refs/heads/*:refs/remotes/
$name
/*
");
}
if
(
!
@ARGV
)
{
for
(
sort
keys
%$remote
)
{
print
"
$_
\n
";
}
}
elsif
(
$ARGV
[
0
]
eq
'
show
')
{
my
$ls_remote
=
1
;
my
$i
;
for
(
$i
=
1
;
$i
<
@ARGV
;
$i
++
)
{
if
(
$ARGV
[
$i
]
eq
'
-n
')
{
$ls_remote
=
0
;
}
else
{
last
;
}
}
if
(
$i
>=
@ARGV
)
{
print
STDERR
"
Usage: git remote show <remote>
\n
";
exit
(
1
);
}
for
(;
$i
<
@ARGV
;
$i
++
)
{
show_remote
(
$ARGV
[
$i
],
$ls_remote
);
}
}
elsif
(
$ARGV
[
0
]
eq
'
add
')
{
if
(
@ARGV
!=
3
)
{
print
STDERR
"
Usage: git remote add <name> <url>
\n
";
exit
(
1
);
}
add_remote
(
$ARGV
[
1
],
$ARGV
[
2
]);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录