libgit2 / libgit2/libgit2

Potential bug when handling relative paths.

未關閉
#6,392 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
C
星號
10.6k
分支
2.7k
PR 合併指標
30 天內沒有已合併 PR

描述

Reproduction steps

Compile the following code (gcc example.c -lgit2), and run it against an object directory.
If we supply an absolute path, the example works fine.
./a.out /home/elliott/repo
If a relative path is provided, the example failed. The git_odb_write_multi_pack_index complains path issues.
./a.out [repo]

A sample repo can be downloaded here. repo.zip

// This simple example just opens a repo odb and writes out a multi-index pack.

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <git2.h>



struct Context {
	git_odb *db;
	git_odb_backend *backend;
	git_indexer *idxer;
};

int git_odb_foreach_cb_1(const git_oid *id, void *payload) {
	printf("%s\n", git_oid_tostr_s(id));
	return 0;
}

int main(int argc, char **argv) {

	struct Context c;

	if (argc != 2) {
		fprintf(stderr, "Usage: bug_example object_dir\n");
		return -1;
	}

	const char* obj_dir = argv[1];

	git_libgit2_init();

	if (git_odb_new(&c.db)) {
		fprintf(stderr, "Unable to open db\n");
		return -1;
	}

	if (git_odb_backend_pack(&c.backend, obj_dir)) {
		fprintf(stderr, "Unable to open backend\n");
		return -1;
	}

	if (git_odb_add_backend(c.db, c.backend, 1)) {
		fprintf(stderr, "Unable to add backend\n");
		return -1;
	}

	if (git_odb_foreach(c.db, git_odb_foreach_cb_1, &c)) {
		fprintf(stderr, "Unable to walk repo\n");
		return -1;
	}


	if (git_odb_write_multi_pack_index(c.db)) {
		fprintf(stderr, "Could not open repository: %s\n", git_error_last()->message);
		return -1;
	}

	return 0;
	
}
Expected behavior

Works on relative path and absolute path.

Actual behavior

If we supply an absolute path, the example works fine.
If a relative path is provided, the example failed. The git_odb_write_multi_pack_index complains path issues.

Version of libgit2 (release number or SHA1)

Tested on 1.5 and 1.4

Operating system(s) tested

Ubuntu 22.04

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,使用 libgit2 1.5 或 1.4 編譯所提供的 C 範例,並使用連結的範例儲存庫執行它,同時比較物件目錄的絕對路徑和相對路徑。追蹤 git_odb_backend_pack 和 git_odb_write_multi_pack_index 呼叫,以找出相對路徑在哪裡失敗;當兩種呼叫形式都能在沒有路徑錯誤的情況下運作時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, git
領域
database
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。