1 // gitdll.cpp : Defines the exported functions for the DLL application.
\r
10 // This is an example of an exported variable
\r
11 GITDLL_API int ngitdll=0;
\r
13 // This is an example of an exported function.
\r
14 GITDLL_API int fngitdll(void)
\r
19 // This is the constructor of a class that has been exported.
\r
20 // see gitdll.h for the class definition
\r
27 #define MAX_ERROR_STR_SIZE 512
\r
28 char g_last_error[MAX_ERROR_STR_SIZE]={0};
\r
30 char * get_git_last_error()
\r
32 return g_last_error;
\r
35 static void die_dll(const char *err, va_list params)
\r
37 memset(g_last_error,0,MAX_ERROR_STR_SIZE);
\r
38 vsnprintf(g_last_error, MAX_ERROR_STR_SIZE-1, err, params);
\r
43 set_die_routine(die_dll);
\r
46 int git_get_sha1(const char *name, GIT_HASH sha1)
\r
48 return get_sha1(name,sha1);
\r
51 static int convert_slash(char * path)
\r
64 char path[MAX_PATH+1];
\r
66 size_t homesize,size,httpsize;
\r
68 // set HOME if not set already
\r
69 getenv_s(&homesize, NULL, 0, "HOME");
\r
72 _dupenv_s(&home,&size,"USERPROFILE");
\r
73 _putenv_s("HOME",home);
\r
76 GetModuleFileName(NULL, path, MAX_PATH);
\r
77 convert_slash(path);
\r
79 git_extract_argv0_path(path);
\r
80 prefix = setup_git_directory();
\r
81 return git_config(git_default_config, NULL);
\r
84 static int git_parse_commit_author(struct GIT_COMMIT_AUTHOR *author, char *pbuff)
\r
89 end=strchr(pbuff,'<');
\r
94 author->NameSize = end - pbuff - 1;
\r
97 end = strchr(pbuff, '>');
\r
101 author->Email = pbuff ;
\r
102 author->EmailSize = end - pbuff;
\r
106 author->Date = atol(pbuff);
\r
107 end = strchr(pbuff, ' ');
\r
112 author->TimeZone = atol(pbuff);
\r
117 static int git_parse_commit(GIT_COMMIT *commit)
\r
124 p= (struct commit *)commit->m_pGitCommit;
\r
126 memcpy(commit->m_hash,p->object.sha1,GIT_HASH_SIZE);
\r
128 if(p->buffer == NULL)
\r
134 if( strncmp(pbuf,"author",6) == 0)
\r
136 ret = git_parse_commit_author(&commit->m_Author,pbuf + 7);
\r
140 if( strncmp(pbuf, "committer",9) == 0)
\r
142 ret = git_parse_commit_author(&commit->m_Committer,pbuf + 10);
\r
146 pbuf = strchr(pbuf,'\n');
\r
150 while((*pbuf) && (*pbuf == '\n'))
\r
153 commit->m_Subject=pbuf;
\r
154 end = strchr(pbuf,'\n');
\r
156 commit->m_SubjectSize = strlen(pbuf);
\r
159 commit->m_SubjectSize = end - pbuf;
\r
161 commit->m_Body = pbuf;
\r
162 commit->m_BodySize = strlen(pbuf);
\r
168 pbuf = strchr(pbuf,'\n');
\r
175 int git_get_commit_from_hash(GIT_COMMIT *commit, GIT_HASH hash)
\r
179 struct commit *p = (struct commit*)commit;
\r
180 commit->m_pGitCommit = p = lookup_commit(hash);
\r
188 ret = parse_commit(p);
\r
192 return git_parse_commit(commit);
\r