資源簡介
linux下的git2.0.0
Git在Wikipedia上的定義:它是一個免費的、分布式的版本控制工具,或是一個強調了速度快的源代碼管理工具。Git最初被Linus Torvalds開發出來用于管理Linux內核的開發。每一個Git的工作目錄都是一個完全獨立的代碼庫,并擁有完整的歷史記錄和版本追蹤能力,不依賴 于網絡和中心服務器。
代碼片段和文件信息
#include?“cache.h“
/*
?*?Do?not?use?this?for?inspecting?*tracked*?content.??When?path?is?a
?*?symlink?to?a?directory?we?do?not?want?to?say?it?is?a?directory?when
?*?dealing?with?tracked?content?in?the?working?tree.
?*/
int?is_directory(const?char?*path)
{
struct?stat?st;
return?(!stat(path?&st)?&&?S_ISDIR(st.st_mode));
}
/*?We?allow?“recursive“?symbolic?links.?Only?within?reason?though.?*/
#define?MAXDEPTH?5
/*
?*?Return?the?real?path?(i.e.?absolute?path?with?symlinks?resolved
?*?and?extra?slashes?removed)?equivalent?to?the?specified?path.??(If
?*?you?want?an?absolute?path?but?don‘t?mind?links?use
?*?absolute_path().)??The?return?value?is?a?pointer?to?a?static
?*?buffer.
?*
?*?The?input?and?all?intermediate?paths?must?be?shorter?than?MAX_PATH.
?*?The?directory?part?of?path?(i.e.?everything?up?to?the?last
?*?dir_sep)?must?denote?a?valid?existing?directory?but?the?last
?*?component?need?not?exist.??If?die_on_error?is?set?then?die?with?an
?*?informative?error?message?if?there?is?a?problem.??Otherwise?return
?*?NULL?on?errors?(without?generating?any?output).
?*
?*?If?path?is?our?buffer?then?return?path?as?it‘s?already?what?the
?*?user?wants.
?*/
static?const?char?*real_path_internal(const?char?*path?int?die_on_error)
{
static?char?bufs[2][PATH_MAX?+?1]?*buf?=?bufs[0]?*next_buf?=?bufs[1];
char?*retval?=?NULL;
/*
?*?If?we?have?to?temporarily?chdir()?store?the?original?CWD
?*?here?so?that?we?can?chdir()?back?to?it?at?the?end?of?the
?*?function:
?*/
char?cwd[1024]?=?““;
int?buf_index?=?1;
int?depth?=?MAXDEPTH;
char?*last_elem?=?NULL;
struct?stat?st;
/*?We‘ve?already?done?it?*/
if?(path?==?buf?||?path?==?next_buf)
return?path;
if?(!*path)?{
if?(die_on_error)
die(“The?empty?string?is?not?a?valid?path“);
else
goto?error_out;
}
if?(strlcpy(buf?path?PATH_MAX)?>=?PATH_MAX)?{
if?(die_on_error)
die(“Too?long?path:?%.*s“?60?path);
else
goto?error_out;
}
while?(depth--)?{
if?(!is_directory(buf))?{
char?*last_slash?=?find_last_dir_sep(buf);
if?(last_slash)?{
last_elem?=?xstrdup(last_slash?+?1);
last_slash[1]?=?‘\0‘;
}?else?{
last_elem?=?xstrdup(buf);
*buf?=?‘\0‘;
}
}
if?(*buf)?{
if?(!*cwd?&&?!getcwd(cwd?sizeof(cwd)))?{
if?(die_on_error)
die_errno(“Could?not?get?current?working?directory“);
else
goto?error_out;
}
if?(chdir(buf))?{
if?(die_on_error)
die_errno(“Could?not?switch?to?‘%s‘“?buf);
else
goto?error_out;
}
}
if?(!getcwd(buf?PATH_MAX))?{
if?(die_on_error)
die_errno(“Could?not?get?current?working?directory“);
else
goto?error_out;
}
if?(last_elem)?{
size_t?len?=?strlen(buf);
if?(len?+?strlen(last_elem)?+?2?>?PATH_MAX)?{
if?(die_on_error)
die(“Too?long?path?name:?‘%s/%s‘“
????buf?last_elem);
else
goto?error_out;
}
if?(len?&&?!is_dir_sep(buf[len?-?1]))
buf[len++]?=?‘/‘;
strcpy(buf?+?len?last_elem);
free(last_elem);
last_elem?=?NULL;
- 上一篇:華為 GTM900才模塊資料大全
- 下一篇:測地距離—來自science雜志
評論
共有 條評論