nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: elixir-gettext/gettext
Pull request #281 (2021-08-20 08:42:57)

Make dngettext/6 bindings optional
According to [the examples](https://hexdocs.pm/gettext/Gettext.html#dngettext/6-examples) `dngettext/6`'s last argument `bindings` is supposed to be optional.
Please let me know If I need to leave the function as is and edit the examples instead.


Patch:
diff --git a/lib/gettext.ex b/lib/gettext.ex
index 2b6b60b..9863b50 100644
--- a/lib/gettext.ex
+++ b/lib/gettext.ex
@@ -907,7 +907,7 @@ defmodule Gettext do
 
   """
   @spec dngettext(module, binary, binary, binary, non_neg_integer, bindings) :: binary
-  def dngettext(backend, domain, msgid, msgid_plural, n, bindings),
+  def dngettext(backend, domain, msgid, msgid_plural, n, bindings \\ %{}),
     do: dpngettext(backend, domain, nil, msgid, msgid_plural, n, bindings)
 
   @doc """


Test patch:
diff --git a/test/fixtures/test_application/priv/gettext/it/LC_MESSAGES/interpolations.po b/test/fixtures/test_application/priv/gettext/it/LC_MESSAGES/interpolations.po
index d16ca98..60df957 100644
--- a/test/fixtures/test_application/priv/gettext/it/LC_MESSAGES/interpolations.po
+++ b/test/fixtures/test_application/priv/gettext/it/LC_MESSAGES/interpolations.po
@@ -9,6 +9,11 @@ msgid_plural "You have %{count} messages, %{name}"
 msgstr[0] "Hai un messaggio, %{name}"
 msgstr[1] "Hai %{count} messaggi, %{name}"
 
+msgid "Month"
+msgid_plural "%{count} months"
+msgstr[0] "Mese"
+msgstr[1] "%{count} mesi"
+
 msgctxt "test"
 msgid "You have one message, %{name}"
 msgid_plural "You have %{count} messages, %{name}"
diff --git a/test/gettext_test.exs b/test/gettext_test.exs
index d847f8c..bc1dac7 100644
--- a/test/gettext_test.exs
+++ b/test/gettext_test.exs
@@ -566,6 +566,13 @@ defmodule GettextTest do
              2,
              %{name: "James"}
            ) == "Hai 2 messaggi, James"
+
+    assert Translator.dngettext(
+             "interpolations",
+             "Month",
+             "%{count} months",
+             2
+           ) == "2 mesi"
   end
 
   @ngettext_msgid "One new email"
@@ -663,6 +670,9 @@ defmodule GettextTest do
 
     assert Gettext.dngettext(Translator, "interpolations", msgid, msgid_plural, 5, %{name: "Meg"}) ==
              "Hai 5 messaggi, Meg"
+
+    assert Gettext.dngettext(Translator, "interpolations", "Month", "%{count} months", 5) ==
+             "5 mesi"
   end
 
   test "dpngettext/6" do
Repository: elixir-gettext/gettext
Pull request #285 (2021-08-31 08:18:36)

Increase Mix.Tasks.Gettext.Merge task timeout.
Increasing the task timeout, necessary when project starts to get big !


Patch:
diff --git a/lib/gettext/merger.ex b/lib/gettext/merger.ex
index 19ee311..0148aac 100644
--- a/lib/gettext/merger.ex
+++ b/lib/gettext/merger.ex
@@ -141,7 +141,7 @@ defmodule Gettext.Merger do
   # msgstr: new.msgstr should be empty since it comes from a POT file
   # comments: new has no translator comments as it comes from POT
   # extracted_comments: we should take the new most recent ones
-  # flags: we should take the new flags
+  # flags: we should take the new flags and preserve the fuzzy flag
   # references: new contains the updated and most recent references
 
   defp merge_two_translations(%Translation{} = old, %Translation{} = new) do
@@ -151,7 +151,7 @@ defmodule Gettext.Merger do
       msgstr: old.msgstr,
       comments: old.comments,
       extracted_comments: new.extracted_comments,
-      flags: new.flags,
+      flags: merge_flags(old.flags, new.flags),
       references: new.references
     }
   end
@@ -164,11 +164,19 @@ defmodule Gettext.Merger do
       msgstr: old.msgstr,
       comments: old.comments,
       extracted_comments: new.extracted_comments,
-      flags: new.flags,
+      flags: merge_flags(old.flags, new.flags),
       references: new.references
     }
   end
 
+  defp merge_flags(%MapSet{} = old, %MapSet{} = new) do
+    if MapSet.member?(old, "fuzzy") do
+      MapSet.put(new, "fuzzy")
+    else
+      new
+    end
+  end
+
   @doc """
   Returns the contents of a new PO file to be written at `po_file` from the POT
   template in `pot_file`.
diff --git a/lib/mix/tasks/gettext.merge.ex b/lib/mix/tasks/gettext.merge.ex
index 3192e3c..0db3356 100644
--- a/lib/mix/tasks/gettext.merge.ex
+++ b/lib/mix/tasks/gettext.merge.ex
@@ -186,7 +186,7 @@ defmodule Mix.Tasks.Gettext.Merge do
     pot_dir
     |> Path.join("*.pot")
     |> Path.wildcard()
-    |> Task.async_stream(merger, ordered: false, timeout: 10_000)
+    |> Task.async_stream(merger, ordered: false, timeout: :infinity)
     |> Stream.run()
 
     warn_for_po_without_pot(po_dir, pot_dir)


Test patch:
diff --git a/test/gettext/merger_test.exs b/test/gettext/merger_test.exs
index aafa455..0acebf2 100644
--- a/test/gettext/merger_test.exs
+++ b/test/gettext/merger_test.exs
@@ -58,6 +58,14 @@ defmodule Gettext.MergerTest do
       assert t.comments == ["# existing comment"]
     end
 
+    test "when translations match, existing translator flags are preserved" do
+      old_po = %PO{translations: [%Translation{msgid: "foo", flags: MapSet.new(["fuzzy"])}]}
+      new_pot = %PO{translations: [%Translation{msgid: "foo"}]}
+
+      assert {%PO{translations: [t]}, _stats} = Merger.merge(old_po, new_pot, "en", @opts)
+      assert MapSet.member?(t.flags, "fuzzy")
+    end
+
     test "when translations match, existing extracted comments are replaced by new ones" do
       old_po = %PO{
         translations: [
Repository: elixir-gettext/gettext
Pull request #309 (2022-05-02 11:01:50)

Uniq comments for same translation
Solves https://github.com/elixir-gettext/gettext/issues/308

Distinct comments for a same Gettext text on extraction, so a `gettext_comment/1` can be added into multiple places inside one or more apps, without duplications at the final `.pot` file.


Patch:
diff --git a/lib/gettext/extractor_agent.ex b/lib/gettext/extractor_agent.ex
index 4ab2146..9da2f9c 100644
--- a/lib/gettext/extractor_agent.ex
+++ b/lib/gettext/extractor_agent.ex
@@ -75,6 +75,6 @@ defmodule Gettext.ExtractorAgent do
   defp merge_translations(t1, t2) do
     t1
     |> Map.put(:references, t1.references ++ t2.references)
-    |> Map.put(:extracted_comments, t1.extracted_comments ++ t2.extracted_comments)
+    |> Map.put(:extracted_comments, Enum.uniq(t1.extracted_comments ++ t2.extracted_comments))
   end
 end


Test patch:
diff --git a/test/gettext/extractor_test.exs b/test/gettext/extractor_test.exs
index fd020c6..b2765ac 100644
--- a/test/gettext/extractor_test.exs
+++ b/test/gettext/extractor_test.exs
@@ -272,9 +272,12 @@ defmodule Gettext.ExtractorTest do
       def bar do
         gettext_comment("some comment")
         gettext_comment("some other comment")
+        gettext_comment("repeated comment")
         gettext("foo")
         dngettext("errors", "one error", "%{count} errors", 2)
         gettext_comment("one more comment")
+        gettext_comment("repeated comment")
+        gettext_comment("repeated comment")
         gettext("foo")
         Gettext.ExtractorTest.MyOtherGettext.dgettext("greetings", "hi")
         pgettext("test", "context based translation")
@@ -292,15 +295,16 @@ defmodule Gettext.ExtractorTest do
 
        #. some comment
        #. some other comment
+       #. repeated comment
        #. one more comment
        #, elixir-autogen, elixir-format
-       #: foo.ex:16
-       #: foo.ex:19
+       #: foo.ex:17
+       #: foo.ex:22
        msgid "foo"
        msgstr ""
 
        #, elixir-autogen, elixir-format
-       #: foo.ex:21
+       #: foo.ex:24
        msgctxt "test"
        msgid "context based translation"
        msgstr ""
@@ -311,7 +315,7 @@ defmodule Gettext.ExtractorTest do
        msgstr ""
 
        #, elixir-autogen, elixir-format
-       #: foo.ex:17
+       #: foo.ex:18
        msgid "one error"
        msgid_plural "%{count} errors"
        msgstr[0] ""
@@ -323,7 +327,7 @@ defmodule Gettext.ExtractorTest do
        msgstr ""
 
        #, elixir-autogen, elixir-format
-       #: foo.ex:20
+       #: foo.ex:23
        msgid "hi"
        msgstr ""
        """}
Repository: elixir-grpc/grpc
Pull request #101 (2019-06-03 15:21:06)

Return already started pid when starting server
I came across this when using elixir-grpc in my tests. Instead of bombing out when the server is already started, return the running pid to remove that potential error.

Thanks for making this library.


Patch:
diff --git a/lib/grpc/adapter/cowboy.ex b/lib/grpc/adapter/cowboy.ex
index b9b894e..4546857 100644
--- a/lib/grpc/adapter/cowboy.ex
+++ b/lib/grpc/adapter/cowboy.ex
@@ -16,7 +16,14 @@ defmodule GRPC.Adapter.Cowboy do
     start_args = cowboy_start_args(endpoint, servers, port, opts)
     start_func = if opts[:cred], do: :start_tls, else: :start_clear
 
-    {:ok, pid} = apply(:cowboy, start_func, start_args)
+    {:ok, pid} =
+      case apply(:cowboy, start_func, start_args) do
+        {:ok, pid} ->
+          {:ok, pid}
+
+        {:error, {:already_started, pid}} ->
+          {:ok, pid}
+      end
 
     port = :ranch.get_port(servers_name(endpoint, servers))
     {:ok, pid, port}


Test patch:
diff --git a/test/grpc/server_test.exs b/test/grpc/server_test.exs
index ecea03f..dea4cdf 100644
--- a/test/grpc/server_test.exs
+++ b/test/grpc/server_test.exs
@@ -9,6 +9,12 @@ defmodule GRPC.ServerTest do
     use GRPC.Server, service: Greeter.Service
   end
 
+  test "start/2 works" do
+    {:ok, pid, port} = GRPC.Server.start(Greeter.Server, 50053)
+
+    assert {:ok, ^pid, ^port} = GRPC.Server.start(Greeter.Server, 50053)
+  end
+
   test "stop/2 works" do
     assert {nil, %{"hello" => GRPC.ServerTest.Greeter.Server}} =
              GRPC.Server.stop(Greeter.Server, adapter: GRPC.Test.ServerAdapter)
Repository: elixir-grpc/grpc
Pull request #119 (2019-11-08 12:21:58)

Add ability to retreive the peer
This is mainly driven by the fact that you cannot retrieve the client's IP address, which is vital for logging.

tony612: Could you add a test and merge/rebase master?
szahariev: @tony612: Can you take a look at the test and tell me if it looks ok to you?

Patch:
diff --git a/lib/grpc/adapter/cowboy.ex b/lib/grpc/adapter/cowboy.ex
index e25ff98..0ebb3a6 100644
--- a/lib/grpc/adapter/cowboy.ex
+++ b/lib/grpc/adapter/cowboy.ex
@@ -139,6 +139,10 @@ defmodule GRPC.Adapter.Cowboy do
     Handler.get_headers(pid)
   end
 
+  def get_peer(%{pid: pid}) do
+    Handler.get_peer(pid)
+  end
+
   def set_compressor(%{pid: pid}, compressor) do
     Handler.set_compressor(pid, compressor)
   end
diff --git a/lib/grpc/adapter/cowboy/handler.ex b/lib/grpc/adapter/cowboy/handler.ex
index a43035c..45a95f4 100644
--- a/lib/grpc/adapter/cowboy/handler.ex
+++ b/lib/grpc/adapter/cowboy/handler.ex
@@ -145,6 +145,10 @@ defmodule GRPC.Adapter.Cowboy.Handler do
     sync_call(pid, :get_headers)
   end
 
+  def get_peer(pid) do
+    sync_call(pid, :get_peer)
+  end
+
   defp sync_call(pid, key) do
     ref = make_ref()
     send(pid, {key, ref, self()})
@@ -185,6 +189,12 @@ defmodule GRPC.Adapter.Cowboy.Handler do
     {:ok, req, state}
   end
 
+  def info({:get_peer, ref, pid}, req, state) do
+    peer = :cowboy_req.peer(req)
+    send(pid, {ref, peer})
+    {:ok, req, state}
+  end
+
   def info({:stream_body, data, opts, is_fin}, req, state) do
     # If compressor exists, compress is true by default
     compressor =


Test patch:
diff --git a/test/grpc/integration/server_test.exs b/test/grpc/integration/server_test.exs
index 6baafc6..3960bf1 100644
--- a/test/grpc/integration/server_test.exs
+++ b/test/grpc/integration/server_test.exs
@@ -17,6 +17,12 @@ defmodule GRPC.Integration.ServerTest do
       Helloworld.HelloReply.new(message: "Hello, #{name}")
     end
 
+    def say_hello(%{name: "get peer"}, stream) do
+      {ip, _port} = stream.adapter.get_peer(stream.payload)
+      name = to_string(:inet_parse.ntoa(ip))
+      Helloworld.HelloReply.new(message: "Hello, #{name}")
+    end
+
     def say_hello(req, _stream) do
       Helloworld.HelloReply.new(message: "Hello, #{req.name}")
     end
@@ -178,4 +184,14 @@ defmodule GRPC.Integration.ServerTest do
       assert reply.authorization == token
     end)
   end
+
+  test "get peer returns correct IP address" do
+    run_server([HelloServer], fn port ->
+      {:ok, channel} = GRPC.Stub.connect("localhost:#{port}")
+
+      req = Helloworld.HelloRequest.new(name: "get peer")
+      {:ok, reply} = channel |> Helloworld.Greeter.Stub.say_hello(req)
+      assert reply.message == "Hello, 127.0.0.1"
+    end)
+  end
 end