Skip to content

Commit f34f0ab

Browse files
committed
add refspec stubs
1 parent 6953b00 commit f34f0ab

File tree

6 files changed

+453
-6
lines changed

6 files changed

+453
-6
lines changed

config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support,
77
if test $PHP_GIT2 != "no"; then
88
PHP_SUBST(GIT2_SHARED_LIBADD)
99

10-
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c, $ext_shared)
10+
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c refspec.c, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

ng.php

+143-5
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,15 @@ public function put($message/* $args */)
343343
}
344344
class Fashion
345345
{
346+
protected $name;
347+
protected $flag;
348+
349+
public function __construct($name, $flag = false)
350+
{
351+
$this->name = basename($name, ".h");
352+
$this->flag = $flag;
353+
}
354+
346355
public function shouldResource(Arg $arg)
347356
{
348357
static $types;
@@ -396,6 +405,7 @@ public function shouldResource(Arg $arg)
396405
"git_packbuilder",
397406
"git_submodule",
398407
"git_push",
408+
"git_refspec",
399409
);
400410
}
401411

@@ -1058,12 +1068,22 @@ public function generateStrarrayConversion(Printer $printer, Func $f)
10581068
}
10591069
}
10601070

1071+
public function generateIncludes(Printer $printer, Func $f)
1072+
{
1073+
if ($this->flag) {
1074+
$printer->put("#include \"php_git2.h\"\n");
1075+
$printer->put("#include \"php_git2_priv.h\"\n");
1076+
$printer->put("#include \"`name`.h\"\n", "name", $this->name);
1077+
}
1078+
}
1079+
10611080
public function out(Func $f)
10621081
{
10631082
$stream = new StringStream();
10641083
$out = new ZeroCopyOutputStream($stream);
10651084
$printer = new Printer($out, "`");
10661085

1086+
$this->generateIncludes($printer, $f);
10671087
$this->generateProto($printer, $f);
10681088
$printer->put("PHP_FUNCTION(`function`)\n",
10691089
"function", $f->getName());
@@ -1089,6 +1109,108 @@ public function out(Func $f)
10891109
}
10901110
}
10911111

1112+
class Header extends Fashion
1113+
{
1114+
public function generateLicense(Printer $printer, Func $f)
1115+
{
1116+
if (!$this->flag) {
1117+
return;
1118+
}
1119+
$printer->put("/*\n");
1120+
$printer->put(" * PHP Libgit2 Extension\n");
1121+
$printer->put(" *\n");
1122+
$printer->put(" * https://github.com/libgit2/php-git\n");
1123+
$printer->put(" *\n");
1124+
$printer->put(" * Copyright 2014 Shuhei Tanuma. All rights reserved.\n");
1125+
$printer->put(" *\n");
1126+
$printer->put(" * Permission is hereby granted, free of charge, to any person obtaining a copy\n");
1127+
$printer->put(" * of this software and associated documentation files (the \"Software\"), to deal\n");
1128+
$printer->put(" * in the Software without restriction, including without limitation the rights\n");
1129+
$printer->put(" * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n");
1130+
$printer->put(" * copies of the Software, and to permit persons to whom the Software is\n");
1131+
$printer->put(" * furnished to do so, subject to the following conditions:\n");
1132+
$printer->put(" *\n");
1133+
$printer->put(" * The above copyright notice and this permission notice shall be included in\n");
1134+
$printer->put(" * all copies or substantial portions of the Software.\n");
1135+
$printer->put(" *\n");
1136+
$printer->put(" * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n");
1137+
$printer->put(" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n");
1138+
$printer->put(" * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n");
1139+
$printer->put(" * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n");
1140+
$printer->put(" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n");
1141+
$printer->put(" * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n");
1142+
$printer->put(" * THE SOFTWARE.\n");
1143+
$printer->put(" */\n");
1144+
$printer->put("#ifndef PHP_GIT2_`file`_H\n", "file", strtoupper($this->name));
1145+
$printer->put("#define PHP_GIT2_`file`_H\n", "file", strtoupper($this->name));
1146+
$printer->put("\n");
1147+
}
1148+
1149+
public function generateArgInfo(Printer $printer, Func $f)
1150+
{
1151+
$printer->put("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`)\n",
1152+
"name", $f->getName(),
1153+
"a", 0,
1154+
"b", 0,
1155+
"c", count($f->getArguments())
1156+
);
1157+
foreach ($f->getArguments() as $arg) {
1158+
/** @var Arg $arg */
1159+
$printer->put("\tZEND_ARG_INFO(`is_ref`, `name`)\n",
1160+
"is_ref", 0,
1161+
"name", $arg->getName());
1162+
}
1163+
$printer->put("ZEND_END_ARG_INFO()\n");
1164+
$printer->put("\n");
1165+
}
1166+
1167+
public function out(Func $f)
1168+
{
1169+
$stream = new StringStream();
1170+
$out = new ZeroCopyOutputStream($stream);
1171+
$printer = new Printer($out, "`");
1172+
1173+
$this->generateLicense($printer, $f);
1174+
$this->generateArgInfo($printer, $f);
1175+
1176+
return $stream->__toString();
1177+
}
1178+
}
1179+
1180+
class Header2 extends Header
1181+
{
1182+
public function generateArgInfo(Printer $printer, Func $f)
1183+
{
1184+
$printer->put("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`)\n",
1185+
"name", $f->getName(),
1186+
"a", 0,
1187+
"b", 0,
1188+
"c", count($f->getArguments())
1189+
);
1190+
foreach ($f->getArguments() as $arg) {
1191+
/** @var Arg $arg */
1192+
$printer->put("\tZEND_ARG_INFO(`is_ref`, `name`)\n",
1193+
"is_ref", 0,
1194+
"name", $arg->getName());
1195+
}
1196+
$printer->put("ZEND_END_ARG_INFO()\n");
1197+
$printer->put("\n");
1198+
}
1199+
1200+
public function out(Func $f)
1201+
{
1202+
$stream = new StringStream();
1203+
$out = new ZeroCopyOutputStream($stream);
1204+
$printer = new Printer($out, "`");
1205+
1206+
$this->generateProto($printer, $f);
1207+
$printer->put("PHP_FUNCTION(`func`);\n", "func", $f->getName());
1208+
$printer->put("\n");
1209+
1210+
return $stream->__toString();
1211+
}
1212+
}
1213+
10921214
$data = file_get_contents($_SERVER['argv'][1]);
10931215
$table = array();
10941216
if (preg_match_all("/GIT_EXTERN\((.+?)\)\s*([a-zA-Z0-9_-]+)\((.+?)\);/s", $data, $match)) {
@@ -1108,14 +1230,30 @@ public function out(Func $f)
11081230
$table[$func->getName()] = $func;
11091231
}
11101232
}
1233+
if (getenv("PRINT_HEADER")) {
1234+
$flag = true;
1235+
foreach ($table as $name => $func) {
1236+
$printer = new Header($_SERVER['argv'][1], $flag);
1237+
echo $printer->out($func);
1238+
$flag = false;
1239+
}
11111240

1112-
if (isset($_SERVER['argv'][2])) {
1113-
$printer = new Fashion();
1114-
echo $printer->out($table[$_SERVER['argv'][2]]);
1115-
} else {
11161241
foreach ($table as $name => $func) {
1117-
$printer = new Fashion();
1242+
$printer = new Header2($_SERVER['argv'][1], $flag);
11181243
echo $printer->out($func);
11191244
}
1245+
echo "#endif\n";
1246+
} else {
1247+
if (isset($_SERVER['argv'][2])) {
1248+
$printer = new Fashion($_SERVER['argv'][1]);
1249+
echo $printer->out($table[$_SERVER['argv'][2]]);
1250+
} else {
1251+
$flag = true;
1252+
foreach ($table as $name => $func) {
1253+
$printer = new Fashion($_SERVER['argv'][1], $flag);
1254+
echo $printer->out($func);
1255+
$flag = false;
1256+
}
1257+
}
11201258
}
11211259

php_git2.c

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "attr.h"
6565
#include "giterr.h"
6666
#include "push.h"
67+
#include "refspec.h"
6768

6869
int git2_resource_handle;
6970

@@ -917,6 +918,16 @@ static zend_function_entry php_git2_functions[] = {
917918
PHP_FE(git_push_status_foreach, arginfo_git_push_status_foreach)
918919
PHP_FE(git_push_free, arginfo_git_push_free)
919920

921+
/* refspec */
922+
PHP_FE(git_refspec_src, arginfo_git_refspec_src)
923+
PHP_FE(git_refspec_dst, arginfo_git_refspec_dst)
924+
PHP_FE(git_refspec_string, arginfo_git_refspec_string)
925+
PHP_FE(git_refspec_force, arginfo_git_refspec_force)
926+
PHP_FE(git_refspec_direction, arginfo_git_refspec_direction)
927+
PHP_FE(git_refspec_src_matches, arginfo_git_refspec_src_matches)
928+
PHP_FE(git_refspec_dst_matches, arginfo_git_refspec_dst_matches)
929+
PHP_FE(git_refspec_transform, arginfo_git_refspec_transform)
930+
PHP_FE(git_refspec_rtransform, arginfo_git_refspec_rtransform)
920931

921932
/* misc */
922933
PHP_FE(git_resource_type, arginfo_git_resource_type)

php_git2.h

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ enum php_git2_resource_type {
124124
PHP_GIT2_TYPE_PACKBUILDER,
125125
PHP_GIT2_TYPE_SUBMODULE,
126126
PHP_GIT2_TYPE_PUSH,
127+
PHP_GIT2_TYPE_REFSPEC,
127128
};
128129

129130
typedef struct php_git2_t {
@@ -175,6 +176,7 @@ typedef struct php_git2_t {
175176
git_packbuilder *packbuilder;
176177
git_submodule *submodule;
177178
git_push *push;
179+
git_refspec *refspec;
178180
} v;
179181
int should_free_v;
180182
int resource_id;

0 commit comments

Comments
 (0)