nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: rsteube/carapace
Pull request #107 (2020-11-15 18:14:52)

zsh: fix lazy completion script


Patch:
diff --git a/zsh/snippet.go b/zsh/snippet.go
index 4d66789..10cb648 100644
--- a/zsh/snippet.go
+++ b/zsh/snippet.go
@@ -22,11 +22,14 @@ var replacer = strings.NewReplacer(
 func snippetLazy(cmd *cobra.Command) string {
 	return fmt.Sprintf(`#compdef %v
 function _%v {
+    compdef -d %v
+    unfunction _%v
     source <(%v _carapace zsh)
 }
 
-if compquote '' 2>/dev/null; then _%v; else compdef _%v %v; fi
-`, cmd.Name(), cmd.Name(), uid.Executable(), cmd.Name(), cmd.Name(), cmd.Name())
+compquote '' 2>/dev/null && _%v
+compdef _%v %v
+`, cmd.Name(), cmd.Name(), cmd.Name(), cmd.Name(), uid.Executable(), cmd.Name(), cmd.Name(), cmd.Name())
 }
 
 func Snippet(cmd *cobra.Command, actions map[string]string, lazy bool) string {
@@ -42,7 +45,7 @@ func Snippet(cmd *cobra.Command, actions map[string]string, lazy bool) string {
 `, cmd.Name(), uid.Executable())
 	result += snippetFunctions(cmd, actions)
 
-	result += fmt.Sprintf("if compquote '' 2>/dev/null; then _%v; else compdef _%v %v; fi\n", cmd.Name(), cmd.Name(), cmd.Name()) // check if withing completion function and enable direct sourcing
+	result += fmt.Sprintf("compquote '' 2>/dev/null && _%v\ncompdef _%v %v\n", cmd.Name(), cmd.Name(), cmd.Name())
 	return result
 }
 


Test patch:
diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go
index d7382ea..a951ac7 100644
--- a/example/cmd/root_test.go
+++ b/example/cmd/root_test.go
@@ -1356,7 +1356,8 @@ function _example__multiparts {
     "1: :{_example_callback '_example__multiparts#1'}" \
     "*: :{_example_callback '_example__multiparts#0'}"
 }
-if compquote '' 2>/dev/null; then _example; else compdef _example example; fi
+compquote '' 2>/dev/null && _example
+compdef _example example
 `
 	rootCmd.InitDefaultHelpCmd()
 	assert.Equal(t, expected, carapace.Gen(rootCmd).Snippet("zsh", false))
Repository: rsteube/carapace
Pull request #108 (2020-11-17 23:17:29)

elvish: use eval for callback


Patch:
diff --git a/Dockerfile.elvish b/Dockerfile.elvish
index 20fca08..f851ea6 100644
--- a/Dockerfile.elvish
+++ b/Dockerfile.elvish
@@ -1,6 +1,6 @@
 FROM golang
 
-RUN curl https://dl.elv.sh/linux-amd64/elvish-v0.14.1.tar.gz | tar -xvz \
+RUN curl https://dl.elv.sh/linux-amd64/elvish-HEAD.tar.gz | tar -xvz \
  && mv elvish-* /usr/local/bin/elvish
 
 ENV PS1=$'%{\e[0;36m%}carapace %{\e[0m%}'
diff --git a/elvish/snippet.go b/elvish/snippet.go
index fd77dd0..c946ad7 100644
--- a/elvish/snippet.go
+++ b/elvish/snippet.go
@@ -36,14 +36,10 @@ func Snippet(cmd *cobra.Command, actions map[string]string, lazy bool) string {
 	result := fmt.Sprintf(`use str
 edit:completion:arg-completer[%v] = [@arg]{
   fn _%v_callback [uid]{
-    # TODO there is no 'eval' in elvish and '-source' needs a file so use a tempary one for callback 
-    tmpfile=(mktemp -t carapace_%v_callback-XXXXX.elv)
     if (eq $arg[-1] "") {
         arg[-1] = "''"
     }
-    echo (str:join ' ' $arg) | xargs %v _carapace elvish $uid > $tmpfile
-    -source $tmpfile
-    rm $tmpfile
+    eval (echo (str:join ' ' $arg) | xargs %v _carapace elvish $uid | slurp)
   }
 
   fn subindex [subcommand]{
@@ -57,7 +53,7 @@ edit:completion:arg-completer[%v] = [@arg]{
   if (eq 1 0) {
   } %v
 }
-`, cmd.Name(), cmd.Name(), cmd.Name(), uid.Executable(), uid.Executable(), snippetFunctions(cmd, actions))
+`, cmd.Name(), cmd.Name(), uid.Executable(), uid.Executable(), snippetFunctions(cmd, actions))
 
 	return result
 }


Test patch:
diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go
index a951ac7..1635767 100644
--- a/example/cmd/root_test.go
+++ b/example/cmd/root_test.go
@@ -284,14 +284,10 @@ func TestElvish(t *testing.T) {
 	expected := `use str
 edit:completion:arg-completer[example] = [@arg]{
   fn _example_callback [uid]{
-    # TODO there is no 'eval' in elvish and '-source' needs a file so use a tempary one for callback 
-    tmpfile=(mktemp -t carapace_example_callback-XXXXX.elv)
     if (eq $arg[-1] "") {
         arg[-1] = "''"
     }
-    echo (str:join ' ' $arg) | xargs example _carapace elvish $uid > $tmpfile
-    -source $tmpfile
-    rm $tmpfile
+    eval (echo (str:join ' ' $arg) | xargs example _carapace elvish $uid | slurp)
   }
 
   fn subindex [subcommand]{
Repository: rsteube/carapace
Pull request #111 (2020-11-18 18:39:15)

xonsh: fix empty callback result


Patch:
diff --git a/xonsh/snippet.go b/xonsh/snippet.go
index 1f10629..681f757 100644
--- a/xonsh/snippet.go
+++ b/xonsh/snippet.go
@@ -86,8 +86,11 @@ def _%v_completer(prefix, line, begidx, endidx, ctx):
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()
         cb = cb.decode('utf-8')
-        nonlocal prefix, line, begidx, endidx, ctx
-        return eval(cb)
+        if cb == "":
+            return {}
+        else:
+            nonlocal prefix, line, begidx, endidx, ctx
+            return eval(cb)
    
     if False:
         pass%s


Test patch:
diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go
index 25d63e2..f79f251 100644
--- a/example/cmd/root_test.go
+++ b/example/cmd/root_test.go
@@ -940,8 +940,11 @@ def _example_completer(prefix, line, begidx, endidx, ctx):
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE).communicate()
         cb = cb.decode('utf-8')
-        nonlocal prefix, line, begidx, endidx, ctx
-        return eval(cb)
+        if cb == "":
+            return {}
+        else:
+            nonlocal prefix, line, begidx, endidx, ctx
+            return eval(cb)
    
     if False:
         pass
Repository: allegro/bigcache
Pull request #299 (2021-11-14 18:31:12)

Adding config validation when creating new cache.
Otherwise this causes more cryptic failures in later code. Best to catch this on initialization.

panmari: Added test coverage.
panmari: Sure thing, switched to a table test.
janisz: We need to also fix comments https://github.com/allegro/bigcache/blob/master/config.go#L12

Patch:
diff --git a/bigcache.go b/bigcache.go
index c4439c1..7ae1f12 100644
--- a/bigcache.go
+++ b/bigcache.go
@@ -46,10 +46,18 @@ func NewBigCache(config Config) (*BigCache, error) {
 }
 
 func newBigCache(config Config, clock clock) (*BigCache, error) {
-
 	if !isPowerOfTwo(config.Shards) {
 		return nil, fmt.Errorf("Shards number must be power of two")
 	}
+	if config.MaxEntrySize < 0 {
+		return nil, fmt.Errorf("MaxEntrySize must be >= 0")
+	}
+	if config.MaxEntriesInWindow < 0 {
+		return nil, fmt.Errorf("MaxEntriesInWindow must be >= 0")
+	}
+	if config.HardMaxCacheSize < 0 {
+		return nil, fmt.Errorf("HardMaxCacheSize must be >= 0")
+	}
 
 	if config.Hasher == nil {
 		config.Hasher = newDefaultHasher()


Test patch:
diff --git a/bigcache_test.go b/bigcache_test.go
index b62a5a9..f4749d1 100644
--- a/bigcache_test.go
+++ b/bigcache_test.go
@@ -156,19 +156,37 @@ func TestConstructCacheWithDefaultHasher(t *testing.T) {
 	assertEqual(t, true, ok)
 }
 
-func TestWillReturnErrorOnInvalidNumberOfPartitions(t *testing.T) {
+func TestNewBigcacheValidation(t *testing.T) {
 	t.Parallel()
 
-	// given
-	cache, error := NewBigCache(Config{
-		Shards:             18,
-		LifeWindow:         5 * time.Second,
-		MaxEntriesInWindow: 10,
-		MaxEntrySize:       256,
-	})
-
-	assertEqual(t, (*BigCache)(nil), cache)
-	assertEqual(t, "Shards number must be power of two", error.Error())
+	for _, tc := range []struct {
+		cfg  Config
+		want string
+	}{
+		{
+			cfg:  Config{Shards: 18},
+			want: "Shards number must be power of two",
+		},
+		{
+			cfg:  Config{Shards: 16, MaxEntriesInWindow: -1},
+			want: "MaxEntriesInWindow must be >= 0",
+		},
+		{
+			cfg:  Config{Shards: 16, MaxEntrySize: -1},
+			want: "MaxEntrySize must be >= 0",
+		},
+		{
+			cfg:  Config{Shards: 16, HardMaxCacheSize: -1},
+			want: "HardMaxCacheSize must be >= 0",
+		},
+	} {
+		t.Run(tc.want, func(t *testing.T) {
+			cache, error := NewBigCache(tc.cfg)
+
+			assertEqual(t, (*BigCache)(nil), cache)
+			assertEqual(t, tc.want, error.Error())
+		})
+	}
 }
 
 func TestEntryNotFound(t *testing.T) {
Repository: allegro/bigcache
Pull request #366 (2023-06-27 15:51:20)

Added extra endpoint for clear cache
Hi, like I [mentioned](https://github.com/allegro/bigcache/issues/71) before, I did extra endpoint for clear all cache.
At the moment, i don't have enough time for change design code. I just need this endpoint for use API server. 

agoalofalife: By the way, I will be able to update the documentation in readme.
agoalofalife: and then?

Patch:
diff --git a/server/cache_handlers.go b/server/cache_handlers.go
index 97ca02d..ee802a0 100644
--- a/server/cache_handlers.go
+++ b/server/cache_handlers.go
@@ -20,6 +20,21 @@ func cacheIndexHandler() http.Handler {
 	})
 }
 
+func cacheClearHandler() http.Handler {
+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		clearCache(w, r)
+	})
+}
+
+func clearCache(w http.ResponseWriter, r *http.Request) {
+	if err := cache.Reset(); err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		log.Printf("internal cache error: %s", err)
+	}
+	log.Println("cache is successfully cleared")
+	w.WriteHeader(http.StatusOK)
+}
+
 // handles get requests.
 func getCacheHandler(w http.ResponseWriter, r *http.Request) {
 	target := r.URL.Path[len(cachePath):]
diff --git a/server/server.go b/server/server.go
index 46486a2..a8f8860 100644
--- a/server/server.go
+++ b/server/server.go
@@ -18,9 +18,9 @@ const (
 	apiBasePath = "/api/" + apiVersion + "/"
 
 	// path to cache.
-	cachePath = apiBasePath + "cache/"
-	statsPath = apiBasePath + "stats"
-
+	cachePath      = apiBasePath + "cache/"
+	statsPath      = apiBasePath + "stats"
+	cacheClearPath = apiBasePath + "cache/clear"
 	// server version.
 	version = "1.0.0"
 )
@@ -76,6 +76,7 @@ func main() {
 	logger.Print("cache initialised.")
 
 	// let the middleware log.
+	http.Handle(cacheClearPath, serviceLoader(cacheClearHandler(), requestMetrics(logger)))
 	http.Handle(cachePath, serviceLoader(cacheIndexHandler(), requestMetrics(logger)))
 	http.Handle(statsPath, serviceLoader(statsIndexHandler(), requestMetrics(logger)))
 


Test patch:
diff --git a/server/server_test.go b/server/server_test.go
index b71ef32..266afef 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -158,6 +158,28 @@ func TestDeleteKey(t *testing.T) {
 	}
 }
 
+func TestClearCache(t *testing.T) {
+	t.Parallel()
+
+	putRequest := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer([]byte("123")))
+	putResponseRecorder := httptest.NewRecorder()
+
+	putCacheHandler(putResponseRecorder, putRequest)
+
+	requestClear := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/clear", nil)
+	rr := httptest.NewRecorder()
+
+	if err := cache.Set("testDeleteKey", []byte("123")); err != nil {
+		t.Errorf("can't set key for testing. %s", err)
+	}
+
+	clearCache(rr, requestClear)
+	resp := rr.Result()
+
+	if resp.StatusCode != 200 {
+		t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
+	}
+}
 func TestGetStats(t *testing.T) {
 	t.Parallel()
 	var testStats bigcache.Stats