r3
| 1 | 나무위키 파서 개발하다 빡쳐서 쓴 내용들 |
|---|
| 2 | |
|---|
r1
| 3 | {{{#!syntax diff |
|---|
| 4 | diff --git a/builtin/commit.c b/builtin/commit.c |
|---|
| 5 | index 2f45968222..25e26a2f70 100644 |
|---|
| 6 | --- a/builtin/commit.c |
|---|
| 7 | +++ b/builtin/commit.c |
|---|
| 8 | @@ -125,7 +125,7 @@ static int all, also, interactive, patch_interactive, only, amend, signoff; |
|---|
| 9 | static int edit_flag = -1; /* unspecified */ |
|---|
| 10 | static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; |
|---|
| 11 | static int config_commit_verbose = -1; /* unspecified */ |
|---|
| 12 | -static int no_post_rewrite, allow_empty_message, pathspec_file_nul; |
|---|
| 13 | +static int no_post_rewrite, allow_empty_message = 1, pathspec_file_nul; |
|---|
| 14 | static const char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg; |
|---|
| 15 | static const char *sign_commit, *pathspec_from_file; |
|---|
| 16 | static struct strvec trailer_args = STRVEC_INIT; |
|---|
| 17 | }}} |
|---|
| 18 | |
|---|
r2
| 19 | 문제는 이대로 빌드하면 unit test가 실패하는 듯하다. |
|---|
| 20 | |
|---|
| 21 | {{{#!syntax sh |
|---|
| 22 | error: builder for '/nix/store/m9iqhqfxxqs7p6jdj2jcf9aq2ygfiv0a-git-2.47.2.drv' failed with exit code 2; |
|---|
| 23 | last 25 log lines: |
|---|
| 24 | > t3404-rebase-interactive.sh (Wstat: 256 (exited 1) Tests: 131 Failed: 3) |
|---|
| 25 | > Failed tests: 42-44 |
|---|
| 26 | > Non-zero exit status: 1 |
|---|
| 27 | > t7500-commit-template-squash-signoff.sh (Wstat: 256 (exited 1) Tests: 54 Failed: 5) |
|---|
| 28 | > Failed tests: 4, 8, 22, 24, 34 |
|---|
| 29 | > Non-zero exit status: 1 |
|---|
| 30 | > t7501-commit-basic-functionality.sh (Wstat: 256 (exited 1) Tests: 77 Failed: 4) |
|---|
| 31 | > Failed tests: 27, 29, 39, 47 |
|---|
| 32 | > Non-zero exit status: 1 |
|---|
| 33 | > t7507-commit-verbose.sh (Wstat: 256 (exited 1) Tests: 45 Failed: 23) |
|---|
| 34 | > Failed tests: 8-10, 13-14, 19-21, 23-24, 26-27, 29-30 |
|---|
| 35 | > 32-33, 35-36, 38-39, 41-42, 44 |
|---|
| 36 | > Non-zero exit status: 1 |
|---|
| 37 | > t7502-commit-porcelain.sh (Wstat: 256 (exited 1) Tests: 81 Failed: 1) |
|---|
| 38 | > Failed test: 39 |
|---|
| 39 | > Non-zero exit status: 1 |
|---|
| 40 | > t7508-status.sh (Wstat: 256 (exited 1) Tests: 125 Failed: 66) |
|---|
| 41 | > Failed tests: 13-19, 21-35, 37-41, 50-54, 58-66, 69, 71-93 |
|---|
| 42 | > 107 |
|---|
| 43 | > Non-zero exit status: 1 |
|---|
| 44 | > Files=1023, Tests=30126, 216 wallclock secs (10.62 usr 2.79 sys + 449.92 cusr 960.70 csys = 1424.03 CPU) |
|---|
| 45 | > Result: FAIL |
|---|
| 46 | > make[1]: *** [Makefile:73: prove] Error 1 |
|---|
| 47 | > make[1]: Leaving directory '/build/git-2.47.2/t' |
|---|
| 48 | > make: *** [Makefile:3273: test] Error 2 |
|---|
| 49 | For full logs, run 'nix log /nix/store/m9iqhqfxxqs7p6jdj2jcf9aq2ygfiv0a-git-2.47.2.drv'. |
|---|
| 50 | error: 1 dependencies of derivation '/nix/store/2i62rn1l27qy4gm30msn39i0ban9q5f1-git-2.47.2-fish-completions.drv' failed to build |
|---|
| 51 | error: 1 dependencies of derivation '/nix/store/hx9d5rydwzi4inqhbfi33azafafv7071-home-manager-path.drv' failed to build |
|---|
| 52 | error: 1 dependencies of derivation '/nix/store/whrrhjd3lwjv6kj6j7smd3xx1h3b1d3l-home-manager-generation.drv' failed to build}}} |
|---|
| 53 | |
|---|
r3
| 54 | 근데 make test를 돌리려고 하는데 perl shebang이 hardcode되어있다. |
|---|
| 55 | |
|---|
| 56 | {{{ |
|---|
| 57 | { |
|---|
| 58 | fetchurl, |
|---|
| 59 | fetchpatch, |
|---|
| 60 | lib, |
|---|
| 61 | stdenv, |
|---|
| 62 | buildPackages, |
|---|
| 63 | curl, |
|---|
| 64 | openssl, |
|---|
| 65 | zlib, |
|---|
| 66 | expat, |
|---|
| 67 | perlPackages, |
|---|
| 68 | python3, |
|---|
| 69 | gettext, |
|---|
| 70 | cpio, |
|---|
| 71 | gnugrep, |
|---|
| 72 | gnused, |
|---|
| 73 | gawk, |
|---|
| 74 | coreutils, # needed at runtime by git-filter-branch etc |
|---|
| 75 | openssh, |
|---|
| 76 | pcre2, |
|---|
| 77 | bash, |
|---|
| 78 | asciidoc, |
|---|
| 79 | texinfo, |
|---|
| 80 | xmlto, |
|---|
| 81 | docbook2x, |
|---|
| 82 | docbook_xsl, |
|---|
| 83 | docbook_xml_dtd_45, |
|---|
| 84 | libxslt, |
|---|
| 85 | tcl, |
|---|
| 86 | tk, |
|---|
| 87 | makeWrapper, |
|---|
| 88 | libiconv, |
|---|
| 89 | libiconvReal, |
|---|
| 90 | svnSupport ? false, |
|---|
| 91 | subversionClient, |
|---|
| 92 | perlLibs, |
|---|
| 93 | smtpPerlLibs, |
|---|
| 94 | perlSupport ? stdenv.buildPlatform == stdenv.hostPlatform, |
|---|
| 95 | nlsSupport ? true, |
|---|
| 96 | osxkeychainSupport ? stdenv.hostPlatform.isDarwin, |
|---|
| 97 | guiSupport ? false, |
|---|
| 98 | withManual ? true, |
|---|
| 99 | pythonSupport ? true, |
|---|
| 100 | withpcre2 ? true, |
|---|
| 101 | sendEmailSupport ? perlSupport, |
|---|
| 102 | Security, |
|---|
| 103 | CoreServices, |
|---|
| 104 | nixosTests, |
|---|
| 105 | withLibsecret ? false, |
|---|
| 106 | pkg-config, |
|---|
| 107 | glib, |
|---|
| 108 | libsecret, |
|---|
| 109 | gzip, # needed at runtime by gitweb.cgi |
|---|
| 110 | withSsh ? false, |
|---|
| 111 | sysctl, |
|---|
| 112 | deterministic-host-uname, # trick Makefile into targeting the host platform when cross-compiling |
|---|
| 113 | doInstallCheck ? !stdenv.hostPlatform.isDarwin, # extremely slow on darwin |
|---|
| 114 | tests, |
|---|
| 115 | }: |
|---|
| 116 | |
|---|
| 117 | assert osxkeychainSupport -> stdenv.hostPlatform.isDarwin; |
|---|
| 118 | assert sendEmailSupport -> perlSupport; |
|---|
| 119 | assert svnSupport -> perlSupport; |
|---|
| 120 | |
|---|
| 121 | let |
|---|
| 122 | version = "2.47.2"; |
|---|
| 123 | svn = subversionClient.override { perlBindings = perlSupport; }; |
|---|
| 124 | gitwebPerlLibs = with perlPackages; [ |
|---|
| 125 | CGI |
|---|
| 126 | HTMLParser |
|---|
| 127 | CGIFast |
|---|
| 128 | FCGI |
|---|
| 129 | FCGIProcManager |
|---|
| 130 | HTMLTagCloud |
|---|
| 131 | ]; |
|---|
| 132 | in |
|---|
| 133 | |
|---|
| 134 | stdenv.mkDerivation (finalAttrs: { |
|---|
| 135 | pname = |
|---|
| 136 | "git" |
|---|
| 137 | + lib.optionalString svnSupport "-with-svn" |
|---|
| 138 | + lib.optionalString ( |
|---|
| 139 | !svnSupport && !guiSupport && !sendEmailSupport && !withManual && !pythonSupport && !withpcre2 |
|---|
| 140 | ) "-minimal"; |
|---|
| 141 | inherit version; |
|---|
| 142 | |
|---|
| 143 | src = fetchurl { |
|---|
| 144 | url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz"; |
|---|
| 145 | hash = "sha256-sZJovmtvFVa0ep3YNCcuFn06dXQM3NKDzzgS7f/jkw8="; |
|---|
| 146 | }; |
|---|
| 147 | |
|---|
| 148 | outputs = [ "out" ] ++ lib.optional withManual "doc"; |
|---|
| 149 | separateDebugInfo = true; |
|---|
| 150 | |
|---|
| 151 | hardeningDisable = [ "format" ]; |
|---|
| 152 | |
|---|
| 153 | enableParallelBuilding = true; |
|---|
| 154 | |
|---|
| 155 | patches = |
|---|
| 156 | [ |
|---|
| 157 | ./docbook2texi.patch |
|---|
| 158 | ./git-sh-i18n.patch |
|---|
| 159 | ./git-send-email-honor-PATH.patch |
|---|
| 160 | ./installCheck-path.patch |
|---|
| 161 | ] |
|---|
| 162 | ++ lib.optionals withSsh [ |
|---|
| 163 | ./ssh-path.patch |
|---|
| 164 | ] |
|---|
| 165 | ++ lib.optionals (guiSupport && stdenv.hostPlatform.isDarwin) [ |
|---|
| 166 | # Needed to workaround an issue in macOS where gitk shows a empty window |
|---|
| 167 | # https://github.com/Homebrew/homebrew-core/issues/68798 |
|---|
| 168 | # https://github.com/git/git/pull/944 |
|---|
| 169 | (fetchpatch { |
|---|
| 170 | name = "gitk_check_main_window_visibility_before_waiting_for_it_to_show.patch"; |
|---|
| 171 | url = "https://github.com/git/git/commit/1db62e44b7ec93b6654271ef34065b31496cd02e.patch"; |
|---|
| 172 | hash = "sha256-ntvnrYFFsJ1Ebzc6vM9/AMFLHMS1THts73PIOG5DkQo="; |
|---|
| 173 | }) |
|---|
| 174 | ]; |
|---|
| 175 | |
|---|
| 176 | postPatch = |
|---|
| 177 | '' |
|---|
| 178 | # Fix references to gettext introduced by ./git-sh-i18n.patch |
|---|
| 179 | substituteInPlace git-sh-i18n.sh \ |
|---|
| 180 | --subst-var-by gettext ${gettext} |
|---|
| 181 | |
|---|
| 182 | # ensure we are using the correct shell when executing the test scripts |
|---|
| 183 | patchShebangs t/*.sh |
|---|
| 184 | '' |
|---|
| 185 | + lib.optionalString withSsh '' |
|---|
| 186 | for x in connect.c git-gui/lib/remote_add.tcl ; do |
|---|
| 187 | substituteInPlace "$x" \ |
|---|
| 188 | --subst-var-by ssh "${openssh}/bin/ssh" |
|---|
| 189 | done |
|---|
| 190 | ''; |
|---|
| 191 | |
|---|
| 192 | nativeBuildInputs = |
|---|
| 193 | [ |
|---|
| 194 | deterministic-host-uname |
|---|
| 195 | gettext |
|---|
| 196 | perlPackages.perl |
|---|
| 197 | makeWrapper |
|---|
| 198 | pkg-config |
|---|
| 199 | ] |
|---|
| 200 | ++ lib.optionals withManual [ |
|---|
| 201 | asciidoc |
|---|
| 202 | texinfo |
|---|
| 203 | xmlto |
|---|
| 204 | docbook2x |
|---|
| 205 | docbook_xsl |
|---|
| 206 | docbook_xml_dtd_45 |
|---|
| 207 | libxslt |
|---|
| 208 | ]; |
|---|
| 209 | buildInputs = |
|---|
| 210 | [ |
|---|
| 211 | curl |
|---|
| 212 | openssl |
|---|
| 213 | zlib |
|---|
| 214 | expat |
|---|
| 215 | cpio |
|---|
| 216 | (if stdenv.hostPlatform.isFreeBSD then libiconvReal else libiconv) |
|---|
| 217 | bash |
|---|
| 218 | ] |
|---|
| 219 | ++ lib.optionals perlSupport [ perlPackages.perl ] |
|---|
| 220 | ++ lib.optionals guiSupport [ |
|---|
| 221 | tcl |
|---|
| 222 | tk |
|---|
| 223 | ] |
|---|
| 224 | ++ lib.optionals withpcre2 [ pcre2 ] |
|---|
| 225 | ++ lib.optionals stdenv.hostPlatform.isDarwin [ |
|---|
| 226 | Security |
|---|
| 227 | CoreServices |
|---|
| 228 | ] |
|---|
| 229 | ++ lib.optionals withLibsecret [ |
|---|
| 230 | glib |
|---|
| 231 | libsecret |
|---|
| 232 | ]; |
|---|
| 233 | |
|---|
| 234 | # required to support pthread_cancel() |
|---|
| 235 | NIX_LDFLAGS = |
|---|
| 236 | lib.optionalString (stdenv.cc.isGNU && stdenv.hostPlatform.libc == "glibc") "-lgcc_s" |
|---|
| 237 | + lib.optionalString (stdenv.hostPlatform.isFreeBSD) "-lthr"; |
|---|
| 238 | |
|---|
| 239 | configureFlags = |
|---|
| 240 | [ |
|---|
| 241 | "ac_cv_prog_CURL_CONFIG=${lib.getDev curl}/bin/curl-config" |
|---|
| 242 | ] |
|---|
| 243 | ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ |
|---|
| 244 | "ac_cv_fread_reads_directories=yes" |
|---|
| 245 | "ac_cv_snprintf_returns_bogus=no" |
|---|
| 246 | "ac_cv_iconv_omits_bom=no" |
|---|
| 247 | ]; |
|---|
| 248 | |
|---|
| 249 | preBuild = '' |
|---|
| 250 | makeFlagsArray+=( perllibdir=$out/$(perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}') ) |
|---|
| 251 | ''; |
|---|
| 252 | |
|---|
| 253 | makeFlags = |
|---|
| 254 | [ |
|---|
| 255 | "prefix=\${out}" |
|---|
| 256 | ] |
|---|
| 257 | # Git does not allow setting a shell separately for building and run-time. |
|---|
| 258 | # Therefore lets leave it at the default /bin/sh when cross-compiling |
|---|
| 259 | ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}" |
|---|
| 260 | ++ (if perlSupport then [ "PERL_PATH=${perlPackages.perl}/bin/perl" ] else [ "NO_PERL=1" ]) |
|---|
| 261 | ++ (if pythonSupport then [ "PYTHON_PATH=${python3}/bin/python" ] else [ "NO_PYTHON=1" ]) |
|---|
| 262 | ++ lib.optionals stdenv.hostPlatform.isSunOS [ |
|---|
| 263 | "INSTALL=install" |
|---|
| 264 | "NO_INET_NTOP=" |
|---|
| 265 | "NO_INET_PTON=" |
|---|
| 266 | ] |
|---|
| 267 | ++ (if stdenv.hostPlatform.isDarwin then [ "NO_APPLE_COMMON_CRYPTO=1" ] else [ "sysconfdir=/etc" ]) |
|---|
| 268 | ++ lib.optionals stdenv.hostPlatform.isMusl [ |
|---|
| 269 | "NO_SYS_POLL_H=1" |
|---|
| 270 | "NO_GETTEXT=YesPlease" |
|---|
| 271 | ] |
|---|
| 272 | ++ lib.optional withpcre2 "USE_LIBPCRE2=1" |
|---|
| 273 | ++ lib.optional (!nlsSupport) "NO_GETTEXT=1" |
|---|
| 274 | # git-gui refuses to start with the version of tk distributed with |
|---|
| 275 | # macOS Catalina. We can prevent git from building the .app bundle |
|---|
| 276 | # by specifying an invalid tk framework. The postInstall step will |
|---|
| 277 | # then ensure that git-gui uses tcl/tk from nixpkgs, which is an |
|---|
| 278 | # acceptable version. |
|---|
| 279 | # |
|---|
| 280 | # See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706 |
|---|
| 281 | ++ lib.optional stdenv.hostPlatform.isDarwin "TKFRAMEWORK=/nonexistent"; |
|---|
| 282 | |
|---|
| 283 | disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ |
|---|
| 284 | stdenv.shellPackage |
|---|
| 285 | ]; |
|---|
| 286 | |
|---|
| 287 | postBuild = |
|---|
| 288 | '' |
|---|
| 289 | make -C contrib/subtree |
|---|
| 290 | '' |
|---|
| 291 | + (lib.optionalString perlSupport '' |
|---|
| 292 | make -C contrib/diff-highlight |
|---|
| 293 | '') |
|---|
| 294 | + (lib.optionalString osxkeychainSupport '' |
|---|
| 295 | make -C contrib/credential/osxkeychain |
|---|
| 296 | '') |
|---|
| 297 | + (lib.optionalString withLibsecret '' |
|---|
| 298 | make -C contrib/credential/libsecret |
|---|
| 299 | ''); |
|---|
| 300 | |
|---|
| 301 | ## Install |
|---|
| 302 | |
|---|
| 303 | # WARNING: Do not `rm` or `mv` files from the source tree; use `cp` instead. |
|---|
| 304 | # We need many of these files during the installCheckPhase. |
|---|
| 305 | |
|---|
| 306 | installFlags = [ "NO_INSTALL_HARDLINKS=1" ]; |
|---|
| 307 | |
|---|
| 308 | preInstall = |
|---|
| 309 | (lib.optionalString osxkeychainSupport '' |
|---|
| 310 | mkdir -p $out/bin |
|---|
| 311 | ln -s $out/share/git/contrib/credential/osxkeychain/git-credential-osxkeychain $out/bin/ |
|---|
| 312 | rm -f $PWD/contrib/credential/osxkeychain/git-credential-osxkeychain.o |
|---|
| 313 | '') |
|---|
| 314 | + (lib.optionalString withLibsecret '' |
|---|
| 315 | mkdir -p $out/bin |
|---|
| 316 | ln -s $out/share/git/contrib/credential/libsecret/git-credential-libsecret $out/bin/ |
|---|
| 317 | rm -f $PWD/contrib/credential/libsecret/git-credential-libsecret.o |
|---|
| 318 | ''); |
|---|
| 319 | |
|---|
| 320 | postInstall = |
|---|
| 321 | '' |
|---|
| 322 | notSupported() { |
|---|
| 323 | unlink $1 || true |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | # Install git-subtree. |
|---|
| 327 | make -C contrib/subtree install ${lib.optionalString withManual "install-doc"} |
|---|
| 328 | rm -rf contrib/subtree |
|---|
| 329 | |
|---|
| 330 | # Install contrib stuff. |
|---|
| 331 | mkdir -p $out/share/git |
|---|
| 332 | cp -a contrib $out/share/git/ |
|---|
| 333 | mkdir -p $out/share/bash-completion/completions |
|---|
| 334 | ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/git |
|---|
| 335 | ln -s $out/share/git/contrib/completion/git-prompt.sh $out/share/bash-completion/completions/ |
|---|
| 336 | # only readme, developed in another repo |
|---|
| 337 | rm -r contrib/hooks/multimail |
|---|
| 338 | mkdir -p $out/share/git-core/contrib |
|---|
| 339 | cp -a contrib/hooks/ $out/share/git-core/contrib/ |
|---|
| 340 | substituteInPlace $out/share/git-core/contrib/hooks/pre-auto-gc-battery \ |
|---|
| 341 | --replace ' grep' ' ${gnugrep}/bin/grep' \ |
|---|
| 342 | |
|---|
| 343 | # grep is a runtime dependency, need to patch so that it's found |
|---|
| 344 | substituteInPlace $out/libexec/git-core/git-sh-setup \ |
|---|
| 345 | --replace ' grep' ' ${gnugrep}/bin/grep' \ |
|---|
| 346 | --replace ' egrep' ' ${gnugrep}/bin/egrep' |
|---|
| 347 | |
|---|
| 348 | # Fix references to the perl, sed, awk and various coreutil binaries used by |
|---|
| 349 | # shell scripts that git calls (e.g. filter-branch) |
|---|
| 350 | SCRIPT="$(cat <<'EOS' |
|---|
| 351 | BEGIN{ |
|---|
| 352 | @a=( |
|---|
| 353 | '${gnugrep}/bin/grep', '${gnused}/bin/sed', '${gawk}/bin/awk', |
|---|
| 354 | '${coreutils}/bin/cut', '${coreutils}/bin/basename', '${coreutils}/bin/dirname', |
|---|
| 355 | '${coreutils}/bin/wc', '${coreutils}/bin/tr' |
|---|
| 356 | ${lib.optionalString perlSupport ", '${perlPackages.perl}/bin/perl'"} |
|---|
| 357 | ); |
|---|
| 358 | } |
|---|
| 359 | foreach $c (@a) { |
|---|
| 360 | $n=(split("/", $c))[-1]; |
|---|
| 361 | s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g |
|---|
| 362 | } |
|---|
| 363 | EOS |
|---|
| 364 | )" |
|---|
| 365 | perl -0777 -i -pe "$SCRIPT" \ |
|---|
| 366 | $out/libexec/git-core/git-{sh-setup,filter-branch,merge-octopus,mergetool,quiltimport,request-pull,submodule,subtree,web--browse} |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | # Also put git-http-backend into $PATH, so that we can use smart |
|---|
| 370 | # HTTP(s) transports for pushing |
|---|
| 371 | ln -s $out/libexec/git-core/git-http-backend $out/bin/git-http-backend |
|---|
| 372 | ln -s $out/share/git/contrib/git-jump/git-jump $out/bin/git-jump |
|---|
| 373 | '' |
|---|
| 374 | + lib.optionalString perlSupport '' |
|---|
| 375 | # wrap perl commands |
|---|
| 376 | makeWrapper "$out/share/git/contrib/credential/netrc/git-credential-netrc.perl" $out/bin/git-credential-netrc \ |
|---|
| 377 | --set PERL5LIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}" |
|---|
| 378 | wrapProgram $out/libexec/git-core/git-cvsimport \ |
|---|
| 379 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}" |
|---|
| 380 | wrapProgram $out/libexec/git-core/git-archimport \ |
|---|
| 381 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}" |
|---|
| 382 | wrapProgram $out/libexec/git-core/git-instaweb \ |
|---|
| 383 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}" |
|---|
| 384 | wrapProgram $out/libexec/git-core/git-cvsexportcommit \ |
|---|
| 385 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}" |
|---|
| 386 | |
|---|
| 387 | # gzip (and optionally bzip2, xz, zip) are runtime dependencies for |
|---|
| 388 | # gitweb.cgi, need to patch so that it's found |
|---|
| 389 | sed -i -e "s|'compressor' => \['gzip'|'compressor' => ['${gzip}/bin/gzip'|" \ |
|---|
| 390 | $out/share/gitweb/gitweb.cgi |
|---|
| 391 | # Give access to CGI.pm and friends (was removed from perl core in 5.22) |
|---|
| 392 | for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do |
|---|
| 393 | sed -i -e "/use CGI /i use lib \"$p/${perlPackages.perl.libPrefix}\";" \ |
|---|
| 394 | "$out/share/gitweb/gitweb.cgi" |
|---|
| 395 | done |
|---|
| 396 | '' |
|---|
| 397 | |
|---|
| 398 | + ( |
|---|
| 399 | if svnSupport then |
|---|
| 400 | '' |
|---|
| 401 | # wrap git-svn |
|---|
| 402 | wrapProgram $out/libexec/git-core/git-svn \ |
|---|
| 403 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${ |
|---|
| 404 | perlPackages.makePerlPath (perlLibs ++ [ svn.out ]) |
|---|
| 405 | }" \ |
|---|
| 406 | --prefix PATH : "${svn.out}/bin" |
|---|
| 407 | '' |
|---|
| 408 | else |
|---|
| 409 | '' |
|---|
| 410 | # replace git-svn by notification script |
|---|
| 411 | notSupported $out/libexec/git-core/git-svn |
|---|
| 412 | '' |
|---|
| 413 | ) |
|---|
| 414 | |
|---|
| 415 | + ( |
|---|
| 416 | if sendEmailSupport then |
|---|
| 417 | '' |
|---|
| 418 | # wrap git-send-email |
|---|
| 419 | wrapProgram $out/libexec/git-core/git-send-email \ |
|---|
| 420 | --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath smtpPerlLibs}" |
|---|
| 421 | '' |
|---|
| 422 | else |
|---|
| 423 | '' |
|---|
| 424 | # replace git-send-email by notification script |
|---|
| 425 | notSupported $out/libexec/git-core/git-send-email |
|---|
| 426 | '' |
|---|
| 427 | ) |
|---|
| 428 | |
|---|
| 429 | + lib.optionalString withManual '' |
|---|
| 430 | # Install man pages |
|---|
| 431 | make -j $NIX_BUILD_CORES PERL_PATH="${buildPackages.perl}/bin/perl" cmd-list.made install install-html \ |
|---|
| 432 | -C Documentation |
|---|
| 433 | '' |
|---|
| 434 | |
|---|
| 435 | + ( |
|---|
| 436 | if guiSupport then |
|---|
| 437 | '' |
|---|
| 438 | # Wrap Tcl/Tk programs |
|---|
| 439 | for prog in bin/gitk libexec/git-core/{git-gui,git-citool,git-gui--askpass}; do |
|---|
| 440 | sed -i -e "s|exec 'wish'|exec '${tk}/bin/wish'|g" \ |
|---|
| 441 | -e "s|exec wish|exec '${tk}/bin/wish'|g" \ |
|---|
| 442 | "$out/$prog" |
|---|
| 443 | done |
|---|
| 444 | ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/gitk |
|---|
| 445 | '' |
|---|
| 446 | else |
|---|
| 447 | '' |
|---|
| 448 | # Don't wrap Tcl/Tk, replace them by notification scripts |
|---|
| 449 | for prog in bin/gitk libexec/git-core/git-gui; do |
|---|
| 450 | notSupported "$out/$prog" |
|---|
| 451 | done |
|---|
| 452 | '' |
|---|
| 453 | ) |
|---|
| 454 | + lib.optionalString osxkeychainSupport '' |
|---|
| 455 | # enable git-credential-osxkeychain on darwin if desired (default) |
|---|
| 456 | mkdir -p $out/etc |
|---|
| 457 | cat > $out/etc/gitconfig << EOF |
|---|
| 458 | [credential] |
|---|
| 459 | helper = osxkeychain |
|---|
| 460 | EOF |
|---|
| 461 | ''; |
|---|
| 462 | |
|---|
| 463 | ## InstallCheck |
|---|
| 464 | |
|---|
| 465 | doCheck = false; |
|---|
| 466 | inherit doInstallCheck; |
|---|
| 467 | |
|---|
| 468 | installCheckTarget = "test"; |
|---|
| 469 | |
|---|
| 470 | # see also installCheckFlagsArray |
|---|
| 471 | installCheckFlags = [ |
|---|
| 472 | "DEFAULT_TEST_TARGET=prove" |
|---|
| 473 | "PERL_PATH=${buildPackages.perl}/bin/perl" |
|---|
| 474 | ]; |
|---|
| 475 | |
|---|
| 476 | nativeInstallCheckInputs = lib.optional ( |
|---|
| 477 | stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isFreeBSD |
|---|
| 478 | ) sysctl; |
|---|
| 479 | |
|---|
| 480 | preInstallCheck = |
|---|
| 481 | '' |
|---|
| 482 | installCheckFlagsArray+=( |
|---|
| 483 | GIT_PROVE_OPTS="--jobs $NIX_BUILD_CORES --failures --state=failed,save" |
|---|
| 484 | GIT_TEST_INSTALLED=$out/bin |
|---|
| 485 | ${lib.optionalString (!svnSupport) "NO_SVN_TESTS=y"} |
|---|
| 486 | ) |
|---|
| 487 | |
|---|
| 488 | function disable_test { |
|---|
| 489 | local test=$1 pattern=$2 |
|---|
| 490 | if [ $# -eq 1 ]; then |
|---|
| 491 | mv t/{,skip-}$test.sh || true |
|---|
| 492 | else |
|---|
| 493 | sed -i t/$test.sh \ |
|---|
| 494 | -e "/^\s*test_expect_.*$pattern/,/^\s*' *\$/{s/^/: #/}" |
|---|
| 495 | fi |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | # Shared permissions are forbidden in sandbox builds: |
|---|
| 499 | substituteInPlace t/test-lib.sh \ |
|---|
| 500 | --replace "test_set_prereq POSIXPERM" "" |
|---|
| 501 | # TODO: Investigate while these still fail (without POSIXPERM): |
|---|
| 502 | # Tested to fail: 2.46.0 |
|---|
| 503 | disable_test t0001-init 'shared overrides system' |
|---|
| 504 | # Tested to fail: 2.46.0 |
|---|
| 505 | disable_test t0001-init 'init honors global core.sharedRepository' |
|---|
| 506 | # Tested to fail: 2.46.0 |
|---|
| 507 | disable_test t1301-shared-repo |
|---|
| 508 | # /build/git-2.44.0/contrib/completion/git-completion.bash: line 452: compgen: command not found |
|---|
| 509 | disable_test t9902-completion |
|---|
| 510 | |
|---|
| 511 | # Our patched gettext never fallbacks |
|---|
| 512 | disable_test t0201-gettext-fallbacks |
|---|
| 513 | '' |
|---|
| 514 | + lib.optionalString (!sendEmailSupport) '' |
|---|
| 515 | # Disable sendmail tests |
|---|
| 516 | disable_test t9001-send-email |
|---|
| 517 | '' |
|---|
| 518 | + '' |
|---|
| 519 | # Flaky tests: |
|---|
| 520 | disable_test t6421-merge-partial-clone |
|---|
| 521 | |
|---|
| 522 | # Fails reproducibly on ZFS on Linux with formD normalization |
|---|
| 523 | disable_test t0021-conversion |
|---|
| 524 | disable_test t3910-mac-os-precompose |
|---|
| 525 | '' |
|---|
| 526 | + lib.optionalString stdenv.hostPlatform.isDarwin '' |
|---|
| 527 | # XXX: Some tests added in 2.24.0 fail. |
|---|
| 528 | # Please try to re-enable on the next release. |
|---|
| 529 | disable_test t7816-grep-binary-pattern |
|---|
| 530 | # fail (as of 2.33.0) |
|---|
| 531 | #===( 18623;1208 8/? 224/? 2/? )= =fatal: Not a valid object name refs/tags/signed-empty |
|---|
| 532 | disable_test t6300-for-each-ref |
|---|
| 533 | # not ok 1 - populate workdir (with 2.33.1 on x86_64-darwin) |
|---|
| 534 | disable_test t5003-archive-zip |
|---|
| 535 | '' |
|---|
| 536 | + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) '' |
|---|
| 537 | disable_test t7527-builtin-fsmonitor |
|---|
| 538 | '' |
|---|
| 539 | + lib.optionalString stdenv.hostPlatform.isMusl '' |
|---|
| 540 | # Test fails (as of 2.17.0, musl 1.1.19) |
|---|
| 541 | disable_test t3900-i18n-commit |
|---|
| 542 | # Fails largely due to assumptions about BOM |
|---|
| 543 | # Tested to fail: 2.18.0 |
|---|
| 544 | disable_test t0028-working-tree-encoding |
|---|
| 545 | ''; |
|---|
| 546 | |
|---|
| 547 | stripDebugList = [ |
|---|
| 548 | "lib" |
|---|
| 549 | "libexec" |
|---|
| 550 | "bin" |
|---|
| 551 | "share/git/contrib/credential/libsecret" |
|---|
| 552 | ]; |
|---|
| 553 | |
|---|
| 554 | passthru = { |
|---|
| 555 | shellPath = "/bin/git-shell"; |
|---|
| 556 | tests = { |
|---|
| 557 | withInstallCheck = finalAttrs.finalPackage.overrideAttrs (_: { |
|---|
| 558 | doInstallCheck = true; |
|---|
| 559 | }); |
|---|
| 560 | buildbot-integration = nixosTests.buildbot; |
|---|
| 561 | } // tests.fetchgit; |
|---|
| 562 | updateScript = ./update.sh; |
|---|
| 563 | }; |
|---|
| 564 | |
|---|
| 565 | meta = { |
|---|
| 566 | homepage = "https://git-scm.com/"; |
|---|
| 567 | description = "Distributed version control system"; |
|---|
| 568 | license = lib.licenses.gpl2; |
|---|
| 569 | changelog = "https://github.com/git/git/blob/v${version}/Documentation/RelNotes/${version}.txt"; |
|---|
| 570 | |
|---|
| 571 | longDescription = '' |
|---|
| 572 | Git, a popular distributed version control system designed to |
|---|
| 573 | handle very large projects with speed and efficiency. |
|---|
| 574 | ''; |
|---|
| 575 | |
|---|
| 576 | platforms = lib.platforms.all; |
|---|
| 577 | maintainers = with lib.maintainers; [ |
|---|
| 578 | primeos |
|---|
| 579 | wmertens |
|---|
| 580 | globin |
|---|
| 581 | kashw2 |
|---|
| 582 | ]; |
|---|
| 583 | mainProgram = "git"; |
|---|
| 584 | }; |
|---|
| 585 | }) |
|---|
| 586 | }}} |
|---|
| 587 | |
|---|
r4
| 588 | pkgs 원본 소스를 까봤는데 perlSupport 설정이 정신나갈 거 같다. 일단 그냥 symlink 강제로 박아서 해결할 듯. 일단 실행은 된다. |
|---|
r3
| 589 | |
|---|
r4
| 590 | {{{#!syntax sh |
|---|
| 591 | not ok 42 - aborted --continue does not squash commits after "edit" |
|---|
| 592 | # |
|---|
| 593 | # old=$(git rev-parse HEAD) && |
|---|
| 594 | # test_tick && |
|---|
| 595 | # ( |
|---|
| 596 | # set_fake_editor && |
|---|
| 597 | # FAKE_LINES="edit 1" git rebase -i HEAD^ && |
|---|
| 598 | # echo "edited again" > file7 && |
|---|
| 599 | # git add file7 && |
|---|
| 600 | # test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue |
|---|
| 601 | # ) && |
|---|
| 602 | # test $old = $(git rev-parse HEAD) && |
|---|
| 603 | # git rebase --abort |
|---|
| 604 | # |
|---|
| 605 | not ok 43 - auto-amend only edited commits after "edit" |
|---|
| 606 | # |
|---|
| 607 | # test_tick && |
|---|
| 608 | # ( |
|---|
| 609 | # set_fake_editor && |
|---|
| 610 | # FAKE_LINES="edit 1" git rebase -i HEAD^ && |
|---|
| 611 | # echo "edited again" > file7 && |
|---|
| 612 | # git add file7 && |
|---|
| 613 | # FAKE_COMMIT_MESSAGE="edited file7 again" git commit && |
|---|
| 614 | # echo "and again" > file7 && |
|---|
| 615 | # git add file7 && |
|---|
| 616 | # test_tick && |
|---|
| 617 | # test_must_fail env FAKE_COMMIT_MESSAGE="and again" \ |
|---|
| 618 | # git rebase --continue |
|---|
| 619 | # ) && |
|---|
| 620 | # git rebase --abort |
|---|
| 621 | # |
|---|
| 622 | not ok 44 - clean error after failed "exec" |
|---|
| 623 | # |
|---|
| 624 | # test_tick && |
|---|
| 625 | # test_when_finished "git rebase --abort || :" && |
|---|
| 626 | # ( |
|---|
| 627 | # set_fake_editor && |
|---|
| 628 | # test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ |
|---|
| 629 | # ) && |
|---|
| 630 | # echo "edited again" > file7 && |
|---|
| 631 | # git add file7 && |
|---|
| 632 | # test_must_fail git rebase --continue 2>error && |
|---|
| 633 | # test_grep "you have staged changes in your working tree" error && |
|---|
| 634 | # test_grep ! "could not open.*for reading" error |
|---|
| 635 | # |
|---|
| 636 | }}} |
|---|
| 637 | |
|---|
r1
| 638 | {{{#!syntax cpp |
|---|
| 639 | struct delta_index { |
|---|
| 640 | unsigned long memsize; |
|---|
| 641 | const void *src_buf; |
|---|
| 642 | unsigned long src_size; |
|---|
| 643 | unsigned int hash_mask; |
|---|
| 644 | struct index_entry *hash[FLEX_ARRAY]; |
|---|
| 645 | }; |
|---|
| 646 | |
|---|
| 647 | struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) |
|---|
| 648 | { |
|---|
| 649 | unsigned int i, hsize, hmask, entries, prev_val, *hash_count; |
|---|
| 650 | const unsigned char *data, *buffer = buf; |
|---|
| 651 | struct delta_index *index; |
|---|
| 652 | struct unpacked_index_entry *entry, **hash; |
|---|
| 653 | struct index_entry *packed_entry, **packed_hash; |
|---|
| 654 | void *mem; |
|---|
| 655 | unsigned long memsize; |
|---|
| 656 | |
|---|
| 657 | if (!buf || !bufsize) |
|---|
| 658 | return NULL; |
|---|
| 659 | |
|---|
| 660 | entries = (bufsize - 1) / RABIN_WINDOW; |
|---|
| 661 | if (bufsize >= 0xffffffffUL) { |
|---|
| 662 | entries = 0xfffffffeU / RABIN_WINDOW; |
|---|
| 663 | } |
|---|
| 664 | hsize = entries / 4; |
|---|
| 665 | for (i = 4; (1u << i) < hsize; i++); |
|---|
| 666 | hsize = 1 << i; |
|---|
| 667 | hmask = hsize - 1; |
|---|
| 668 | |
|---|
| 669 | /* allocate lookup index */ |
|---|
| 670 | memsize = sizeof(*hash) * hsize + |
|---|
| 671 | sizeof(*entry) * entries; |
|---|
| 672 | mem = malloc(memsize); |
|---|
| 673 | if (!mem) |
|---|
| 674 | return NULL; |
|---|
| 675 | hash = mem; |
|---|
| 676 | mem = hash + hsize; |
|---|
| 677 | entry = mem; |
|---|
| 678 | |
|---|
| 679 | memset(hash, 0, hsize * sizeof(*hash)); |
|---|
| 680 | |
|---|
| 681 | hash_count = calloc(hsize, sizeof(*hash_count)); |
|---|
| 682 | if (!hash_count) { |
|---|
| 683 | free(hash); |
|---|
| 684 | return NULL; |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | prev_val = ~0; |
|---|
| 688 | for (data = buffer + entries * RABIN_WINDOW - RABIN_WINDOW; |
|---|
| 689 | data >= buffer; |
|---|
| 690 | data -= RABIN_WINDOW) { |
|---|
| 691 | unsigned int val = 0; |
|---|
| 692 | for (i = 1; i <= RABIN_WINDOW; i++) |
|---|
| 693 | val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT]; |
|---|
| 694 | if (val == prev_val) { |
|---|
| 695 | entry[-1].entry.ptr = data + RABIN_WINDOW; |
|---|
| 696 | --entries; |
|---|
| 697 | } else { |
|---|
| 698 | prev_val = val; |
|---|
| 699 | i = val & hmask; |
|---|
| 700 | entry->entry.ptr = data + RABIN_WINDOW; |
|---|
| 701 | entry->entry.val = val; |
|---|
| 702 | entry->next = hash[i]; |
|---|
| 703 | hash[i] = entry++; |
|---|
| 704 | hash_count[i]++; |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | for (i = 0; i < hsize; i++) { |
|---|
| 709 | int acc; |
|---|
| 710 | |
|---|
| 711 | if (hash_count[i] <= HASH_LIMIT) |
|---|
| 712 | continue; |
|---|
| 713 | |
|---|
| 714 | entries -= hash_count[i] - HASH_LIMIT; |
|---|
| 715 | |
|---|
| 716 | entry = hash[i]; |
|---|
| 717 | acc = 0; |
|---|
| 718 | |
|---|
| 719 | do { |
|---|
| 720 | acc += hash_count[i] - HASH_LIMIT; |
|---|
| 721 | if (acc > 0) { |
|---|
| 722 | struct unpacked_index_entry *keep = entry; |
|---|
| 723 | do { |
|---|
| 724 | entry = entry->next; |
|---|
| 725 | acc -= HASH_LIMIT; |
|---|
| 726 | } while (acc > 0); |
|---|
| 727 | keep->next = entry->next; |
|---|
| 728 | } |
|---|
| 729 | entry = entry->next; |
|---|
| 730 | } while (entry); |
|---|
| 731 | } |
|---|
| 732 | free(hash_count); |
|---|
| 733 | |
|---|
| 734 | memsize = sizeof(*index) |
|---|
| 735 | + sizeof(*packed_hash) * (hsize+1) |
|---|
| 736 | + sizeof(*packed_entry) * entries; |
|---|
| 737 | mem = malloc(memsize); |
|---|
| 738 | if (!mem) { |
|---|
| 739 | free(hash); |
|---|
| 740 | return NULL; |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | index = mem; |
|---|
| 744 | index->memsize = memsize; |
|---|
| 745 | index->src_buf = buf; |
|---|
| 746 | index->src_size = bufsize; |
|---|
| 747 | index->hash_mask = hmask; |
|---|
| 748 | |
|---|
| 749 | mem = index->hash; |
|---|
| 750 | packed_hash = mem; |
|---|
| 751 | mem = packed_hash + (hsize+1); |
|---|
| 752 | packed_entry = mem; |
|---|
| 753 | |
|---|
| 754 | for (i = 0; i < hsize; i++) { |
|---|
| 755 | packed_hash[i] = packed_entry; |
|---|
| 756 | for (entry = hash[i]; entry; entry = entry->next) |
|---|
| 757 | *packed_entry++ = entry->entry; |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | packed_hash[hsize] = packed_entry; |
|---|
| 761 | |
|---|
| 762 | assert(packed_entry - (struct index_entry *)mem == entries); |
|---|
| 763 | free(hash); |
|---|
| 764 | |
|---|
| 765 | return index; |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | void free_delta_index(struct delta_index *index) |
|---|
| 769 | { |
|---|
| 770 | free(index); |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | unsigned long sizeof_delta_index(struct delta_index *index) |
|---|
| 774 | { |
|---|
| 775 | if (index) |
|---|
| 776 | return index->memsize; |
|---|
| 777 | else |
|---|
| 778 | return 0; |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | #define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7) |
|---|
| 782 | |
|---|
| 783 | void * |
|---|
| 784 | create_delta(const struct delta_index *index, |
|---|
| 785 | const void *trg_buf, unsigned long trg_size, |
|---|
| 786 | unsigned long *delta_size, unsigned long max_size) |
|---|
| 787 | { |
|---|
| 788 | unsigned int i, val; |
|---|
| 789 | off_t outpos, moff; |
|---|
| 790 | size_t l, outsize, msize; |
|---|
| 791 | int inscnt; |
|---|
| 792 | const unsigned char *ref_data, *ref_top, *data, *top; |
|---|
| 793 | unsigned char *out; |
|---|
| 794 | |
|---|
| 795 | *delta_size = 0; |
|---|
| 796 | |
|---|
| 797 | if (!trg_buf || !trg_size) |
|---|
| 798 | return NULL; |
|---|
| 799 | |
|---|
| 800 | outpos = 0; |
|---|
| 801 | outsize = 8192; |
|---|
| 802 | if (max_size && outsize >= max_size) |
|---|
| 803 | outsize = max_size + MAX_OP_SIZE + 1; |
|---|
| 804 | out = malloc(outsize); |
|---|
| 805 | if (!out) |
|---|
| 806 | return NULL; |
|---|
| 807 | |
|---|
| 808 | l = index->src_size; |
|---|
| 809 | while (l >= 0x80) { |
|---|
| 810 | out[outpos++] = l | 0x80; |
|---|
| 811 | l >>= 7; |
|---|
| 812 | } |
|---|
| 813 | out[outpos++] = l; |
|---|
| 814 | |
|---|
| 815 | l = trg_size; |
|---|
| 816 | while (l >= 0x80) { |
|---|
| 817 | out[outpos++] = l | 0x80; |
|---|
| 818 | l >>= 7; |
|---|
| 819 | } |
|---|
| 820 | out[outpos++] = l; |
|---|
| 821 | |
|---|
| 822 | ref_data = index->src_buf; |
|---|
| 823 | ref_top = ref_data + index->src_size; |
|---|
| 824 | data = trg_buf; |
|---|
| 825 | top = (const unsigned char *) trg_buf + trg_size; |
|---|
| 826 | |
|---|
| 827 | outpos++; |
|---|
| 828 | val = 0; |
|---|
| 829 | for (i = 0; i < RABIN_WINDOW && data < top; i++, data++) { |
|---|
| 830 | out[outpos++] = *data; |
|---|
| 831 | val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT]; |
|---|
| 832 | } |
|---|
| 833 | inscnt = i; |
|---|
| 834 | |
|---|
| 835 | moff = 0; |
|---|
| 836 | msize = 0; |
|---|
| 837 | while (data < top) { |
|---|
| 838 | if (msize < 4096) { |
|---|
| 839 | struct index_entry *entry; |
|---|
| 840 | val ^= U[data[-RABIN_WINDOW]]; |
|---|
| 841 | val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT]; |
|---|
| 842 | i = val & index->hash_mask; |
|---|
| 843 | for (entry = index->hash[i]; entry < index->hash[i+1]; entry++) { |
|---|
| 844 | const unsigned char *ref = entry->ptr; |
|---|
| 845 | const unsigned char *src = data; |
|---|
| 846 | unsigned int ref_size = ref_top - ref; |
|---|
| 847 | if (entry->val != val) |
|---|
| 848 | continue; |
|---|
| 849 | if (ref_size > top - src) |
|---|
| 850 | ref_size = top - src; |
|---|
| 851 | if (ref_size <= msize) |
|---|
| 852 | break; |
|---|
| 853 | while (ref_size-- && *src++ == *ref) |
|---|
| 854 | ref++; |
|---|
| 855 | if (msize < ref - entry->ptr) { |
|---|
| 856 | msize = ref - entry->ptr; |
|---|
| 857 | moff = entry->ptr - ref_data; |
|---|
| 858 | if (msize >= 4096) |
|---|
| 859 | break; |
|---|
| 860 | } |
|---|
| 861 | } |
|---|
| 862 | } |
|---|
| 863 | |
|---|
| 864 | if (msize < 4) { |
|---|
| 865 | if (!inscnt) |
|---|
| 866 | outpos++; |
|---|
| 867 | out[outpos++] = *data++; |
|---|
| 868 | inscnt++; |
|---|
| 869 | if (inscnt == 0x7f) { |
|---|
| 870 | out[outpos - inscnt - 1] = inscnt; |
|---|
| 871 | inscnt = 0; |
|---|
| 872 | } |
|---|
| 873 | msize = 0; |
|---|
| 874 | } else { |
|---|
| 875 | unsigned int left; |
|---|
| 876 | unsigned char *op; |
|---|
| 877 | |
|---|
| 878 | if (inscnt) { |
|---|
| 879 | while (moff && ref_data[moff-1] == data[-1]) { |
|---|
| 880 | msize++; |
|---|
| 881 | moff--; |
|---|
| 882 | data--; |
|---|
| 883 | outpos--; |
|---|
| 884 | if (--inscnt) |
|---|
| 885 | continue; |
|---|
| 886 | outpos--; |
|---|
| 887 | inscnt--; |
|---|
| 888 | break; |
|---|
| 889 | } |
|---|
| 890 | out[outpos - inscnt - 1] = inscnt; |
|---|
| 891 | inscnt = 0; |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | left = (msize < 0x10000) ? 0 : (msize - 0x10000); |
|---|
| 895 | msize -= left; |
|---|
| 896 | |
|---|
| 897 | op = out + outpos++; |
|---|
| 898 | i = 0x80; |
|---|
| 899 | |
|---|
| 900 | if (moff & 0x000000ff) |
|---|
| 901 | out[outpos++] = moff >> 0, i |= 0x01; |
|---|
| 902 | if (moff & 0x0000ff00) |
|---|
| 903 | out[outpos++] = moff >> 8, i |= 0x02; |
|---|
| 904 | if (moff & 0x00ff0000) |
|---|
| 905 | out[outpos++] = moff >> 16, i |= 0x04; |
|---|
| 906 | if (moff & 0xff000000) |
|---|
| 907 | out[outpos++] = moff >> 24, i |= 0x08; |
|---|
| 908 | |
|---|
| 909 | if (msize & 0x00ff) |
|---|
| 910 | out[outpos++] = msize >> 0, i |= 0x10; |
|---|
| 911 | if (msize & 0xff00) |
|---|
| 912 | out[outpos++] = msize >> 8, i |= 0x20; |
|---|
| 913 | |
|---|
| 914 | *op = i; |
|---|
| 915 | |
|---|
| 916 | data += msize; |
|---|
| 917 | moff += msize; |
|---|
| 918 | msize = left; |
|---|
| 919 | |
|---|
| 920 | if (moff > 0xffffffff) |
|---|
| 921 | msize = 0; |
|---|
| 922 | |
|---|
| 923 | if (msize < 4096) { |
|---|
| 924 | int j; |
|---|
| 925 | val = 0; |
|---|
| 926 | for (j = -RABIN_WINDOW; j < 0; j++) |
|---|
| 927 | val = ((val << 8) | data[j]) |
|---|
| 928 | ^ T[val >> RABIN_SHIFT]; |
|---|
| 929 | } |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | if (outpos >= outsize - MAX_OP_SIZE) { |
|---|
| 933 | void *tmp = out; |
|---|
| 934 | outsize = outsize * 3 / 2; |
|---|
| 935 | if (max_size && outsize >= max_size) |
|---|
| 936 | outsize = max_size + MAX_OP_SIZE + 1; |
|---|
| 937 | if (max_size && outpos > max_size) |
|---|
| 938 | break; |
|---|
| 939 | out = realloc(out, outsize); |
|---|
| 940 | if (!out) { |
|---|
| 941 | free(tmp); |
|---|
| 942 | return NULL; |
|---|
| 943 | } |
|---|
| 944 | } |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | if (inscnt) |
|---|
| 948 | out[outpos - inscnt - 1] = inscnt; |
|---|
| 949 | |
|---|
| 950 | if (max_size && outpos > max_size) { |
|---|
| 951 | free(out); |
|---|
| 952 | return NULL; |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | *delta_size = outpos; |
|---|
| 956 | return out; |
|---|
| 957 | } |
|---|
| 958 | }}} |
|---|