summaryrefslogtreecommitdiff
path: root/builtin/replace.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-04-26 20:00:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-04-29 19:38:33 (GMT)
commit479bd75751d81b6f3ffc29fcece56f9a200493a1 (patch)
tree976ed12dbbf9a2e4c097f2aa9d3d27fcb04c8305 /builtin/replace.c
parent70c7bd6dafc83eee7bf76d33d12027224d80f20d (diff)
downloadgit-479bd75751d81b6f3ffc29fcece56f9a200493a1.zip
git-479bd75751d81b6f3ffc29fcece56f9a200493a1.tar.gz
git-479bd75751d81b6f3ffc29fcece56f9a200493a1.tar.bz2
replace: factor object resolution out of replace_object
As we add new options that operate on objects before replacing them, we'll want to be able to feed raw sha1s straight into replace_object. Split replace_object into the object-resolution part and the actual replacement. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/replace.c')
-rw-r--r--builtin/replace.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/builtin/replace.c b/builtin/replace.c
index 29cf699..af40129 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -123,19 +123,17 @@ static int delete_replace_ref(const char *name, const char *ref,
return 0;
}
-static int replace_object(const char *object_ref, const char *replace_ref,
- int force)
+static int replace_object_sha1(const char *object_ref,
+ unsigned char object[20],
+ const char *replace_ref,
+ unsigned char repl[20],
+ int force)
{
- unsigned char object[20], prev[20], repl[20];
+ unsigned char prev[20];
enum object_type obj_type, repl_type;
char ref[PATH_MAX];
struct ref_lock *lock;
- if (get_sha1(object_ref, object))
- die("Failed to resolve '%s' as a valid ref.", object_ref);
- if (get_sha1(replace_ref, repl))
- die("Failed to resolve '%s' as a valid ref.", replace_ref);
-
if (snprintf(ref, sizeof(ref),
"refs/replace/%s",
sha1_to_hex(object)) > sizeof(ref) - 1)
@@ -166,6 +164,18 @@ static int replace_object(const char *object_ref, const char *replace_ref,
return 0;
}
+static int replace_object(const char *object_ref, const char *replace_ref, int force)
+{
+ unsigned char object[20], repl[20];
+
+ if (get_sha1(object_ref, object))
+ die("Failed to resolve '%s' as a valid ref.", object_ref);
+ if (get_sha1(replace_ref, repl))
+ die("Failed to resolve '%s' as a valid ref.", replace_ref);
+
+ return replace_object_sha1(object_ref, object, replace_ref, repl, force);
+}
+
int cmd_replace(int argc, const char **argv, const char *prefix)
{
int force = 0;